2016-09-06 18:49:40 +00:00
|
|
|
Quickstart
|
|
|
|
|
==========
|
|
|
|
|
|
|
|
|
|
.. contents:: :local:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Installation
|
|
|
|
|
------------
|
|
|
|
|
|
2016-09-06 20:03:40 +00:00
|
|
|
Web3.py can be installed using ``pip`` as follows.
|
2016-09-06 18:49:40 +00:00
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
2016-09-06 20:03:40 +00:00
|
|
|
$ pip install web3
|
2016-09-06 18:49:40 +00:00
|
|
|
|
2016-12-28 17:50:45 +00:00
|
|
|
Or to install with support for the ``TestRPCProvider`` and
|
|
|
|
|
``EthereumTesterProvider`` you can use this install command.
|
|
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
2017-01-10 15:59:58 +00:00
|
|
|
$ pip install web3[tester]
|
2016-12-28 17:50:45 +00:00
|
|
|
|
2017-01-10 17:08:41 +00:00
|
|
|
|
|
|
|
|
Or to install with support for gevent based threading:
|
|
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
|
|
|
|
$ pip install web3[gevent]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
To enable gevent based threading set the environment variable ``THREADING_BACKEND=gevent``
|
|
|
|
|
|
|
|
|
|
|
2016-09-06 18:49:40 +00:00
|
|
|
Installation from source can be done from the root of the project with the
|
|
|
|
|
following command.
|
|
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
|
|
|
|
$ python setup.py install
|
|
|
|
|
|
|
|
|
|
|
2016-09-06 20:03:40 +00:00
|
|
|
The ``Web3`` object
|
|
|
|
|
-------------------
|
2016-09-06 18:49:40 +00:00
|
|
|
|
2016-09-06 20:03:40 +00:00
|
|
|
The common entrypoint for interacting with the Web3 library is the ``Web3``
|
|
|
|
|
class. You will need to instantiate a web3 instance.
|
2016-09-06 18:49:40 +00:00
|
|
|
|
2016-09-22 19:15:57 +00:00
|
|
|
Web3 takes a connection to existing Ethereum node (*Geth* or *Parity*).
|
|
|
|
|
This connection can be either over JSON-RPC using HTTP (TCP/IP)
|
|
|
|
|
or UNIX sockets (IPC).
|
|
|
|
|
|
2016-09-06 18:49:40 +00:00
|
|
|
.. code-block:: python
|
|
|
|
|
|
2016-12-22 12:35:49 +00:00
|
|
|
>>> from web3 import Web3, KeepAliveRPCProvider, IPCProvider
|
2016-09-22 19:15:57 +00:00
|
|
|
|
|
|
|
|
# Note that you should create only one RPCProvider per
|
|
|
|
|
# process, as it recycles underlying TCP/IP network connections between
|
|
|
|
|
# your process and Ethereum node
|
|
|
|
|
>>> web3 = Web3(KeepAliveRPCProvider(host='localhost', port='8545'))
|
|
|
|
|
|
2016-09-06 20:03:40 +00:00
|
|
|
# or for an IPC based connection
|
|
|
|
|
>>> web3 = Web3(IPCProvider())
|
2016-09-06 18:49:40 +00:00
|
|
|
|
2016-09-06 20:03:40 +00:00
|
|
|
This ``web3`` instance will now allow you to interact with the Ethereum
|
|
|
|
|
blockchain.
|