Skip to main content

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


Download files

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

Source Distribution

pincer_sdk-0.1.2.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

pincer_sdk-0.1.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

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

Hashes for pincer_sdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 67e407beb2c99ea3e8e0601b60f05f19d934d855c2e1e69f06b762e9dfec80fd
MD5 ed2988767add95b6b919c6eb80d5b2ab
BLAKE2b-256 7febeb0b0bccbd06cb56c6c39ff14c359a8cf309be41e2e04da11f317fdfcff6

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pincer_sdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c7bfa9814325dc9269eb9ec427677b8570fe34ef751615c9f83e7219ebf25719
MD5 343010d18850a93f9f4fcf540e474ec2
BLAKE2b-256 acd6c1fe59cc738900ea1a6d15bc1d6d6bcbd617a4da71ead90d73a3fbc9b11c

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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