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.7.tar.gz (14.0 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.7-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for web3_multi_provider-2.2.7.tar.gz
Algorithm Hash digest
SHA256 388f8d67ff19c9a83a239c320c538cea98f471492245b647656babf9bef6d0f5
MD5 69ba9a374d57b8aae9ebe93f04f5e164
BLAKE2b-256 20dcff2622ae4ee4a33c09fff43f7840eb4b7e7fa7ea450dd2bd1b7a39337e75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for web3_multi_provider-2.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 f16d21b3349ba394a6104f48915298f6e8c0fdb72e6a50284d8819454d42e465
MD5 3cd2f369c09cd3834fc0f2ede76404fb
BLAKE2b-256 4072e4cde966e42b26778ae362542173d19100ffb76bf9cec751bd97ff50a637

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