Skip to main content

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


Download files

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

Source Distribution

web3-collections-0.0.6b2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

web3_collections-0.0.6b2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file web3-collections-0.0.6b2.tar.gz.

File metadata

  • Download URL: web3-collections-0.0.6b2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.5

File hashes

Hashes for web3-collections-0.0.6b2.tar.gz
Algorithm Hash digest
SHA256 2dbf7549937bb81b1ee7062e45ab623a4f2f2e555c4897046b42bec2dc9c935b
MD5 9ecdf6d458343bc90c76c79934ca88af
BLAKE2b-256 a69be1eb16064c26d77abac72fa7f8e2eaaaee2a4d8da735c4b653efa96a0d3a

See more details on using hashes here.

File details

Details for the file web3_collections-0.0.6b2-py3-none-any.whl.

File metadata

File hashes

Hashes for web3_collections-0.0.6b2-py3-none-any.whl
Algorithm Hash digest
SHA256 a07474c649766e8efe97f7189e409943a4a27288d1de310d5840de453aac6d86
MD5 c34ad3072597d09c953fcefa38eb3379
BLAKE2b-256 0127df3c29335207bbd7300f12c24a3a24fe81af41a1fbfd08669bd0026a5c5a

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