Skip to content

Web3.py compatible async provider supports multiply RPC URLs

License

Notifications You must be signed in to change notification settings

deknowny/web3-async-multi-provider

Repository files navigation

Web3 async multi provider

Web3.py compatible async providers that supports multiply RPC URLs

This library allows to create a w3 instance with multiply RPC URLs to prevent failures when a node is down by choosing another one by cycle.

PyPI - Python Version PyPI - Implementation PyPI Coverage Status


Features

  • HTTP async provider
  • WebSockets async provider

Overview

HTTP w3 provider

import web3
from web3_async_multi_provider import AsyncWSMultiProvider


provider = AsyncHTTPMultiProvider(
    providers=[
        web3.AsyncHTTPProvider("https://eth.llamarpc.com"),
        web3.AsyncHTTPProvider("https://rpc.flashbots.net"),
    ]
)

WebSockets provider

import web3
from web3_async_multi_provider import AsyncWSMultiProvider


provider = AsyncWSMultiProvider(
    providers=[
        web3.providers.WebsocketProvider("wss://example.com/"),
        web3.providers.WebsocketProvider("wss://google.com/"),
    ]
)

And then add it into Web3:

w3 = web3.Web3(
    provider
    modules={"eth": [web3.eth.AsyncEth]},
    middlewares=[]
)
print(await web3.eth.chain_id)

Installation

Via PyPI:

python -m pip install web3_async_multi_provider

Or via GitHub

python -m pip install https://github.com/deknowny/web3-async-multi-provider/archive/main.zip

Contributing

Check out site Contributing section

About

Web3.py compatible async provider supports multiply RPC URLs

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published