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.1.tar.gz (7.1 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.1-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file pincer_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: pincer_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 7.1 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.1.tar.gz
Algorithm Hash digest
SHA256 7c84ff8278cc51bc9ce3f0e583b7b96f037d16a9c0f0b028ddaeec7358626711
MD5 fbbef78fba9c0c9ce890520be3ad9b9d
BLAKE2b-256 02dd76492dc3e8ebaf04e39d3b3bf83a121a9a622837bdd1b914e90df3b731e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pincer_sdk-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: pincer_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1168921f3e52ff04811866f275371209d4dc547628d58b5c3ecf61ee33a31a05
MD5 90cf37a27f536b344cedf0df9ee1b050
BLAKE2b-256 71f17ca95c41e49bb60033da0000c0255ed5bf2b55933cadb03bf010cea21525

See more details on using hashes here.

Provenance

The following attestation bundles were made for pincer_sdk-0.1.1-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