auradefi 0.1.2
PyPI GitHub

Recorder

auradefi.testing.cassettes · source

Wraps a real transport, saving each interaction for later replay.

The other half of load. Point one at a live service once, then run offline forever after::

recorder = Recorder("mywallet.json")
source = EtherscanSource(recorder.client(), api_key=KEY)
source.balances("eip155:1", "0x…")
recorder.save()

# every run after this one, with no key and no network:
source = EtherscanSource(load("mywallet.json").client())

Credentials named in REDACTED_PARAMS are stripped from every recorded URL, which is also why the replay above needs no key: the saved request matches a keyless client. A secret in the path or in a header is never written at all, since this format stores neither.

Response BODIES are saved whole, so read a cassette before committing it. Redaction covers what this package puts on the wire, and a service that echoes your credential back to you defeats it.

What handle returns to the caller is built from the entry it just saved, so a recording run exercises the same bytes the replay will. A response this format cannot represent therefore fails while you are recording, in front of you, instead of at replay time.

__init__

__init__(self, path: str | Path, transport: httpx.BaseTransport | None = None, redact: frozenset[str] | set[str] | tuple[str, ...] = frozenset({apikey, api_key, api-key, access_token})) -> None

Parameters

pathrequired, str | Path

none

transportoptional, httpx.BaseTransport | None, default None

none

redactoptional, frozenset[str] | set[str] | tuple[str, ...], default frozenset({'apikey', 'api_key', 'api-key', 'access_token'})

none

handle

handle(self, request: httpx.Request) -> httpx.Response

Perform request for real, record it, and answer from the record.

Parameters

requestrequired, httpx.Request

none

transport

transport(self) -> httpx.MockTransport

client

client(self, **kwargs) -> httpx.Client

Parameters

kwargsoptional, any

none

save

save(self) -> Path

Write the cassette and return its path.

An empty recording is refused. Written out it would load cleanly and then miss on every request, which reads as a broken library rather than as a session that recorded nothing.