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

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

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.

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.2.tar.gz (18.3 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.2-py3-none-any.whl (39.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hexpay-0.0.2.tar.gz
  • Upload date:
  • Size: 18.3 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.2.tar.gz
Algorithm Hash digest
SHA256 822835e452ff0307feb6a08269199b950b694abf8fe2e37f0f0d4f8e8e61ef65
MD5 76a75d672b4e70f48365e8016400d479
BLAKE2b-256 97d6858bd7f36e9a56bbc53a82c5c51d01f78eb3cae6b645091cec2bc3aa6471

See more details on using hashes here.

Provenance

The following attestation bundles were made for hexpay-0.0.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: hexpay-0.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2c21ddc8e889032899ce444f19ceece8e20f6d66b95e3d50d61eaf4144a34c76
MD5 adf3a7259c0ee2ff576047ef38d08e98
BLAKE2b-256 eb4c53dd5bee2722a58233fa90d5d72b2ed5506726da1addbba43fec1c5bb229

See more details on using hashes here.

Provenance

The following attestation bundles were made for hexpay-0.0.2-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