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
Web3 Multi Provider
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
poetry install- to install depspre-commit install- to install pre-commit hooks
Tests
poetry run pytest tests
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file web3_multi_provider-2.2.2.tar.gz.
File metadata
- Download URL: web3_multi_provider-2.2.2.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.11 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
250ccf64fd5a9a439a2880214665da30032443e2a752e04fb79a22cbc9ef2140
|
|
| MD5 |
fead7076f3400cb2ba9c53a29bb9effd
|
|
| BLAKE2b-256 |
82d814d97b695a0053df1fd1612d3481c6b7f83315f6417b2ce03cf25ee5627c
|
File details
Details for the file web3_multi_provider-2.2.2-py3-none-any.whl.
File metadata
- Download URL: web3_multi_provider-2.2.2-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.11 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bddc155b1f9fda2884b4db42e85137cb91de07ff5aafb1b0e8d1695f87c01a55
|
|
| MD5 |
1669704a3335e4f9619461318818ea88
|
|
| BLAKE2b-256 |
d63d31302f4aa9a233fa1e84d1d749e30aa388bbc26d43bed0ddbdd7f5c65829
|