x402-trinity
Let a Python process pay for things by itself — with hard spending limits, no hosted wallet service, and no changes to the code doing the fetching.
Standard library only. No dependencies, at all.
pip install x402-trinity
Why
When a script hits a paid resource it gets 402 Payment Required. Without something to handle
that, the request simply fails.
x402-trinity handles it: reads the challenge, checks it against limits you set, signs, retries. All of it locally — no hosted wallet service, no third-party API, and the key never leaves your process.
Gas exists but the payer doesn't pay it — under EIP-3009 the facilitator submits the transfer, so the wallet only ever needs USDC.
Use
import os
from x402_trinity import X402Client, Policy
client = X402Client(
private_key=os.environ["X402_PRIVATE_KEY"],
policy=Policy(
max_amount_per_request=5000, # 0.005 USDC per call (REQUIRED)
total_budget=1_000_000, # 1.00 USDC lifetime (REQUIRED)
allow_hosts=["api.example.com"],
),
)
body = client.urlopen("https://api.example.com/data").read()
Or as a decorator, so payment-unaware code just works:
from x402_trinity import x402_telemetry, Policy
@x402_telemetry(private_key=KEY, policy=Policy(max_amount_per_request=5000,
total_budget=1_000_000))
def harvest():
return urllib.request.urlopen("https://sensor.local/v1/lidar").read()
Inside the decorated function urllib.request.urlopen pays 402s automatically. Existing code
is untouched.
Scope
Buyer only. To charge for a resource, use the TypeScript seller in the same project.
Base mainnet + USDC. Other EVM chains work by passing custom_chains to X402Client.
Check any entry against the deployed contract first: call DOMAIN_SEPARATOR() and confirm it
equals what this library computes. A wrong name or version produces a signature that looks
valid and the contract rejects.
Limits are not optional
max_amount_per_request and total_budget are required arguments. An auto-payer without caps
is a money leak controlled by whoever runs the server on the other end. Set allow_hosts and
nothing else can be paid, however convincing the challenge looks.
Before you use it with real money
This software signs payment authorizations. You are responsible for the funds in any wallet you configure it with, for the limits you set, and for the behaviour of any autonomous process you connect to it. Use a dedicated wallet holding only what you would accept losing.
Links
- Source: https://github.com/devmster/x402-trinity
- TypeScript package (buyer, seller, MCP server):
npm install x402-trinity
License
Business Source License 1.1 — source-available, converts to MIT on 2029-08-25. See the LICENSE file in the repository.
Metadata
Release files for x402-trinity 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| x402_trinity-0.2.2.tar.gz | 20.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| x402_trinity-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 40.9 kB
Release files / x402_trinity-0.2.2.tar.gz
| Download URL | x402_trinity-0.2.2.tar.gz |
|---|---|
| Size | 20.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5520b7323b0f8c0799f139d88534d90f2f06d5efa432304feb2f2b509ef6ce46
|
|
BLAKE2b-256 checksum How to use checksums |
44a23cd93284b50e3bc19a4f962ca740872a40db29867b65fb601096093e3c27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / x402_trinity-0.2.2-py3-none-any.whl
| Download URL | x402_trinity-0.2.2-py3-none-any.whl |
|---|---|
| Size | 20.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
67b27115ccf7bd73f1c44b0383fe059971cfc31bd5702d166cfb54ba4a1affd2
|
|
BLAKE2b-256 checksum How to use checksums |
8db7a9daa8ce06929d757719a4b1db10216df8fcd0e773b0b239aa44c4eb5f08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|