Go to file
2017-02-14 22:04:22 -07:00
.github template contains the markdown for the image 2016-08-10 10:04:05 +02:00
docs basic docs updates and remove usage from othe parts of code 2017-02-06 15:33:23 -07:00
tests fix hex encoding change 2017-02-14 22:04:22 -07:00
web3 fix hex encoding change 2017-02-14 22:04:22 -07:00
.gitignore again ignore pycharm...i thought I did it 2016-10-14 09:33:02 +02:00
.travis.yml travis futzing 2017-02-13 16:44:32 -07:00
ARCHITECTURE.md Add ARCHITECTURE.md 2016-04-21 17:21:00 +02:00
CHANGELOG 3.6.1 Release 2017-02-13 17:30:50 -07:00
conftest.py change from async to compat 2017-01-10 10:08:41 -07:00
CONTRIBUTING.md initial commit 2016-04-14 10:21:31 -06:00
LICENSE initial commit 2016-04-14 10:21:31 -06:00
Makefile setup documentation 2016-09-07 14:14:49 -06:00
MANIFEST.in initial commit 2016-04-14 10:21:31 -06:00
pytest.ini pytest.ini verbosity 2016-07-31 08:58:45 -06:00
README.md more gevent abstractions 2017-01-10 08:59:58 -07:00
requirements-dev.txt update requirements 2017-01-10 11:09:00 -07:00
requirements-docs.txt changed version requirement for py-geth 2016-10-12 15:29:08 +05:30
requirements-gevent.txt dirty 2017-01-10 14:30:49 -07:00
setup.py start conversion 2017-02-14 17:18:11 -07:00
tox.ini travis futzing 2017-02-13 16:44:32 -07:00

Web3.py

Join the chat at https://gitter.im/pipermerriam/web3.py

Build Status

Documentation on ReadTheDocs

A python implementation of web3.js

  • Python 2.7, 3.4, 3.5 support

Installation

pip install web3

Testing

For testing you can use the TestRPCProvider. This depends on eth-testrpc>=0.9.0 which must be eithe installed independently or with the following installation command.

pip install web3[tester]

Then in your code:

from web3 import Web3, TestRPCProvider

# Initialising a Web3 instance with an RPCProvider:
web3rpc = Web3(TestRPCProvider())

# or specifying host and port.
web3rpc = Web3(TestRPCProvider(host="127.0.0.1", port="8545"))

The TestRPCProvider uses an EVM backed by the ethereum.tester module from the pyethereum package. This can be quite useful for testing your code which uses web3.py.

Setting defaults

web3.eth.defaultAccount = <your (unlocked) account>
web3.eth.defaultBlock = "latest"
# Can also be an integer or one of "latest", "pending", "earliest"

Interacting with contracts

>>> abi = json.joads("<abi-json-string>")
>>> ContractFactory = web3.eth.contract(abi, code="0x...")
>>> ContractFactory.deploy()
... '0x461e829a731d96539ec1f147232f1d52b475225ed343e5853ff6bf3b237c6e79'
>>> contract = web3.eth.contract(abi, address="0x...")
>>> contract.transact().someMethod()
... '0xfbb0f76aa6a6bb8d178bc2b54de8fc7ca778d704af47d135c188ca7b5d25f2e4'
>>> contract.call().return13()
... 13
>>> contract.estimateGas().someMethod()
... 23212

You can listen for events using the on and pastEvents functions on a contract.

def transfer_callback(log_entry):
    ...  # do something with the log.

# create a filter and register a callback.
filter = MyContract.on("Transfer", {})
filter.watch(transfer_callback)

filter.stop_watching()

The underlying asynchronous operations are managed by gevent.

Timeouts, blocking and nonblocking requests

Web3.py does not currently support asynchronous calling patterns.