rpc_url

Documentation for eth_defi.rpc_url Python module.

Credential-free RPC diagnostics.

Provider constructors register their endpoints before making requests. This also protects dependency logs and logged exception chains, without shortening links to unrelated services. Call register_rpc_url() before using an externally constructed provider. Registration is process-local and safe across threads.

Functions

get_url_domain(url)

Display a URL as its hostname and optional non-default port.

install_rpc_logging(*[, from_environment])

Install RPC redaction while preserving an existing log record factory.

redact_rpc_urls(text)

Shorten registered RPC URLs in diagnostic text.

register_rpc_url(configuration_line)

Register endpoints whose diagnostic representations must be shortened.

Classes

RPCURLFilter

Protect handler output, including cached exception text and extra fields.

get_url_domain(url)

Display a URL as its hostname and optional non-default port.

Credentials, paths, query parameters and fragments are discarded. Invalid URLs use a fixed placeholder rather than echoing the invalid input.

Parameters

url (str) – An endpoint URL or fallback configuration, including mev+.

Returns

Hostname, with a non-default port when supplied.

Return type

str

register_rpc_url(configuration_line)

Register endpoints whose diagnostic representations must be shortened.

Registration installs logging protection before any provider network reads. Fallback configurations and mev+ endpoints are supported. The original strings remain available to callers for real network requests.

Parameters

configuration_line (str) – A URL or space-separated RPC configuration.

Returns

None.

Return type

None

redact_rpc_urls(text)

Shorten registered RPC URLs in diagnostic text.

Other URLs are preserved. Request targets in urllib3-style exception text are also shortened, even when the transport omitted the URL’s scheme.

Parameters

text (str) – Diagnostic text, never a value used for network requests.

Returns

Sanitised text.

Return type

str

class RPCURLFilter

Bases: logging.Filter

Protect handler output, including cached exception text and extra fields.

Initialize a filter.

Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.

filter(record)

Sanitise a record immediately before formatting.

This complements record creation for records received from queues and fields added with extra after the record factory has returned.

Parameters

record (logging.LogRecord) – Record about to be emitted.

Returns

Always True.

Return type

bool

__init__(name='')

Initialize a filter.

Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.

install_rpc_logging(*, from_environment=False)

Install RPC redaction while preserving an existing log record factory.

Repeated calls are idempotent. Each worker registers its own providers; logging setup can additionally seed endpoints from RPC environment values.

Parameters

from_environment (bool) – Register JSON_RPC_* and *_RPC_URL values.

Returns

None.

Return type

None