Skip to main content

Web3py provider that makes it easy to switch between different blockchain nodes to make sure application will be be online if main blockchain node will be unavailable.

Project description

Lido Web3 Multi Provider

Code style: black License: MIT

Provider that accepts multiple endpoints.

Install

$ pip install web3-multi-provider

or

$ poetry add web3-multi-provider

or with metrics:

$ poetry add web3-multi-provider[metrics]

Usage

from web3 import Web3
from web3_multi_provider import MultiProvider
from web3_multi_provider import FallbackProvider

w3 = Web3(MultiProvider([  # RPC endpoints list
    'http://127.0.0.1:8000/',
    'https://mainnet.infura.io/v3/...',
]))

# or

w3 = Web3(FallbackProvider([  # RPC endpoints list
    'http://127.0.0.1:8000/',
    'https://mainnet.infura.io/v3/...',
]))

last_block = w3.eth.get_block('latest')

MultiProvider

This provider keeps track of the current endpoint and switches to the next one if an error occurs. It fails if no endpoints are available.

FallbackProvider

This provider sends requests to the all endpoints in the sequence until response received or endpoints list exhausted.

AsyncMultiProvider and AsyncFallbackProvider

These providers are async versions of MultiProvider and FallbackProvider respectively. They may be used with instances of AsyncWeb3.

from web3 import AsyncWeb3
from web3_multi_provider import AsyncMultiProvider

w3 = AsyncWeb3(AsyncMultiProvider([  # RPC endpoints list
    'http://127.0.0.1:8000/',
    'https://mainnet.infura.io/v3/...',
]))

Metrics

Library has in-built prometheus metrics, to enable them run metrics.init_metrics().

For developers

  1. poetry install - to install deps
  2. pre-commit install - to install pre-commit hooks

Tests

poetry run pytest tests

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_multi_provider-2.2.6.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

web3_multi_provider-2.2.6-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file web3_multi_provider-2.2.6.tar.gz.

File metadata

  • Download URL: web3_multi_provider-2.2.6.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for web3_multi_provider-2.2.6.tar.gz
Algorithm Hash digest
SHA256 5891b1fc080b94563e7e5ef9c752b45f22439cece57cf5c9ca75a3dd5040f720
MD5 ad92f0e4efcf5200c04a8d371a14a8da
BLAKE2b-256 86c8594aef3e718f7b839c28f262d4c01b9b0e1f3758b8003e9dd44614a632db

See more details on using hashes here.

File details

Details for the file web3_multi_provider-2.2.6-py3-none-any.whl.

File metadata

File hashes

Hashes for web3_multi_provider-2.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 240aefa00da021da07c908725e4d0275100d1d03978c7462465face4f93785f4
MD5 65773edd6b116bb5922ae8ede8ed9233
BLAKE2b-256 6a7ce36361d44beca7c454a0dfe93c09ba674e68c7008c2f0dd9cd54372f9e27

See more details on using hashes here.

Supported by

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