pympp
Python SDK for the Machine Payments Protocol
Documentation
Full documentation, API reference, and guides are available at mpp.dev/sdk/python.
Install
pip install pympp
Quick Start
Server
from mpp import Credential, Receipt
from mpp.server import Mpp
from mpp.methods.tempo import tempo, ChargeIntent
server = Mpp.create(
method=tempo(
intents={"charge": ChargeIntent()},
recipient="0x742d35Cc6634c0532925a3b844bC9e7595F8fE00",
),
)
@app.get("/paid")
@server.pay(amount="0.50")
async def handler(request, credential: Credential, receipt: Receipt):
return {"data": "...", "payer": credential.source}
If the endpoint already uses Authorization (API keys, Bearer tokens), create the server with requires_auth=True. Challenges then advertise header="Payment-Authorization", and clients send the Payment credential in that header instead of Authorization.
server = Mpp.create(method=tempo(...), requires_auth=True)
result = await server.charge(
authorization=request.headers.get("Authorization"),
amount="0.50",
payment_authorization=request.headers.get("Payment-Authorization"),
)
Client
from mpp.client import Client
from mpp.methods.tempo import tempo, TempoAccount, ChargeIntent
account = TempoAccount.from_key("0x...")
async with Client(methods=[tempo(account=account, intents={"charge": ChargeIntent()})]) as client:
response = await client.get("https://mpp.dev/api/ping/paid")
Custom transports can reuse method matching and credential creation without depending on HTTPX:
from mpp.client import PaymentTransport
from mpp.runtime import PaymentRuntime
payments = PaymentRuntime([method])
challenge, method = payments.match_challenge(challenges)
credential = await payments.create_credential(challenge, method)
transport = PaymentTransport(runtime=payments)
Examples
Stripe charge and composed-offer inputs accept payment_intent_options as a
mapping or a sync/async callable receiving PaymentIntentContext. The supported
fields are customer, receipt_email, metadata, and
hooks.inputs.tax.calculation. The input stays out of the signed challenge.
Resolvers run in the terminal payment operation, after available credential
validation; validate_credential() never invokes them.
async def options(context):
return {"metadata": {"order_id": "order_123"}}
result = await server.charge(
authorization,
"0.50",
payment_intent_options=options,
)
# Also supported in compose offer mappings and server.pay(...).
Both Stripe rails include SDK/challenge analytics. Existing configured metadata
retains its precedence, including the forced machine_payment="true" flag;
the new options' metadata overrides all generated/configured metadata. Crypto
recording retries a definitive optional-field rejection once without optional
fields, and remains best-effort after settlement.
Custom methods may implement the optional
prepare_intent(intent, input) -> (intent, request_input) hook to consume private
method-specific input before request construction. Return an isolated intent
view; never mutate a shared intent or execute deferred work during preparation.
Unconsumed unknown offer options are still rejected. Existing methods need no
changes, and the intent verification signatures and event payloads are unchanged.
| Example | Description |
|---|---|
| api-server | Payment-gated API server |
| fetch | CLI tool for fetching URLs with automatic payment handling |
| mcp-server | MCP server with payment-protected tools |
Protocol
Built on the "Payment" HTTP Authentication Scheme. See mpp-specs for the full specification.
License
MIT OR Apache-2.0
Metadata
Release files for pympp 0.14.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 | |
|---|---|---|---|
| pympp-0.14.0.tar.gz | 233.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pympp-0.14.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 358.7 kB
Release files / pympp-0.14.0.tar.gz
| Download URL | pympp-0.14.0.tar.gz |
|---|---|
| Size | 233.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
402821a577832edb3e7d68d34471180b8b5f3812847079f5682c5f8b7402a05a
|
|
BLAKE2b-256 checksum How to use checksums |
76c1e6d9ef6855e3859d982b9ae4c12e7b244b0a4be4bdae2d2fd885740d1ac2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Release files / pympp-0.14.0-py3-none-any.whl
| Download URL | pympp-0.14.0-py3-none-any.whl |
|---|---|
| Size | 125.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e9e6f6c073fa0eea26db0bd7a2dcde7468109b4305c0ae09358eb95fcb43feb6
|
|
BLAKE2b-256 checksum How to use checksums |
815e3fb49a0120f441dfac0d2cd7123108392cc582bc6384971f87f1c1987faf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|