Python client
A single-file Python mirror of @tollgatepay/agent, packaged in examples/python/tollgate.py. It implements the same 402 → sign → retry protocol against the canonical EIP-712 typed data.
Install
cd examples/python
pip install -e .Dependencies: eth-account>=0.13, requests>=2.28.
Usage
# examples/python/tollgate.py — full source in the repo.
from tollgate import TollgateClient
client = TollgateClient(private_key="0x...")
r = client.fetch("https://api.example.com/premium")
print(r.status_code, r.json())What's in scope
- Parse the 402 envelope, validate required fields.
- Enforce per-request and per-session budgets.
- Maintain a per-
(developer, path)cumulative + nonce. - Sign EIP-712 typed data with
eth_account. - Base64-encode the envelope and retry with
x-tollgate-iou.
What's not (yet)
- No wallet pool / rotation. Use one
TollgateClientper key. - No on-chain allowance checks. Pre-approve manually via your wallet of choice.
- No Redis-backed nonce store. Nonces are in-process (fine for single workers).
- No async support. This is
requests.Session, blocking.
The TypeScript SDK is the canonical implementation. This Python mirror is for parity demos and quick prototyping. Production Python users should expect a follow-up release to harden it; PRs welcome.
See also
- @tollgatepay/agent (TS) — reference.
- Cross-language test vectors.