Skip to main content

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

Latest stable release from PyPI:

pip install hexpay

Pin to a specific version (recommended for production — see Releases for available tags):

pip install "hexpay==X.Y.Z"

Or install straight from the repo — main for the latest commit, or any tag:

pip install "git+https://github.com/hexpay-io/hexpay-python.git@main"
pip install "git+https://github.com/hexpay-io/hexpay-python.git@vX.Y.Z"

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

POST requests accept an optional X-Idempotency-Key (UUID). 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.

Metadata

Release files for hexpay 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hexpay 0.1.0
File Size Uploaded Provenance Actions
hexpay-0.1.0.tar.gz 19.9 kB With provenance Details for hexpay-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hexpay 0.1.0
File Interpreter ABI Platform Actions
hexpay-0.1.0-py3-none-any.whl Python 3 none any Details for hexpay-0.1.0-py3-none-any.whl

Total release size: 64.8 kB

Release files / hexpay-0.1.0.tar.gz

Download URL hexpay-0.1.0.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
208a6213ff0ac07d64fb398788e4243b3a95d136147da54715b560824c88ebac
BLAKE2b-256 checksum
How to use checksums
e721ec25ef9edd60f615a54c6ae78988b49536f2429481af7fc9a6b915d2e2bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / hexpay-0.1.0-py3-none-any.whl

Download URL hexpay-0.1.0-py3-none-any.whl
Size 44.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d9a962dea57d4db4f8b49a4a39502a3e62bae766d9ed1e798dea9ed30cc3e16
BLAKE2b-256 checksum
How to use checksums
a05d261eb3c4769d64c3d0fd7014b6b0c93ae5fc1da1c1041cfc1775d9a7c78f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Security for hexpay 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hexpay-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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