Skip to main content

Web3.py

Project description

# Web3.py

[![Join the chat at https://gitter.im/pipermerriam/web3.py](https://badges.gitter.im/pipermerriam/web3.py.svg)](https://gitter.im/pipermerriam/web3.py?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[![Build Status](https://travis-ci.org/pipermerriam/web3.py.png)](https://travis-ci.org/pipermerriam/web3.py)

[Documentation on ReadTheDocs](http://web3py.readthedocs.io/)


A python implementation of [web3.js](https://github.com/ethereum/web3.js)

* Python 2.7, 3.4, 3.5 support


## Installation

```sh
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.

```sh
pip install web3[tester]
```

Then in your code:


```python
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
```python
web3.eth.defaultAccount = <your (unlocked) account>
web3.eth.defaultBlock = "latest"
# Can also be an integer or one of "latest", "pending", "earliest"
```

### Interacting with contracts


```python
>>> 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.

```python
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.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

web3-3.6.2.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

web3-3.6.2-py3-none-any.whl (46.0 kB view details)

Uploaded Python 3

File details

Details for the file web3-3.6.2.tar.gz.

File metadata

  • Download URL: web3-3.6.2.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for web3-3.6.2.tar.gz
Algorithm Hash digest
SHA256 13f0abacc079c7c3a613960be2371615603e3b296617c7185cda0d9432bb7257
MD5 3af95f6aeda6a449d4d3465c55cb7ca7
BLAKE2b-256 3b369d55d54ee4b960ff3b001630eff62afd8935945c610a9c44899a5f78a2c5

See more details on using hashes here.

File details

Details for the file web3-3.6.2-py3-none-any.whl.

File metadata

File hashes

Hashes for web3-3.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 72f503d6b92f1e79b9cbbee11a074e44e29e127cca741dc2886e1e8670a216a8
MD5 b01e6f6b98a416a3911d4bf4d5d8abcd
BLAKE2b-256 bb32d9a3394d07e6c8b0b08c6f4d470f3c6a618517019d157e61af563079e7f0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page