x402 payment SDK for billmyagent — auto-pays HTTP 402 challenges with an eth-account signer and gates your own endpoints (FastAPI/Flask)
Project description
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 | polygon
)
@app.get("/premium")
def premium():
return {"unlocked": True}
Flask is identical via billmyagent.middleware.flask.add_payment_middleware.
Mainnet (base/polygon) 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), polygon.
Development
pip install -e '.[dev,fastapi,flask]'
pytest && ruff check . && mypy billmyagent
License
Apache 2.0.
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 billmyagent-2.1.0.tar.gz.
File metadata
- Download URL: billmyagent-2.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2f5b2798fedd357b2f44960d182c9e329cfcf427287c71c3958d66c18d7ad6d
|
|
| MD5 |
f4a600089cb7f889ca3c460821e9f214
|
|
| BLAKE2b-256 |
36571298581015a29986397b817483e44678f570031701070f58e9d8d862fc4c
|
Provenance
The following attestation bundles were made for billmyagent-2.1.0.tar.gz:
Publisher:
publish-sdks.yml on RealMaxPower/payment-processing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
billmyagent-2.1.0.tar.gz -
Subject digest:
f2f5b2798fedd357b2f44960d182c9e329cfcf427287c71c3958d66c18d7ad6d - Sigstore transparency entry: 2010319392
- Sigstore integration time:
-
Permalink:
RealMaxPower/payment-processing@fdd5885f3961f27e0f215287dab1b23a27d3019b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/RealMaxPower
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdks.yml@fdd5885f3961f27e0f215287dab1b23a27d3019b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file billmyagent-2.1.0-py3-none-any.whl.
File metadata
- Download URL: billmyagent-2.1.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04b408808c9f4cb95d852d63138dc9eeba939f26015e492c5c353baff4392a2c
|
|
| MD5 |
645799ab74d979358a5db09875cdbfb3
|
|
| BLAKE2b-256 |
08d08b357299219006e2c96f83942f55620b88f1d528e5b54a2fcc5a2455bb8d
|
Provenance
The following attestation bundles were made for billmyagent-2.1.0-py3-none-any.whl:
Publisher:
publish-sdks.yml on RealMaxPower/payment-processing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
billmyagent-2.1.0-py3-none-any.whl -
Subject digest:
04b408808c9f4cb95d852d63138dc9eeba939f26015e492c5c353baff4392a2c - Sigstore transparency entry: 2010319454
- Sigstore integration time:
-
Permalink:
RealMaxPower/payment-processing@fdd5885f3961f27e0f215287dab1b23a27d3019b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/RealMaxPower
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdks.yml@fdd5885f3961f27e0f215287dab1b23a27d3019b -
Trigger Event:
workflow_dispatch
-
Statement type: