Skip to main content

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 4.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for billmyagent 4.0.0
File Size Uploaded Provenance Actions
billmyagent-4.0.0.tar.gz 11.5 kB With provenance Details for billmyagent-4.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for billmyagent 4.0.0
File Interpreter ABI Platform Actions
billmyagent-4.0.0-py3-none-any.whl Python 3 none any Details for billmyagent-4.0.0-py3-none-any.whl

Total release size: 24.2 kB

Release files / billmyagent-4.0.0.tar.gz

Download URL billmyagent-4.0.0.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0f3a0b4b5b2c2addb1e37222d61eba1d8704a60a177bd7b967d8c6a0b1b34c96
BLAKE2b-256 checksum
How to use checksums
96ba1217c831e1ca844a6eae0078a7e80fd551dfefe73fa3c81dfb3bf0d9347a
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 27, 2026.

Transparency log

Release files / billmyagent-4.0.0-py3-none-any.whl

Download URL billmyagent-4.0.0-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e57e5f1d1c2c0c66d00b3777865d0d6980176e7fe5daa08df05429362d3130ba
BLAKE2b-256 checksum
How to use checksums
bd156311d133c14e5768edc3cdc38371f0c8c4f3421f05ba9a11ced51ea5b24b
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 27, 2026.

Transparency log

Security for billmyagent 4.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.

Select from 2 files

Attestation for billmyagent-4.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 27, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page