billmyagent (Python)
x402 payment SDK for Python. Pay x402-gated APIs as a server/agent and gate
your own endpoints with a paywall. The Python counterpart of
@billmyagent/payments-core, built on the official
x402 library + eth-account.
Unlike the browser-oriented JS SDK, the agent here holds its private key directly — which is why this SDK matters for autonomous Python agents (LangChain, CrewAI, FastAPI services).
Install
pip install billmyagent # buyer client
pip install 'billmyagent[fastapi]' # + FastAPI seller middleware
pip install 'billmyagent[flask]' # + Flask seller middleware
Pay an x402-gated API (buyer / agent)
import os
from billmyagent import PaymentClient, create_signer
# The private key is held in-process and never leaves it.
signer = create_signer("base", os.environ["PRIVATE_KEY"])
client = PaymentClient(signer=signer)
# client.http is a requests.Session; any HTTP 402 it hits is paid and retried.
res = client.http.get("https://api.example.com/paid-resource")
print(res.json(), "paid:", bool(res.headers.get("x-payment-response")))
Manage your merchant account (REST)
client = PaymentClient(api_key=os.environ["BMA_API_KEY"], auth_token=jwt)
client.get_payout_settings()
client.update_payout_settings({"base_address": "0x…"})
client.list_payments()
Charge for your endpoints (seller)
FastAPI:
from fastapi import FastAPI
from billmyagent.middleware.fastapi import add_payment_middleware
app = FastAPI()
add_payment_middleware(
app,
pay_to="0xYourPayoutAddress",
routes={"GET /premium": "$0.01"},
network="base-sepolia", # base | base-sepolia
)
@app.get("/premium")
def premium():
return {"unlocked": True}
Flask is identical via billmyagent.middleware.flask.add_payment_middleware.
Mainnet (base) settlement needs a facilitator with CDP credentials — pass
facilitator_url=.... Omit it to use the public x402.org testnet facilitator.
Supported networks
EVM only, exact scheme: base, base-sepolia (testing).
Development
pip install -e '.[dev,fastapi,flask]'
pytest && ruff check . && mypy billmyagent
License
Apache 2.0.
Metadata
Release files for billmyagent 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| billmyagent-3.0.0.tar.gz | 11.4 kB | With provenance | Details for billmyagent-3.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| billmyagent-3.0.0-py3-none-any.whl | Python 3 | none | any | Details for billmyagent-3.0.0-py3-none-any.whl |
Total release size: 24.1 kB
Release files / billmyagent-3.0.0.tar.gz
| Download URL | billmyagent-3.0.0.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6a8b09f0b5489c292375ddc0de2e1c0b47cbc3119f7b541d2b1e47fbb2a3540
|
|
BLAKE2b-256 checksum How to use checksums |
aa86fad49fdb46f3d965cf9ce4f24aeabc6ee4f3ea7612cd928da4bff0909a68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.
Transparency logRelease files / billmyagent-3.0.0-py3-none-any.whl
| Download URL | billmyagent-3.0.0-py3-none-any.whl |
|---|---|
| Size | 12.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4b490d0309a139914f71fec3479a113e1ec114aacb4890d3e125394bc41bf76e
|
|
BLAKE2b-256 checksum How to use checksums |
f17cf3143f9b1726222addd78f2029d88c550d36d6435980bf8de5102cde7ecb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.
Transparency logSecurity for billmyagent 3.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for billmyagent-3.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.