Sync + Async Python client for Telegram Crypto Pay API (Crypto Bot)
Project description
cryptopay-python-sdk
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cryptopay_python_sdk-0.1.2.tar.gz.
File metadata
- Download URL: cryptopay_python_sdk-0.1.2.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
054650c8729ecd5dcd156bdf2fb4a2333398aacf7da6c3ce03762f439df9abdb
|
|
| MD5 |
7dfaa9f6bccdf9a70688413803078946
|
|
| BLAKE2b-256 |
7a37bab9a01ed89ca37f97daa5a835a44f5d9c949ce07c332975c6c2d9af0b14
|
File details
Details for the file cryptopay_python_sdk-0.1.2-py3-none-any.whl.
File metadata
- Download URL: cryptopay_python_sdk-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
714ed37b0be6aeb04797cf93b2381b2b08a57facda264dc3b5ddc7f0f270ab6d
|
|
| MD5 |
a13fe3c6c98311272a3cf99d57586d97
|
|
| BLAKE2b-256 |
2c605020f156d94d0771f38fc103cfa8101f5a860e5070a457c590648e927f41
|