Plaidly Docs

Python Integration

Accept crypto payments in Python applications

Python Integration

Install the official Plaidly Python SDK:

Not yet published to the package registry

plaidly-python is not yet published to PyPI — install from source until registry publication ships.

pip install git+https://github.com/plaidly/plaidly-python.git

Once published, the intended install command will be:

pip install plaidly-python

Initialize the client

import os
from plaidly import PlaidlyClient

plaidly = PlaidlyClient(api_key=os.environ["PLAIDLY_API_KEY"])

Create and poll a payment session

session = plaidly.payment_sessions.create(
    amount=10.0,
    chain="solana",
    token="USDC",
    network="mainnet",
    expires_in="15m",
    metadata={"order_id": "ord_123"},
)

print(session.address)

latest = plaidly.payment_sessions.get(session.session_id)
print(latest.status)

Sandbox onboarding

from plaidly.helpers import onboard_sandbox_with_simulation

with PlaidlyClient(api_key=os.environ["PLAIDLY_API_KEY"]) as client:
    merchant = client.merchants.register(
        name="Example Sandbox Merchant",
        webhook_url="https://example.test/webhook",
    )

    result = onboard_sandbox_with_simulation(
        client,
        chain="solana",
        token="USDC",
        network="testnet",
        amount=1.0,
        simulate=True,
        include_receipt=True,
        attempts=10,
    )

print(merchant.api_key)
print(result.terminal_session.status)
print(len(result.receipt or b""))

Demo and public discovery

demo = plaidly.payment_sessions.create_demo(
    chain="ethereum",
    token="USDC",
    network="testnet",
    amount=5.0,
)

done = plaidly.payment_sessions.simulate(demo.session_id)
print(done.is_paid)
print(plaidly.faucets())

x402 paid resources

The Python SDK exports the same x402 helper surface used by the Node, Go, and PHP SDKs: parse_x402_challenge, parse_x402_challenge_from_header, resolve_x402_proof, and retry_request_with_x402_proof.

import httpx
from plaidly import retry_request_with_x402_proof


def do_request(proof: str, payment_header: str) -> httpx.Response:
    headers = {}
    if proof:
        headers[payment_header] = proof
    return httpx.get("https://api.example.com/paid-resource", headers=headers)


response = retry_request_with_x402_proof(
    do_request,
    proof_provider=my_wallet_or_plaidly_facilitator,
)

Verify webhooks

FastAPI

import os
from fastapi import FastAPI, HTTPException, Request
from plaidly import verify_webhook_signature_any

app = FastAPI()

@app.post("/webhook")
async def webhook(request: Request):
    raw_body = await request.body()
    signature = request.headers.get("x-plaidly-signature", "")

    valid = verify_webhook_signature_any(
        payload=raw_body,
        signature=signature,
        secrets=(
            os.environ["PLAIDLY_WEBHOOK_SECRET_NEW"],
            os.environ["PLAIDLY_WEBHOOK_SECRET_OLD"],
        ),
    )
    if not valid:
        raise HTTPException(status_code=400, detail="Invalid signature")

    event = await request.json()
    if event["event_type"] == "payment_session.completed":
        await fulfill_order(event["session_id"])

    return {"status": "ok"}

Django

import json
from django.http import HttpResponse, HttpResponseBadRequest
from django.views.decorators.csrf import csrf_exempt
from plaidly import verify_webhook_signature

@csrf_exempt
def webhook(request):
    signature = request.headers.get("X-Plaidly-Signature", "")
    if not verify_webhook_signature(
        payload=request.body,
        signature=signature,
        secret=settings.PLAIDLY_WEBHOOK_SECRET,
    ):
        return HttpResponseBadRequest("Invalid signature")

    event = json.loads(request.body)
    if event["event_type"] == "payment_session.completed":
        fulfill_order.delay(event["session_id"])

    return HttpResponse(status=200)

Agent example flows

The helper scripts under plaidly-python/examples/helpers/ cover the same flows used by the agent docs:

  • payment_session.py for create-and-wait and demo polling
  • sandbox_onboarding.py for merchant registration plus sandbox simulation
  • webhook.py for timestamped signature verification

On this page