Pine Labs Online MPP Seller SDK — x402 Machine Payments Protocol server middleware (Python)
Project description
pinelabs-online-mpp-server-sdk (Python)
Python port of @pinelabs-online/mpp-server-sdk. x402
Machine Payments Protocol server-side SDK for monetising API endpoints.
Issues HTTP 402 challenges, verifies UPI SBMD credentials, captures payments, and returns receipts — works standalone or as Flask / FastAPI middleware.
Installation
pip install pinelabs-online-mpp-server-sdk[flask] # with Flask support
pip install pinelabs-online-mpp-server-sdk[fastapi] # with FastAPI support
# or from source
cd mpp-server-sdk-python
pip install -e '.[flask,fastapi]'
Requires Python ≥ 3.9. Core deps: httpx, PyJWT[crypto].
Quick Start
Flask
from flask import Flask, jsonify
from pinelabs-online_mpp_server import Amount, ChargeOptions, MppEnvironment, pinelabs-onlineserverConfig
from pinelabs-online_mpp_server.flask_mw import payment_required
app = Flask(__name__)
config = pinelabs-onlineserverConfig(
clientId="…", clientSecret="…", challengeSecretKey="…",
baseUrl=MppEnvironment.SANDBOX,
)
@app.get("/api/premium")
@payment_required(config, ChargeOptions(
amount=Amount(value=50000, currency="INR"),
resource="/api/premium",
))
def premium():
return jsonify({"data": "premium content"})
FastAPI
from fastapi import FastAPI, Depends
from pinelabs-online_mpp_server import Amount, ChargeOptions, MppEnvironment, pinelabs-onlineserverConfig
from pinelabs-online_mpp_server.fastapi_mw import PaymentRequired
app = FastAPI()
config = pinelabs-onlineserverConfig(
clientId="…", clientSecret="…", challengeSecretKey="…",
baseUrl=MppEnvironment.SANDBOX,
)
require_payment = PaymentRequired(config, ChargeOptions(
amount=Amount(value=50000, currency="INR"),
resource="/api/premium",
))
@app.get("/api/premium", dependencies=[Depends(require_payment)])
async def premium():
return {"data": "premium content"}
Generic (any framework)
from pinelabs-online_mpp_server import Amount, ChargeOptions, MppEnvironment, pinelabs-onlineserverConfig
from pinelabs-online_mpp_server.server.middleware import decide_payment
decision = decide_payment(
authorization_header=request.headers.get("Authorization"),
grantex_token_header=request.headers.get("X-Grantex-Token"),
config=config,
charge_options=ChargeOptions(
amount=Amount(value=50000, currency="INR"),
resource="/api/premium-data",
),
)
if decision.action != "proceed":
# Build a 402/403 response from decision.problem_details + decision.headers
...
else:
# Run business logic; attach decision.headers (Payment-Receipt) to your response
...
Configuration
pinelabs-onlineserverConfig(
clientId="…", clientSecret="…", challengeSecretKey="…",
realm="pinelabs-online MPP",
baseUrl=MppEnvironment.SANDBOX,
defaultChallengeExpirySeconds=300,
requestTimeoutMs=30_000,
maxRetries=3,
initialRetryDelayMs=500,
grantex=serverGrantexConfig(
jwksUrl="https://grantex.dev/.well-known/jwks.json",
requiredScopes=["mpp:payment:initiate"],
enforceGrant=True,
),
)
API
pinelabs-onlineMPP.create(config) → pinelabs-onlineMPPInstance
| Method | Description |
|---|---|
generate_challenge(options) |
Create a signed 402 challenge |
verify_credential(auth_header) |
Verify a Payment credential |
capture(options) |
Capture a payment via pinelabs-online's API |
build_receipt_header(result, challenge_id) |
Build Payment-Receipt header value |
build_receipt_data(result, challenge_id) |
Build receipt data object |
verify_grant_token(token) |
Verify a Grantex grant token (None when not configured) |
Also exposed: ChallengeGenerator, CredentialVerifier, CaptureClient,
GrantTokenVerifier, AuthManager, build_receipt_header,
build_receipt_data, build_failure_receipt_data.
Error handling
from pinelabs-online_mpp_server import MppError, MppCaptureError, MppVerificationError
try:
result = mpp.capture(options)
except MppCaptureError as err:
print(err, err.capture_error and err.capture_error.http_status)
except MppError as err:
print(err.code, err.http_status)
License
MIT
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 pinelabs_online_mpp_server_sdk-0.1.1.tar.gz.
File metadata
- Download URL: pinelabs_online_mpp_server_sdk-0.1.1.tar.gz
- Upload date:
- Size: 19.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd2d4b36f6d1708aaf816c5d9a159b2e4e6d4f39c1476d9918ead47129efa3b1
|
|
| MD5 |
651de74fc959b308a517c8ede72e61e5
|
|
| BLAKE2b-256 |
1e0c47371c184d1b8fb73443f4c350a660a61bc083b26995373131ea0f4da9ff
|
File details
Details for the file pinelabs_online_mpp_server_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pinelabs_online_mpp_server_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 26.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9733cf10abf7805acbe42cc195135c85d1bb5775c3f51213b77ecec2053aa3e0
|
|
| MD5 |
6496ec1ccfc6638867d2e3524938be94
|
|
| BLAKE2b-256 |
2d549bfbd8a7bcad70d169e2ef86e542641606a37b99d47aca1fc4b26d502695
|