@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()
print(profile, currencies, balance, rates, sep='\n')
Create and get 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.pay_url)
invoices = await crypto.get_invoices(invoice_ids=invoice.invoice_id)
print(invoices.status)
# Get amount in crypto by fiat summ
amount = await crypto.get_amount_by_fiat(summ=100, asset='TON', target='USD')
invoice = await crypto.create_invoice(asset='TON', amount=amount)
print(invoice.pay_url)
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.pay_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.3.2.tar.gz
(9.4 kB
view details)
Built Distribution
File details
Details for the file aiocryptopay-0.3.2.tar.gz
.
File metadata
- Download URL: aiocryptopay-0.3.2.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.2 Linux/4.4.0-19041-Microsoft
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19e54a51a546d8bb04582f81ecf3866473cccbdfc1f1e8802037ba5931bb185e |
|
MD5 | 0f96c94bf26e83b12bd9fed6bbc4e0b9 |
|
BLAKE2b-256 | b0b4f2fa795ee6e22ca5d51424dada13834888e43bd3db37181923354066b9bb |
File details
Details for the file aiocryptopay-0.3.2-py3-none-any.whl
.
File metadata
- Download URL: aiocryptopay-0.3.2-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.2 Linux/4.4.0-19041-Microsoft
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d75fb493eed77bab4f18a6d587cf25a75f3c214e30146a035afb35c50a8fd23 |
|
MD5 | 676318f13594e608dd2d3bd30fe7d275 |
|
BLAKE2b-256 | a0301cc0568d55d7754c1302d0313a976e47b2c14d47c66645656dddb7e8a13d |