Skip to main content

Python SDK for PayGate x402 payment flows

Project description

deltablab-paygate

Python SDK for PayGate Cloud management, Gateway Facade request orchestration, and x402-compatible payment retries.

Install

Paid client:

pip install "deltablab-paygate[client]"

Cloud management / webhook helpers:

pip install "deltablab-paygate[cloud]"

Publisher integrations:

pip install "deltablab-paygate[publisher]"

Gateway publisher

Current public publisher path is the Cloud Gateway Facade. Use the gateway helpers for protected merchant routes.

import os

import uvicorn
from fastapi import FastAPI

from paygate.publisher import create_fastapi_gateway

app = FastAPI()
paygate = create_fastapi_gateway(
    api_key=os.environ["PAYGATE_API_KEY"],
    publisher_id=os.environ["PAYGATE_PUBLISHER_ID"],
    env="dev",
)

@app.get("/v1/weather")
@paygate.protect(endpoint_id=os.environ["PAYGATE_WEATHER_ENDPOINT_ID"])
async def weather():
    return {"city": "Shanghai", "temp": 22}


if __name__ == "__main__":
    uvicorn.run(app, host="127.0.0.1", port=8000)

For dynamic prepaid-balance flows, use create_fastapi_metered(...) and return {"quantity": "...", "body": ...} from the protected handler.

Gateway client

Current public client path is the gateway-aware paid client. It handles:

  • 401 payer_auth_required
  • 402 payment_required
  • payer_session persistence
  • 202 settling polling
import json
import os

from eth_account import Account

from paygate.client import create_gateway_client
from paygate.cloud import paygate_chain_id_for_environment

env = os.getenv("PAYGATE_ENV", "dev")
client = create_gateway_client(
    account=Account.from_key(os.environ["CLIENT_WALLET_PRIVATE_KEY"]),
    base_url="http://127.0.0.1:8000",
    payer_auth_chain_id=paygate_chain_id_for_environment(env),
)

response = client.get(
    "/v1/weather",
)
print(response.status_code)
print(json.dumps(response.json(), indent=2))

Cloud management helpers

paygate.cloud.PublisherCloudClient and AsyncPublisherCloudClient now cover:

  • GET /supported
  • POST /verify
  • POST /settle
  • /v1/gateway/*
  • /v1/access-grants*
  • /v1/usage-events
  • publishers/endpoints/webhooks/transactions/metrics

Compatibility surfaces

Legacy helpers remain available for compatibility and migration:

  • publisher compat: from paygate.publisher.compat import create_fastapi_paygate, create_starlette_paygate
  • client compat: from paygate.client.compat import create_relay_client, create_async_relay_client
  • client compat: from paygate.client.compat import create_eip3009_client, create_async_eip3009_client

PayGate Cloud URLs and chain IDs are built into the SDK. Examples typically use env="dev" for Base Sepolia development and env="prod" for Base mainnet production.

Examples

Runnable examples live in examples/README.md:

  • examples/publisher/register.py
  • examples/publisher/fastapi_app.py
  • examples/publisher/starlette_app.py
  • examples/client/weather.py
  • examples/client/llm_chat.py
  • examples/client/company_search.py
  • examples/client/premium_feed.py
  • examples/cloud_ops/endpoints.py
  • examples/cloud_ops/transactions.py
  • examples/cloud_ops/metrics.py
  • examples/cloud_ops/settlement_events.py
  • examples/cloud_ops/webhook_register.py
  • examples/cloud_ops/webhook_receiver.py

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

deltablab_paygate-0.1.1.tar.gz (34.0 kB view details)

Uploaded Source

Built Distribution

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

deltablab_paygate-0.1.1-py3-none-any.whl (45.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: deltablab_paygate-0.1.1.tar.gz
  • Upload date:
  • Size: 34.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for deltablab_paygate-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5e16d14fd54b24a086ec5b140f70b2d7cc73e1293cba8991071227f9958e3cdb
MD5 983c74ee68197176ffe9c04f7e2a32d5
BLAKE2b-256 8ca5e0ef762119cea2901a54dfc04454876e7979566a7f973dfb17230e14475a

See more details on using hashes here.

File details

Details for the file deltablab_paygate-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for deltablab_paygate-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b8826cc54aa4da9259512d795c01f586f0ae44adc143b2cac53ef743947878ce
MD5 ed030bfe817ec67335101603590e5ffc
BLAKE2b-256 69689bbe04bc8e02a6e4a8ba43a3b7fa7978ec5f667834c57e44811421d4d684

See more details on using hashes here.

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