Skip to main content

altpay-py

Official Python SDK for the AltPay crypto-payments API. Synchronous and asynchronous clients, typed models, request signing and webhook verification in one package. Built on httpx and pydantic v2.

pip install altpay-py
import altpay  # the distribution is altpay-py; the import name is altpay

Quick start

from decimal import Decimal
from altpay import AltPay, Credentials

client = AltPay(Credentials(
    merchant_id="YOUR_MERCHANT_ID",
    api_key="vc_live_...",
    api_secret="YOUR_API_SECRET",
))

invoice = client.invoices.create(
    uuid="order-42",                 # your idempotency key / order reference
    amount=Decimal("100.00"),
    fiat_currency="USD",
    url_callback="https://example.com/altpay/webhook",
)
print(invoice.url)                   # hosted checkout URL to redirect the payer to

# later, check on it
invoice = client.invoices.get(order_id=invoice.order_id)
print(invoice.status)                # PaymentStatus.WAITING | PAID | EXPIRED | ...

Async

The async client mirrors the sync one exactly; just await the calls.

from altpay import AsyncAltPay, Credentials

async with AsyncAltPay(creds) as client:
    invoice = await client.invoices.create(
        uuid="order-42", amount="100.00", fiat_currency="USD",
    )
    print(invoice.url)

What you can do

Resource Method Endpoint
client.invoices create(...) create an invoice
get(order_id=... | uuid=...) fetch one invoice
list(status=..., cursor=..., limit=...) page through invoices
services() available methods, limits and fees
balance(fiat_currency=...) balance valued in one fiat, per asset
create_wallet(network=..., order_id=...) static deposit wallet
list_wallets(limit=..., offset=...) list static wallets
client.account get() merchant + API-key identity
balance() paid volume per method (native asset)
statistics() aggregate counts and USD volume

Webhooks

AltPay POSTs a signed payment.updated event to your url_callback when an invoice is paid. Always verify the signature before trusting the body, and pass the raw request bytes (not the re-serialized JSON).

from altpay import WebhookVerifier

verifier = WebhookVerifier(WEBHOOK_SECRET, target="/altpay/webhook")

# inside your handler (framework-agnostic):
event = verifier.parse(raw_body, request_headers)   # raises AuthenticationError on a bad sig
if event.status == "paid":
    fulfil_order(event.merchant_reference)

verifier.verify(raw_body, headers) returns a bool if you prefer to branch yourself.

Errors

Every failure is an AltPayError. Network problems raise AltPayTransportError; anything the API rejected raises an APIError subclass keyed by HTTP status. Each carries the server's machine-readable detail, a human hint, and the request_id for support.

from altpay import AuthenticationError, RateLimitError, ValidationError, NotFoundError

try:
    client.invoices.create(uuid="o1", amount="100", fiat_currency="USD")
except AuthenticationError as e:
    ...   # bad credentials / clock skew / revoked key  (HTTP 401, detail="invalid_signature")
except ValidationError as e:
    ...   # a field failed validation                   (HTTP 400, detail="invalid_request")
except RateLimitError as e:
    sleep(e.retry_after or 1)                            # HTTP 429
except NotFoundError as e:
    ...                                                  # HTTP 404

The full catalogue, with every detail value and how to fix it, is at https://docs.altpay.money/docs/http-codes.

Configuration

AltPay(
    credentials,
    base_url="https://api.altpay.money",  # override for staging
    timeout=30.0,                          # per-request seconds
    max_retries=2,                         # retry transient errors (5xx, 429, network) with backoff
    http_client=my_httpx_client,           # bring your own httpx.Client (proxies, custom TLS)
)

Authentication, in brief

Each request is signed with HMAC-SHA256 over a canonical string of the merchant id, API key, timestamp, nonce, body hash, method and path. The SDK does this for you; the secret never leaves your process. If you ever need the primitives (custom transport, testing), they live in altpay.signing. Full spec: https://docs.altpay.money/docs/authentication.

Requirements

  • Python 3.10+
  • httpx >= 0.24, pydantic >= 2.0

License

MIT

Download files

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

Source Distribution

altpay_py-0.1.2.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

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

altpay_py-0.1.2-py3-none-any.whl (35.2 kB view details)

Uploaded Python 3

File details

Details for the file altpay_py-0.1.2.tar.gz.

File metadata

  • Download URL: altpay_py-0.1.2.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for altpay_py-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bdbb40445e45b37e3e7f0321657f0bbdbbd4cf8d21d6864336bb8b6803fa6f51
MD5 cb8220b92f181c29c8ae836cf6213cd6
BLAKE2b-256 e2982523fa069c444036080ac540e3b421e5953c6b66e302b6702e7c9684c1a6

See more details on using hashes here.

File details

Details for the file altpay_py-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: altpay_py-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 35.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for altpay_py-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c3fad84b0c2b47b926f5fe4d727a24fb6cba11a78355e3b77a36176a758050fc
MD5 54b4142e9cb35aaed05a355e02c260c0
BLAKE2b-256 661418aa1e0c2b195624e8bb238012859bf13a34434fda78439e97547b6f5bc1

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.3

2 files

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

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