Skip to main content

Official Python SDK for the HexPay Merchant API (TON cryptocurrency payments).

Project description

HexPay Python SDK

Official Python client for the HexPay Merchant API — TON-blockchain cryptocurrency payments.

The client in hexpay/ is fully auto-generated from the OpenAPI spec at oapi/api.yaml. Do not edit it by hand — your changes will be overwritten on the next regeneration.

Installation

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

Or pin to a release tag:

pip install "git+https://github.com/hexpay/hexpay-python.git@v0.0.1"

Quickstart

import os
import uuid

from hexpay import AuthenticatedClient
from hexpay.api.payments import create_payment
from hexpay.models import CreatePaymentRequest

client = AuthenticatedClient(
    base_url="https://api.hexpay.io",
    token=os.environ["HEXPAY_TOKEN"],
)

payment = create_payment.sync(
    client=client,
    body=CreatePaymentRequest(amount="100.00", currency="USD"),
    x_idempotency_key=str(uuid.uuid4()),
)

print(payment.id, payment.checkout_url)

Authentication

All endpoints require a JWT obtained from the HexPay merchant dashboard. Pass it as the token argument to AuthenticatedClient. Never hard-code tokens — load them from environment variables, a secrets manager, or your config layer.

Idempotency

Every POST request requires a UUID v4 X-Idempotency-Key. The SDK exposes it as the x_idempotency_key argument on every mutating operation.

Reuse the same key when retrying a failed request — the server returns the cached response from the first attempt instead of creating a duplicate payment. Generate a fresh key for each new logical operation.

See examples/idempotency_retry.py for a complete retry loop that gets this right.

Async

Every endpoint exposes both sync and asyncio entry points:

import asyncio
from hexpay.api.payments import list_payments

async def main():
    page = await list_payments.asyncio(client=client, limit=20)
    for p in page.payments:
        print(p.id, p.status)

asyncio.run(main())

Examples

Runnable scripts under examples/ — each is self-contained and reads HEXPAY_TOKEN (and optionally HEXPAY_BASE_URL) from the environment:

File What it shows
create_payment_customer_choice.py Customer-Choice mode — checkout picks the method
create_payment_preselected.py Preselected USDT/TON — pending immediately
retrieve_payment.py Fetch full payment details
poll_payment_status.py Lightweight status polling loop
list_payments.py Cursor-based pagination
cancel_payment.py Cancel an active payment
list_payment_methods.py Discover store-enabled coin/chain combos
error_handling.py Pattern for inspecting structured errors
idempotency_retry.py Safe retry loop preserving the idempotency key

Run them with:

make gen install                # generate client + install into .venv/
export HEXPAY_TOKEN="<your-jwt>"
.venv/bin/python examples/create_payment_customer_choice.py

Or activate the venv once and use plain python:

source .venv/bin/activate
python examples/create_payment_customer_choice.py

Regeneration

make gen      # rebuild hexpay/ from oapi/api.yaml — runs in Docker
make install  # editable install into a local venv
make lint     # ruff check

make gen builds a small image from gen.Dockerfile (based on python:3.12-slim with openapi-python-client preinstalled) and runs it against the spec — no host Python required. The generator version is pinned by OPENAPI_PYTHON_CLIENT_VERSION in the Dockerfile.

CI (.github/workflows/generate.yml) runs the same make gen on every push to a non-main branch and commits the regenerated client back to the branch.

Compatibility

  • Python ≥ 3.9
  • httpx ≥ 0.23, < 0.29
  • Type hints throughout (py.typed)

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

hexpay-0.0.1.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

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

hexpay-0.0.1-py3-none-any.whl (39.7 kB view details)

Uploaded Python 3

File details

Details for the file hexpay-0.0.1.tar.gz.

File metadata

  • Download URL: hexpay-0.0.1.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hexpay-0.0.1.tar.gz
Algorithm Hash digest
SHA256 1b8c008bd3d1e294f482942905d692894a6ba8491e206fdb89876b202ccc9309
MD5 c39753e854f9b4b55c3dc7e257f7fd4b
BLAKE2b-256 072a0a7d5cb0db586efada87c24076ba0eeaa0f34b809cd1e4b587c842de95ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for hexpay-0.0.1.tar.gz:

Publisher: release.yml on hexpay-io/hexpay-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 hexpay-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: hexpay-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 39.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hexpay-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6f8d7ac3bc088fa3899081ba4cea0d26416ad8aa72990f183c6a8884e7adb67a
MD5 08ad7cb54a34afe95af30ea9470450a1
BLAKE2b-256 9195c1ec98304bea413c1dd4ce7d50d842ab26b3c7d92faa8c57341803e634da

See more details on using hashes here.

Provenance

The following attestation bundles were made for hexpay-0.0.1-py3-none-any.whl:

Publisher: release.yml on hexpay-io/hexpay-python

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