Skip to main content

TopCharge Python SDK

Python SDK for the TopCharge merchant API. The synchronous client has no external dependencies and works in Django, Flask, Celery, scripts, and WSGI apps. An optional asynchronous client works with FastAPI, Starlette, Quart, and async workers.

Release status

This SDK is prepared for publication on PyPI as topcharge.

Install from PyPI

python3 -m pip install topcharge

For async framework support:

python3 -m pip install 'topcharge[async]'

Install locally

cd /Users/chawan/Desktop/Projects/TopCharge/sdk/python
python3 -m pip install -e .

For async framework support:

python3 -m pip install -e '.[async]'

Synchronous client: Flask, Django, Celery, scripts

import os
from topcharge_sdk import TopChargeClient

client = TopChargeClient(
    client_id=os.environ["TOPCHARGE_CLIENT_ID"],
    secret_key=os.environ["TOPCHARGE_SECRET_KEY"],
)

payment = client.payments.create(
    "25000",
    description="Invoice #1001",
    redirect_url="https://merchant.example/success",
    callback_url="https://merchant.example/webhooks/payment",
)
print(payment["paymentUrl"])

Asynchronous client: FastAPI, Starlette, Quart

import os
from topcharge_sdk import AsyncTopChargeClient

async with AsyncTopChargeClient(
    os.environ["TOPCHARGE_CLIENT_ID"],
    os.environ["TOPCHARGE_SECRET_KEY"],
) as client:
    payment = await client.payments.create("25000", description="Invoice #1001")
    print(payment["paymentUrl"])

The default API host is https://api.topcharge.app. Responses are dictionaries. API failures raise TopChargeApiError, which includes status_code and response_body.

client_id is sent as x-api-key and secret_key as x-api-secret. Keep both in server-side environment variables or secret storage only; never place them in frontend code, logs, or source control.

Services

client.account.verify_credentials()
balance = client.account.get_balance()

payment = client.payments.create("25000")
status = client.payments.get_status(payment["paymentId"])
client.payments.cancel(payment["paymentId"])

client.withdrawals.create("964", "7701234567", "50000")

Every async method has the same name and parameters; prefix calls with await.

Tests and individual integration examples

PYTHONPATH=src python3 -m unittest discover -s tests -v
python3 tests/integration.py help

For the live payment smoke test (create → status → cancel):

export TOPCHARGE_RUN_INTEGRATION=1
export TOPCHARGE_CLIENT_ID='mch_...'
export TOPCHARGE_SECRET_KEY='sk_...'
python3 tests/integration.py payment:smoke

Each operation can run independently: payment:create, payment:status, payment:cancel, account:balance, and withdrawal:create. Value-moving actions require their corresponding TOPCHARGE_ALLOW_* confirmation variable. Run python3 tests/integration.py help for the full list.

Keep merchant credentials in server environment variables; never commit them to source control.

Reliability

The sync and async clients use a 30-second default timeout and do not retry automatically. Reads can generally be retried. Do not blindly retry payment creation or withdrawals after an unknown network result; resolve the original operation first.

License

MIT License

Metadata

Release files for topcharge 1.0.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 topcharge 1.0.0
File Size Uploaded Provenance
topcharge-1.0.0.tar.gz 7.0 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 14.9 kB

Release files / topcharge-1.0.0.tar.gz

Download URL topcharge-1.0.0.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
de711f00c6acadb1193daa84a165a47674ff9ca2f567da26254a99c37e6df3d8
BLAKE2b-256 checksum
How to use checksums
8cf15c51a71cceb96b3e581a4cf887f2f46900f5076daed4d0290bf5f596db5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / topcharge-1.0.0-py3-none-any.whl

Download URL topcharge-1.0.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ae5e71f958f43861428ca747ed35e6c324222706b17656047e6e902f1440c3e
BLAKE2b-256 checksum
How to use checksums
ad6f9dc69656baa4f05d0126f39550e564b6eae0b79f6045f24c5db2015c2c49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for topcharge 1.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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