Pincer SDK for Python - Reference implementation for x402 protocol
Project description
Pincer SDK for Python
Simple, machine-native payments for the AI economy.
The Pincer SDK is a lightweight wrapper for the x402 protocol, specifically designed to handle Post-Pay Rebates and sponsored access. It enables API providers (Sellers) to monetize their services while allowing sponsors (Merchants) to subsidize the cost for high-intent agents.
🚀 Quick Start
Installation
pip install pincer-sdk
1. For Sellers: Protect your API
Sellers use Pincer to verify x402 payments and identify active sponsors using the built-in middleware.
from src.pincer_sdk import PincerClient
from src.pincer_sdk.middleware import PincerPaymentMiddleware
from x402.server import x402ResourceServer
client = PincerClient(
base_url="https://your-pincer-url.com",
api_key="your_api_key"
)
# Initialize standard x402 server with Pincer facilitator
server = x402ResourceServer(client.facilitator())
# Add Pincer middleware to your FastAPI app
app.add_middleware(PincerPaymentMiddleware, routes=routes, server=server)
# Your FastAPI route
@app.get("/premium-data")
async def get_data(request: Request):
# Payment is already verified here!
# Sponsors are automatically injected into the request state
payment = getattr(request.state, "payment", None)
sponsors = getattr(payment, "sponsors", []) if payment else []
return {
"data": "Premium content",
"applied_sponsors": sponsors
}
2. For Merchants: Report Conversions
Merchants notify Pincer when a transaction occurs to trigger user rebates.
from pincer_sdk import PincerClient
async with PincerClient(
base_url="https://pincer.zeabur.app", # URL is now required
webhook_secret="your_secret"
) as pincer:
await pincer.report_conversion(
session_id="sess-123",
user_address="0x...",
purchase_amount=25.0,
merchant_id="my-store"
)
🏗 Why Pincer SDK?
The Pincer SDK enhances the base x402 experience by:
- Injecting Sponsorship Data: Automatically capturing sponsor offers during the verification phase.
- Simplifying Webhooks: Providing signed conversion reporting for merchants out of the box.
- Managing Identity: Properly handling session IDs across the payment lifecycle.
📄 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 pincer_sdk-0.1.2.tar.gz.
File metadata
- Download URL: pincer_sdk-0.1.2.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67e407beb2c99ea3e8e0601b60f05f19d934d855c2e1e69f06b762e9dfec80fd
|
|
| MD5 |
ed2988767add95b6b919c6eb80d5b2ab
|
|
| BLAKE2b-256 |
7febeb0b0bccbd06cb56c6c39ff14c359a8cf309be41e2e04da11f317fdfcff6
|
Provenance
The following attestation bundles were made for pincer_sdk-0.1.2.tar.gz:
Publisher:
sdk-ci-cd.yml on pincerclaw/pincer-x402-starter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pincer_sdk-0.1.2.tar.gz -
Subject digest:
67e407beb2c99ea3e8e0601b60f05f19d934d855c2e1e69f06b762e9dfec80fd - Sigstore transparency entry: 936993659
- Sigstore integration time:
-
Permalink:
pincerclaw/pincer-x402-starter@e7d4976bffc97c2eba3854067b834f6ed567ed9f -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/pincerclaw
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-ci-cd.yml@e7d4976bffc97c2eba3854067b834f6ed567ed9f -
Trigger Event:
release
-
Statement type:
File details
Details for the file pincer_sdk-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pincer_sdk-0.1.2-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7bfa9814325dc9269eb9ec427677b8570fe34ef751615c9f83e7219ebf25719
|
|
| MD5 |
343010d18850a93f9f4fcf540e474ec2
|
|
| BLAKE2b-256 |
acd6c1fe59cc738900ea1a6d15bc1d6d6bcbd617a4da71ead90d73a3fbc9b11c
|
Provenance
The following attestation bundles were made for pincer_sdk-0.1.2-py3-none-any.whl:
Publisher:
sdk-ci-cd.yml on pincerclaw/pincer-x402-starter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pincer_sdk-0.1.2-py3-none-any.whl -
Subject digest:
c7bfa9814325dc9269eb9ec427677b8570fe34ef751615c9f83e7219ebf25719 - Sigstore transparency entry: 936993669
- Sigstore integration time:
-
Permalink:
pincerclaw/pincer-x402-starter@e7d4976bffc97c2eba3854067b834f6ed567ed9f -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/pincerclaw
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-ci-cd.yml@e7d4976bffc97c2eba3854067b834f6ed567ed9f -
Trigger Event:
release
-
Statement type: