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

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
from web3_multi_provider import AsyncFallbackProvider

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

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.1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

web3_multi_provider-2.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: web3_multi_provider-2.1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.1 Linux/6.5.0-1025-azure

File hashes

Hashes for web3_multi_provider-2.1.0.tar.gz
Algorithm Hash digest
SHA256 3ca01fbeb655cd1bf3c558971303e5ba61c54515a9d5304654db3b359cf6422f
MD5 0f20d9d17736dcf551b0b1661d1bd51c
BLAKE2b-256 a82db82a2dd7b1f0b7c947e4d3aef39f367d047919a131c0881e16d8b29a1bae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for web3_multi_provider-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29c5da10bb96ea8bd2e1fc3831e4b2b48daa60fec3bbb59e7b0b50c729aa630b
MD5 9cff20eb259a88959cd04e4a12c86ce3
BLAKE2b-256 eeff72c44add11d39c1bec2718ae7f18c386f24e43a6a05fe49cd153e82906ef

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