Metadata-Version: 2.4
Name: billmyagent
Version: 2.1.0
Summary: x402 payment SDK for billmyagent — auto-pays HTTP 402 challenges with an eth-account signer and gates your own endpoints (FastAPI/Flask)
Project-URL: Homepage, https://billmyagent.ai
Project-URL: Source, https://github.com/RealMaxPower/payment-processor
Author: billmyagent
License-Expression: Apache-2.0
Keywords: ai-agents,eip-3009,ethereum,payments,usdc,x402
Requires-Python: >=3.10
Requires-Dist: eth-account>=0.13
Requires-Dist: requests>=2.31
Requires-Dist: x402[evm]<3,>=2.13
Provides-Extra: dev
Requires-Dist: mypy>=1.11; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: responses>=0.25; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Requires-Dist: types-requests; extra == 'dev'
Provides-Extra: fastapi
Requires-Dist: fastapi>=0.110; extra == 'fastapi'
Requires-Dist: httpx>=0.27; extra == 'fastapi'
Provides-Extra: flask
Requires-Dist: flask>=3.0; extra == 'flask'
Description-Content-Type: text/markdown

# 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`](../core), built on the official
[`x402`](https://pypi.org/project/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

```bash
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)

```python
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)

```python
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:

```python
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

```bash
pip install -e '.[dev,fastapi,flask]'
pytest && ruff check . && mypy billmyagent
```

## License

Apache 2.0.
