provider.named

Documentation for eth_defi.provider.named Python module.

Helper methods to extract the URL endpoint and name of a provider.

See also

Functions

get_provider_name(provider)

Get loggable name of the JSON-RPC provider.

Classes

BaseNamedProvider

A base class for getting a JSON-RPC provider name and URL.

class BaseNamedProvider

Bases: abc.ABC, web3.providers.base.JSONBaseProvider

A base class for getting a JSON-RPC provider name and URL.

abstract property endpoint_uri: str

Return the active node URI endpoint.

Warning

Endpoint URIs often contain API keys. They should be never publicly displayed as is.

property call_endpoint_uri: str

Return the active node URI where call JSON-RPCs go.

Warning

Endpoint URIs often contain API keys. They should be never publicly displayed as is.

__init__(**kwargs)
Parameters

kwargs (Any) –

Return type

None

request_func(w3, middleware_onion)

@param w3 is the web3 instance @param middleware_onion is an iterable of middleware,

ordered by first to execute

@returns a function that calls all the middleware and

eventually self.make_request()

Parameters
  • w3 (Web3) –

  • middleware_onion (web3.datastructures.NamedElementOnion[str, Type[web3.middleware.base.Web3Middleware]]) –

Return type

Callable[[…], web3.types.RPCResponse]

NamedProvider: TypeAlias = eth_defi.provider.named.BaseNamedProvider | web3.providers.rpc.rpc.HTTPProvider

Named providers including web3.py core providers

get_provider_name(provider)

Get loggable name of the JSON-RPC provider.

Strips out API keys from the URL of a JSON-RPC API provider.

Supports eth_defi customer provider classes as well as web3 core providers.

Example:

print(get_provider_name(web3.provider))
Returns

HTTP provider URL’s domain name if available.

Assume any API keys are not part of the domain name.

Parameters

provider (web3.providers.base.BaseProvider) –

Return type

str