Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncHTTPProvider docs #2017

Merged
merged 2 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions docs/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,46 @@ AutoProvider
:class:`~web3.providers.auto.AutoProvider` is the default used when initializing
:class:`web3.Web3` without any providers. There's rarely a reason to use it
explicitly.



AsyncHTTPProvider
~~~~~~~~~~~~~~~~~

.. warning:: This provider is unstable and there are still gaps in
functionality. However, it is being actively developed.

.. py:class:: web3.providers.async_rpc.AsyncHTTPProvider(endpoint_uri[, request_kwargs])

This provider handles interactions with an HTTP or HTTPS based JSON-RPC server asynchronously.

* ``endpoint_uri`` should be the full URI to the RPC endpoint such as
``'https://localhost:8545'``. For RPC servers behind HTTP connections
running on port 80 and HTTPS connections running on port 443 the port can
be omitted from the URI.
* ``request_kwargs`` should be a dictionary of keyword arguments which
will be passed onto each http/https POST request made to your node.

.. code-block:: python

>>> from web3 import Web3
>>> w3 = Web3(Web3.AsyncHTTPProvider("http://127.0.0.1:8545"))

Under the hood, the ``AsyncHTTPProvider`` uses the python
`aiohttp <https://docs.aiohttp.org/en/stable/>`_ library for making requests.

Supported Methods
^^^^^^^^^^^^^^^^^

- :meth:`web3.eth.block_number <web3.eth.Eth.block_number>`
- :meth:`web3.eth.coinbase <web3.eth.Eth.coinbase>`
- :meth:`web3.eth.gas_price <web3.eth.Eth.gas_price>`
- :meth:`web3.eth.estimate_gas() <web3.eth.Eth.estimate_gas>`
- :meth:`web3.eth.generate_gas_price() <web3.eth.Eth.generate_gas_price>`
- :meth:`web3.eth.get_block() <web3.eth.Eth.get_block>`
- :meth:`web3.eth.get_transaction() <web3.eth.Eth.get_transaction>`
- :meth:`web3.eth.send_transaction() <web3.eth.Eth.send_transaction>`

Supported Middleware
^^^^^^^^^^^^^^^^^^^^
- :meth:`Gas Price Strategy <web3.middleware.gas_price_strategy_middleware>`
1 change: 1 addition & 0 deletions newsfragments/2017.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add docs for unstable AsyncHTTPProvider
4 changes: 4 additions & 0 deletions web3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
from web3.providers.ipc import (
IPCProvider,
)
from web3.providers.async_rpc import (
AsyncHTTPProvider,
)
from web3.providers.rpc import (
HTTPProvider,
)
Expand Down Expand Up @@ -148,6 +151,7 @@ class Web3:
IPCProvider = IPCProvider
EthereumTesterProvider = EthereumTesterProvider
WebsocketProvider = WebsocketProvider
AsyncHTTPProvider = AsyncHTTPProvider

# Managers
RequestManager = DefaultRequestManager
Expand Down
3 changes: 1 addition & 2 deletions web3/providers/async_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class AsyncHTTPProvider(AsyncJSONBaseProvider):

def __init__(
self, endpoint_uri: Optional[Union[URI, str]] = None,
request_kwargs: Optional[Any] = None,
session: Optional[Any] = None
request_kwargs: Optional[Any] = None
) -> None:
if endpoint_uri is None:
self.endpoint_uri = get_default_http_endpoint()
Expand Down