Python client for The Factory — x402 micropayment agent for clean machine data
Project description
The Factory Client
Python client for The Factory — an x402 micropayment agent that sells clean JSON data to AI agents and bots.
Install
pip install the-factory-client
Quick start
from the_factory_client import Factory
# Initialize with your Solana private key (Phantom → Settings → Show Private Key)
f = Factory(
private_key_base58="YOUR_BASE58_PRIVATE_KEY",
# optional: rpc_url="https://api.mainnet-beta.solana.com",
)
# Call any endpoint — payment is handled automatically
weather = f.get("/api/v1/meteo", params={"q": "Milano", "days": 3})
print(weather)
# {'location': 'Milano', 'avg_temp_c': 24.3, 'days': [...]}
fx = f.get("/api/v1/fx", params={"base": "EUR", "target": "USD", "days": 7})
transit = f.get("/api/v1/transit", params={"stop": "4205"})
Bulk packs and subscriptions
Pre-pay for discounted calls:
# Buy a 10-call bulk pack for 0.08 USDC
bulk = f.purchase_bulk()
print(bulk["token"]) # bulk_abc123...
# Use the token for the next 10 calls
for _ in range(10):
data = f.get("/api/v1/meteo", params={"q": "Roma"})
# Or buy a monthly subscription (10k calls for $50)
sub = f.purchase_subscription()
How it works (under the hood)
- Client calls
GET /api/v1/<endpoint>without payment header - Server returns
402withWWW-Authenticate: x402 challenge=... - Client decodes the challenge, builds a USDC transfer tx to
pay_toforamount_atomic - Client signs with the provided Solana keypair
- Client broadcasts via Solana RPC, captures the tx signature
- Client retries the endpoint with
X-Payment: base64({"signature":"<sig>"}) - Server verifies on-chain, returns
200+ clean JSON
All of this happens in f.get(...). One line.
API reference
Factory(private_key_base58=None, rpc_url=None, base_url=DEFAULT, token=None)
private_key_base58: Solana private key in base58 (from Phantom). Required for auto-payment.rpc_url: Solana RPC URL. Defaults to public mainnet.base_url: The Factory base URL. Defaults tohttps://the-factory-9ja4.onrender.com.token: Pre-purchased bulk or subscription token. If set, no Solana key needed.
f.get(endpoint, params=None) -> dict
Call an endpoint with query params. Returns the cleaned JSON from the server.
f.purchase_bulk() -> dict
Buy a 10-call bulk pack (0.08 USDC). Returns {"token": "...", "calls_remaining": 10}.
f.purchase_subscription() -> dict
Buy a 10k-call monthly subscription (50 USDC). Returns {"token": "...", "calls_remaining": 10000}.
f.balance() -> dict
Check the bulk/subscription token balance (if a token is set).
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file the_factory_client-0.1.0.tar.gz.
File metadata
- Download URL: the_factory_client-0.1.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e94d88017afe0d21548834bd81e74ce65ce6f4e3aa303e40412a7832b157498b
|
|
| MD5 |
47d9fa3a5ad577a20e573f630b53c00f
|
|
| BLAKE2b-256 |
48f3f9fdda5fc643b4a3ebda9a9f3eb5e9347613f54ae68fe1b41b36a4cfdf5e
|
File details
Details for the file the_factory_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: the_factory_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b720f55293e252c40f70d82d83756e3e2b2f904bef1562958578e22a3f3ca621
|
|
| MD5 |
d2c8732ca3357a2222dc366e0e5ff51d
|
|
| BLAKE2b-256 |
cab745c9e195cea76abed9eca2bf806c2793875e713e9318c54a4433dc4222c2
|