Skip to main content

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'

Release files for web3-collections 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for web3-collections 0.1.0
File Size Uploaded
web3-collections-0.1.0.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for web3-collections 0.1.0
File Interpreter ABI Platform
web3_collections-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.2 kB

Release files / web3-collections-0.1.0.tar.gz

Download URL web3-collections-0.1.0.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e37b203d872f6f19c5c87191222212510206423b97ab10bfab5a5ffe78385888
BLAKE2b-256 checksum
How to use checksums
f21f294b50aaf58a8f88d648f0cb66acf5869667a3440ddbba698384da78fe8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Release files / web3_collections-0.1.0-py3-none-any.whl

Download URL web3_collections-0.1.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7aaa01a834c7d2bdd83a4a2604e5bd6ab16806d86c106e7b6684712491d22eaa
BLAKE2b-256 checksum
How to use checksums
5ba60182316ca366d4fb1de6f7095ad92ac601a46b8f57d50c582b83ebd30da8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page