Skip to main content

Sync + Async Python client for Telegram Crypto Pay API (Crypto Bot)

Project description

cryptopay-python-sdk

PyPI Python License: MIT

Sync + async Python client for the Telegram Crypto Pay API.

Supports Python 3.9+, type-annotated, and has no heavy dependencies — just httpx for async and requests for sync.

Install

pip install cryptopay-python-sdk

Quick start

Async (recommended)

import asyncio
from crypto_pay_api import CryptoPayAsync, CryptoPayConfig

async def main():
    cfg = CryptoPayConfig(token="YOUR_TOKEN")
    async with CryptoPayAsync(cfg) as cp:
        invoice = await cp.create_invoice(asset="USDT", amount=5)
        print(invoice["pay_url"])

asyncio.run(main())

Sync

from crypto_pay_api import CryptoPay, CryptoPayConfig

cfg = CryptoPayConfig(token="YOUR_TOKEN")
with CryptoPay(cfg) as cp:
    invoice = cp.create_invoice(asset="USDT", amount=5)
    print(invoice["pay_url"])

Both clients are context managers that close the underlying HTTP session automatically.

Configuration

from crypto_pay_api import CryptoPayConfig

cfg = CryptoPayConfig(
    token="YOUR_TOKEN",          # required — get it from @CryptoBot on Telegram
    network="mainnet",           # "mainnet" (default) or "testnet"
    timeout=20.0,                # request timeout in seconds (default: 20.0)
    base_url_override=None,      # override the API base URL if needed
)

Methods

All methods are available on both CryptoPay (sync) and CryptoPayAsync (async) with identical signatures.

App

Method Description
get_me() Returns basic info about the app associated with the token
get_balance() Returns list of balance objects per asset
get_exchange_rates() Returns current exchange rates
get_currencies() Returns list of supported currencies
get_stats(*, start_at, end_at) Returns app statistics for a given date range

Invoices

Method Description
create_invoice(*, amount, ...) Create a payment invoice
delete_invoice(invoice_id) Delete an invoice by ID
get_invoices(*, asset, fiat, invoice_ids, status, offset, count) List invoices with optional filters

create_invoice parameters:

Parameter Type Description
amount str | float Amount to charge (required)
currency_type "crypto" | "fiat" Type of currency (optional)
asset str Crypto asset, e.g. "USDT", "TON"
fiat str Fiat currency code, e.g. "USD"
accepted_assets str Comma-separated accepted assets (for fiat invoices)
swap_to str Auto-swap received asset to this asset
description str Invoice description shown to the payer
hidden_message str Message shown after payment
paid_btn_name str Label for the button after payment
paid_btn_url str URL for the button after payment
payload str Custom string attached to the invoice (max 4kb)
allow_comments bool Allow payer to leave a comment
allow_anonymous bool Allow anonymous payments
expires_in int Invoice lifetime in seconds

Checks

Method Description
create_check(*, asset, amount, pin_to_user_id, pin_to_username) Create a check
delete_check(check_id) Delete a check by ID
get_checks(*, asset, check_ids, status, offset, count) List checks with optional filters

Transfers

Method Description
transfer(*, user_id, asset, amount, spend_id, comment, disable_send_notification) Send coins to a Telegram user
get_transfers(*, asset, transfer_ids, spend_id, offset, count) List transfers with optional filters

Webhook verification

Verify incoming webhooks from Crypto Pay using the built-in helper:

from crypto_pay_api import verify_webhook_signature

is_valid = verify_webhook_signature(
    token="YOUR_TOKEN",
    raw_body=request.body,                                    # raw bytes
    signature_header=request.headers["crypto-pay-api-signature"],
)

if not is_valid:
    return 403

Error handling

from crypto_pay_api import CryptoPayAPIError, CryptoPayHTTPError

try:
    invoice = cp.create_invoice(asset="USDT", amount=5)
except CryptoPayAPIError as e:
    # API returned ok=false (e.g. invalid token, bad params)
    print(e.error_code)  # string error code from the API
    print(e.raw)         # full raw response dict
except CryptoPayHTTPError as e:
    # Network error or non-2xx HTTP response
    print(e)

Error hierarchy:

CryptoPayError          ← base class
├── CryptoPayAPIError   ← API returned ok=false
└── CryptoPayHTTPError  ← network / HTTP-level error

License

MIT

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

cryptopay_python_sdk-0.1.3.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

cryptopay_python_sdk-0.1.3-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file cryptopay_python_sdk-0.1.3.tar.gz.

File metadata

  • Download URL: cryptopay_python_sdk-0.1.3.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cryptopay_python_sdk-0.1.3.tar.gz
Algorithm Hash digest
SHA256 132eda8002060b573eac2d56bd5c20dc28fe1b7136ec3d54569603e7f54aef5b
MD5 00cfd507d609895371b9032cd32c2189
BLAKE2b-256 8eb54338bb5f241433894c76a1f7f7cc65b49fff8883050369be134e7214633a

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryptopay_python_sdk-0.1.3.tar.gz:

Publisher: publish.yml on medovi40k/crypto-pay-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryptopay_python_sdk-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for cryptopay_python_sdk-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 777740b03989a331b3e329386b3c1645cd5acb760333e788519f89c0e906052e
MD5 b0d603e0d164af7a4fa6390c756522c3
BLAKE2b-256 e01e8fed318f32da741b8f5adcafd34d9ef36d2bc4c952e9aa5375596f12a611

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryptopay_python_sdk-0.1.3-py3-none-any.whl:

Publisher: publish.yml on medovi40k/crypto-pay-api

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