wallet_helper.remote module
RemoteLedger: use a wallet-helper HTTP server as a shared, remote store.
A LedgerLike backend that talks to the dedup
server in wallet_helper.api. Point a wallet at one and every process, on
any host, shares the same store and the same in-flight lease, so the same heavy
call is not run twice across a whole fleet:
>>> from wallet_helper import Wallet, memoize
>>> from wallet_helper.remote import RemoteLedger
>>> wallet = Wallet(RemoteLedger("http://cache.internal:8000"))
>>> @memoize(wallet=wallet)
... def transcribe(path):
... return call_some_paid_api(path)
Because it offers claim / submit / release,
Wallet routes through the server’s lease, giving
cross-process single-flight with no extra code.
It uses only the Python standard library (urllib), so a client host needs
nothing installed beyond wallet-helper itself. The HTTP call is isolated in
RemoteLedger._request(), which can be replaced with a custom transport
(handy in tests).
- class wallet_helper.remote.RemoteLedger(base_url, *, timeout=30.0, request=None)[source]
Bases:
objectA ledger backed by a wallet-helper HTTP server.
- Parameters:
base_url (str) – Root URL of the server, for example
"http://127.0.0.1:8000". A trailing slash is fine; it is trimmed.timeout (float, optional) – Per-request timeout in seconds. Defaults to 30.
request (callable, optional) – A custom transport
request(method, path, body) -> dict | Noneused instead of the built-inurllibone. Mainly for tests, where it can route to a FastAPITestClient.
- claim(key, lease_seconds=300.0)[source]
Get the cached result, or lease the right to compute it (see the server).
- clear(namespace=None)[source]
Delete results on the server, all of them or just one namespace.
- Parameters:
namespace (str | None)
- Return type:
None
- evict(*, max_entries=None, older_than=None)[source]
Prune results on the server and return how many were removed.
- register_hit(key)[source]
No-op: the server counts reuses itself, on claim hits and result reads.
- Parameters:
key (str)
- Return type:
None
- release(key, token=None)[source]
Drop a lease on the server so a waiter can take over (your own, if fenced).