Skip to main content

USDPAY Python SDK

Official Python SDK for USDPAY.

Accept USDT directly to your wallet. USDPAY verifies the payment on-chain and notifies your application automatically with signed webhooks.

Requirements

  • Python 3.10 or newer
  • A USDPAY store secret key for authenticated methods
  • A server-side application; never expose the secret key in browser or mobile code

Installation

pip install usdpay

Quick Start

import os

from usdpay import UsdpayClient

client = UsdpayClient(
    secret_key=os.environ["USDPAY_SECRET"]
)

result = client.create_invoice(
    {
        "amount": "49.00",
        "orderId": "ORDER-1042",
        "network": "TRC20",
        "callbackUrl": "https://merchant.example/usdpay/webhook",
        "returnUrl": "https://merchant.example/orders/1042",
    },
    idempotency_key="ORDER-1042-create",
)

print(result["invoice"]["checkoutUrl"])

Create an Invoice

create_invoice() sends POST /api/invoices. JSON field names match the REST API exactly.

result = client.create_invoice(
    {
        "amount": "49.00",
        "orderId": "ORDER-1042",
        "network": "TRC20",
        "expiresInMinutes": 30,
        "callbackUrl": "https://merchant.example/usdpay/webhook",
        "returnUrl": "https://merchant.example/orders/1042",
    },
    idempotency_key="ORDER-1042-create",
)

Omit network to let the customer choose an enabled network in the hosted checkout.

Get an Invoice

result = client.get_invoice("inv_7Fq2xK9")
print(result["invoice"]["status"])

The production API exposes this status endpoint to anyone who has the unguessable invoice ID. The SDK therefore does not send your Bearer key with get_invoice().

List Invoices

result = client.list_invoices()
for invoice in result["invoices"]:
    print(invoice["id"], invoice["status"])

list_invoices() is authenticated and returns invoices for the store selected by the secret key. The current API does not define filtering or pagination parameters, so the SDK does not invent any.

Fiat Order Amounts

Keep monetary values as decimal strings. USDPAY performs the currency conversion; the SDK does not use floating-point math or calculate FX rates.

result = client.create_invoice(
    {
        "amount": "49.00",
        "currency": "EUR",
        "orderId": "ORDER-1042",
        "callbackUrl": "https://merchant.example/usdpay/webhook",
    },
    idempotency_key="ORDER-1042-create",
)

Idempotency

Pass one stable idempotency_key for a logical create operation. If a timeout, 429, or retryable 5xx occurs, retry with the same key. Do not generate a new key for each attempt.

USDPAY accepts 1–160 letters, digits, dots, underscores, colons, or hyphens. The SDK validates the key but does not automatically retry requests.

Verify Webhooks

Verify the signature against the exact raw request body before parsing JSON.

import os

from usdpay import verify_webhook_signature

raw_body = request_body_bytes
signature = request_headers.get("X-USDPAY-Signature", "")

if not verify_webhook_signature(
    raw_body,
    signature,
    os.environ["USDPAY_WEBHOOK_SECRET"],
):
    # Return HTTP 401.
    ...

The signature format is sha256=<hex HMAC-SHA256>. Store X-USDPAY-Idempotency-Key under a unique database constraint before fulfilling an order, and acknowledge an already processed delivery with a 2xx response.

Error Handling

from usdpay import UsdpayApiError

try:
    client.create_invoice(
        {"amount": "49.00", "orderId": "ORDER-1042"},
        idempotency_key="ORDER-1042-create",
    )
except UsdpayApiError as exc:
    print(exc.status)
    print(exc.code)
    print(exc.retry_after)
    print(exc.request_id)

UsdpayApiError covers HTTP failures, timeouts, network failures, and malformed JSON. Its public attributes are:

  • status: HTTP status, or 0 when no HTTP response was received
  • code: stable API or SDK error code
  • details: redacted response object when available
  • retry_after: parsed Retry-After seconds or HTTP-date
  • request_id: response request identifier for support

Security

  • Keep USDPAY_SECRET and the webhook signing secret on your server.
  • The default transport accepts HTTPS only and uses Python's verified system trust store with hostname verification.
  • Requests have finite connect and response timeouts; configure them with connect_timeout and timeout.
  • The client does not follow redirects or make network calls when imported.
  • Secrets are not included in repr(client), public exception messages, or exception details.
  • Never disable TLS verification.

Documentation

License

MIT © 2026 PIXELTIDE LLC.

Download files

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

Source Distribution

usdpay-1.0.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

usdpay-1.0.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file usdpay-1.0.0.tar.gz.

File metadata

  • Download URL: usdpay-1.0.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for usdpay-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c4750fe5206b5353854edc67c0c75fc62507a947dcee83d4469bd8c8307278d0
MD5 caf6a74bdb5aa587b8d10ee9db8b4247
BLAKE2b-256 f8a2112f7e3de0fba181661f38f2e9263cf80f6b6c011a9c5426c21f8b466788

See more details on using hashes here.

Provenance

The following attestation bundles were made for usdpay-1.0.0.tar.gz:

Publisher: release.yml on probizi/usdpay-python

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

File details

Details for the file usdpay-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: usdpay-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for usdpay-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 226f338e1c6af1d63a85c441d7c447615bb18c8f5e79d849e80df0b9ee033792
MD5 76d9d818fee993314411a2257f69282f
BLAKE2b-256 fc7003dd097a33a0de0cd2d2b40d9f37e948f10f74db62d93d7efcce5c38b05c

See more details on using hashes here.

Provenance

The following attestation bundles were made for usdpay-1.0.0-py3-none-any.whl:

Publisher: release.yml on probizi/usdpay-python

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

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page