@cryptobot api asynchronous python wrapper
Project description
@cryptobot asynchronous api wrapper
Docs: https://help.crypt.bot/crypto-pay-api
- MainNet - @CryptoBot
- TestNet - @CryptoTestnetBot
Install
pip install aiocryptopay
poetry add aiocryptopay
Basic methods
from aiocryptopay import AioCryptoPay, Networks
crypto = AioCryptoPay(token='1337:JHigdsaASq', network=Networks.MAIN_NET)
profile = await crypto.get_me()
currencies = await crypto.get_currencies()
balance = await crypto.get_balance()
rates = await crypto.get_exchange_rates()
stats = await crypto.get_stats()
print(profile, currencies, balance, rates, stats, sep='\n')
Create, get and delete invoice methods
from aiocryptopay import AioCryptoPay, Networks
crypto = AioCryptoPay(token='1337:JHigdsaASq', network=Networks.MAIN_NET)
invoice = await crypto.create_invoice(asset='TON', amount=1.5)
print(invoice.bot_invoice_url)
# Create invoice in fiat
fiat_invoice = await crypto.create_invoice(amount=5, fiat='USD', currency_type='fiat')
print(fiat_invoice)
old_invoice = await crypto.get_invoices(invoice_ids=invoice.invoice_id)
print(old_invoice.status)
deleted_invoice = await crypto.delete_invoice(invoice_id=invoice.invoice_id)
print(deleted_invoice)
Create, get and delete check methods
# The check creation method works when enabled in the application settings
from aiocryptopay import AioCryptoPay, Networks
crypto = AioCryptoPay(token='1337:JHigdsaASq', network=Networks.MAIN_NET)
check = await crypto.create_check(asset='USDT', amount=1)
print(check)
old_check = await crypto.get_checks(check_ids=check.check_id)
print(old_check)
deleted_check = await crypto.delete_check(check_id=check.check_id)
print(deleted_check)
WebHook usage
from aiohttp import web
from aiocryptopay import AioCryptoPay, Networks
from aiocryptopay.models.update import Update
web_app = web.Application()
crypto = AioCryptoPay(token='1337:JHigdsaASq', network=Networks.MAIN_NET)
@crypto.pay_handler()
async def invoice_paid(update: Update, app) -> None:
print(update)
async def create_invoice(app) -> None:
invoice = await crypto.create_invoice(asset='TON', amount=1.5)
print(invoice.bot_invoice_url)
async def close_session(app) -> None:
await crypto.close()
web_app.add_routes([web.post('/crypto-secret-path', crypto.get_updates)])
web_app.on_startup.append(create_invoice)
web_app.on_shutdown.append(close_session)
web.run_app(app=web_app, host='localhost', port=3001)
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
aiocryptopay-0.4.3.tar.gz
(10.6 kB
view details)
Built Distribution
File details
Details for the file aiocryptopay-0.4.3.tar.gz
.
File metadata
- Download URL: aiocryptopay-0.4.3.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.9.2 Linux/5.15.133.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82e5455466c3227410ad08bac9c636affdcb78c5268c86ad45a668048509d0a5 |
|
MD5 | dc94256e804e4459e23b6666bbffb770 |
|
BLAKE2b-256 | 46bd4e8dfc8ff467acef77d78437ce59550742196863cb2d82cef2c480b804d7 |
File details
Details for the file aiocryptopay-0.4.3-py3-none-any.whl
.
File metadata
- Download URL: aiocryptopay-0.4.3-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.9.2 Linux/5.15.133.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 857fd7cc5c6a32b78cbccbc0c07d1808bd897a4dbb48789c1822479b2254232c |
|
MD5 | 08e5a1ec77930f30cf4267a830edfe22 |
|
BLAKE2b-256 | e2a5a3607f9110f48f5f9009107ae0211c81a027f3ac9fa13bf7a70da9d3d60a |