Alternatives to some of the web3's classes
Project description
Web3.py collections
This module providing alternatives to some of the web3's classes
Installation
Install the package using the following command:
pip install -U web3-collections
Alternatives
Class name | Alternative to |
---|---|
MultiEndpointHTTPProvider | HTTPProvider |
MultiEndpointHTTPProvider
The constructor gives a list of endpoint URIs. In each http request, it tries to use the current_endpoint
to fetch
data and if it fails, updates the current endpoint and tries again.
import web3
from web3_collections import MultiEndpointHTTPProvider
endpoint_uris = ['https://rpc.ankr.com/eth', 'https://1rpc.io/eth', 'https://eth.drpc.org', ...]
w3 = web3.Web3(MultiEndpointHTTPProvider(endpoint_uris))
By default auto_update=True
and you don't need to use update_endpoint
method. But, you can disable auto update and
handle it manually:
w3 = web3.Web3(MultiEndpointHTTPProvider(endpoint_uris, auto_update=False))
try:
w3.eth.get_block('latest')
except Exception as e:
print(f'{w3.provider.current_endpoint} got error: {e}')
w3.provider.update_endpoint()
print(f'Endpoint updated to {w3.provider.current_endpoint}')
Method MultiEndpointHTTPProvider.sort_endpoints
sorts the endpoints by their latest block number
(most updated will choose as current_endpoint
):
>>> endpoint_uris = [
... 'https://arbitrum.meowrpc.com',
... 'https://1rpc.io/arb',
... 'https://arbitrum-one-rpc.publicnode.com',
... 'https://arb-pokt.nodies.app'
... ]
>>> w3 = web3.Web3(MultiEndpointHTTPProvider(endpoint_uris))
>>> w3.provider.current_endpoint # before sorting
'https://arbitrum.meowrpc.com'
>>> w3.provider.sort_endpoints() # sorting by latest block number
>>> w3.provider.current_endpoint # after sorting
'https://arbitrum-one-rpc.publicnode.com'
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
Built Distribution
File details
Details for the file web3-collections-0.0.5.tar.gz
.
File metadata
- Download URL: web3-collections-0.0.5.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e695de61650491612d357a3f9505bcc9d3bb5ef9e44a50ced70a8527c983b4e |
|
MD5 | 46ec835d91cefcaa04a471c5b7551e63 |
|
BLAKE2b-256 | 35449178ac524fc7c1d090a44eb65ab5b1a506a6723799a18e1a39f6ad7bb330 |
File details
Details for the file web3_collections-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: web3_collections-0.0.5-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a17f33cd492980c2e6b2bc4b788dc0203262ea651576a1f3298af35f2b609cd |
|
MD5 | 91c07bdf188f5078c4a72877653763d2 |
|
BLAKE2b-256 | 69eda4d2059a55f350d34e3bb4301386d7583664b454fbec4af7cc97b07b3606 |