A Python library for interacting with Ethereum, inspired by web3.js.
- Python 3.6+ support
Added support of multiple rpc nodes for HTTPProvider. Usage: choose custom source for downloading library, i.e (for installing via requirements.txt):
web3 @ git+https://github.com/Rock-n-Block/web3.py.git
initialize web3 instance in code:
from web3 import Web3
web3 = Web3(
Web3.HTTPProvider(
[endpoint1, endpoint2, ...]
)
)
For a backwards compatibility you can still pass a single string rpc provider as usual, i.e.
Web3.HTTPProvider('endpoint')
For any blockchain call using web3 (simple requests like "gas_price", or contract interactions and filters,), web3 instance will try to make a call using one provider at once in cycle, and will change provider if any RequestException is thrown. If all endpoints are invalid, built-in "CannotHandleRequest" Exception is thrown.
Additionally, you can use some kind of node balancing, passing "randomize=True" in HTTPProvider initialization. In this case, every time you make a call, nodes are shuffled randomly, meaning that requests will be shared between them (instead of logic "call first infura unless it passes out, after that go to the second one").
Get started in 5 minutes or take a tour of the library.
For additional guides, examples, and APIs, see the documentation.
Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing, then check out issues that are labeled Good First Issue.