Skip to main content

HTTP 402 Payment Authentication for Python

Project description

pympp

Python SDK for the Machine Payments Protocol

PyPI License

Documentation

Full documentation, API reference, and guides are available at machinepayments.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()},
        currency="0x20c0000000000000000000000000000000000000",
        recipient="0x742d35Cc6634c0532925a3b844bC9e7595F8fE00",
    ),
)

@app.get("/paid")
@server.pay(amount="0.50")
async def handler(request, credential: Credential, receipt: Receipt):
    return {"data": "...", "payer": credential.source}

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://api.example.com/resource")

Examples

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pympp-0.3.0.tar.gz (90.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pympp-0.3.0-py3-none-any.whl (59.1 kB view details)

Uploaded Python 3

File details

Details for the file pympp-0.3.0.tar.gz.

File metadata

  • Download URL: pympp-0.3.0.tar.gz
  • Upload date:
  • Size: 90.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pympp-0.3.0.tar.gz
Algorithm Hash digest
SHA256 474569986fd50e9b7ec01a3c179b9dada25b391c818862ba4b5aa90c645d607c
MD5 2f5236e2fb560fa2117f7f2542ea9cb3
BLAKE2b-256 f3685dd504ac39be984c0a541d33e8dcf0a5a339359fc724062f0e54f2ee1506

See more details on using hashes here.

File details

Details for the file pympp-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pympp-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 59.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pympp-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 136b2522e3e9b20d97e72101efb4e36a575cd8d26969b50140303c4517c980a0
MD5 5ab505bbcb828914ba09f78b388df096
BLAKE2b-256 8357082ab6efdcdcd1c06043686f7768d6a96583552e81e1289d98f3fe58185e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page