Skip to main content

aiopaysell

Python License Pydantic v2 Aiohttp Code linter: ruff Checked with mypy

aiopaysell is an async Python client for the Paysell payment API — accept TON & USDT on TON with invoices, webhooks, and a polling fallback.

API documentation

Install

pip install aiopaysell
# pip install aiopaysell[fastapi]   # if you use the FastAPI webhook manager

Quick start

import asyncio
from aiopaysell import Paysell


async def main():
    pay = Paysell("sk_live_YOUR_KEY")

    invoice = await pay.create_invoice("TON", 5, order_id="order-1042")
    print(f"pay: {invoice.payment_url}")


if __name__ == "__main__":
    asyncio.run(main())

Webhook example

webhook_secret is not your API key — it's a separate secret shown once, next to the key, when you create it. Without it no delivery can be verified, and payment_credited never fires.

from aiohttp import web
from magic_filter import F
from aiopaysell import Paysell
from aiopaysell.webhook import AiohttpManager

app = web.Application()
pay = Paysell(
    "sk_live_YOUR_KEY",
    webhook_manager=AiohttpManager(app, path="/webhooks/paysell"),
    webhook_secret="YOUR_WEBHOOK_SECRET",
)


@pay.payment_credited(F.status == "paid")
async def on_paid(payment):
    print(f"order {payment.order_id} paid, {payment.credited_int} credited")


@pay.payment_rejected()
async def on_rejected(payment):
    print(f"order {payment.order_id}: deposit rejected ({payment.reason})")


if __name__ == "__main__":
    web.run_app(app, port=8080)

FastAPI works the same way via aiopaysell.webhook.FastAPIManager. No webhooks in local dev? Poll instead:

@pay.invoice_paid()
async def on_paid(invoice):
    print(invoice.status)


invoice = await pay.create_invoice("TON", 1.5)
invoice.poll()
await pay.start_polling()

Webhook and polling events live on separate routers (payment_credited/payment_rejected vs. invoice_paid/invoice_expired/invoice_cancelled) — running both is safe, just make handlers idempotent since the same payment could be reported by each.

Need your own checkout page instead of redirecting to payment_url? pay.get_public_invoice(invoice_id) reads the same unauthenticated endpoint the hosted page uses — no API key needed.

More in examples/: FastAPI webhooks, a standalone router for splitting handlers across modules, polling, a public-invoice checkout.

Good to know

  • webhook_secret is required for webhooks to work at all. It's shown once when the key is created, separately from the key itself. Passing webhook_manager= without it raises immediately; leaving both out (polling-only usage) is fine.
  • create_invoice(amount=...) takes normal units, like on an exchange5, 1.5, Decimal("1.5") — and formats them for you (decimal places validated against the coin). Pass a str if you already have it formatted and want it sent through unchanged.
  • The REST API and the webhook body disagree about units, on purpose. Invoice.amount is normal units, exactly what you sent; Invoice.amount_minor is the same as an integer smallest-unit string — use Invoice.amount_minor_int. Webhook payloads (PaymentCredited.amount, .credited, .fee) are smallest-unit integers throughout — use the matching *_int properties.
  • idempotency_key is yours to generate and persist per order; the library won't invent one for you, since its entire value is surviving a retry with the same key.
  • The webhook signature is HMAC-SHA256(secret, "{timestamp}.{raw_body}"), header names X-Paysell-Signature / X-Paysell-Timestamp. aiopaysell verifies both, including a ±5 minute replay window, before any handler runs.
  • There's a single network (https://paysell.me) — no test/live split to configure, the client always talks to it.

Errors

Status Exception
401 AuthenticationError
404 NotFoundError
409 ConflictError
422 InvalidRequestError
429 RateLimitError (.retry_after holds the Retry-After header, in seconds, when present)
502 BadGatewayError (safe to retry with the same idempotency_key)

All inherit aiopaysell.exceptions.APIErrorPaysellError.

License

MIT

Release files for aiopaysell 0.7.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 aiopaysell 0.7.0
File Size Uploaded
aiopaysell-0.7.0.tar.gz 175.6 kB Details

Built distribution (wheel)

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

Total release size: 215.7 kB

Release files / aiopaysell-0.7.0.tar.gz

Download URL aiopaysell-0.7.0.tar.gz
Size 175.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ea351b77a5fa88540aaabab71936e90e5f3b8b0d743ae72935f6e8c7e2ac7c15
BLAKE2b-256 checksum
How to use checksums
5c9159a5395edda31b498c4d8e3fb9cc9ccabbf15cda5a32127e750d745311da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / aiopaysell-0.7.0-py3-none-any.whl

Download URL aiopaysell-0.7.0-py3-none-any.whl
Size 40.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ec5d0e86cb06889122697d1ed8c7427b8ed92d8aae374e33c3c2fcf10d4c9be
BLAKE2b-256 checksum
How to use checksums
af7e514c3ddf259e9e6f237e4e9bad4a861c59a32213a7c59befd554c3b408f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.8.1

2 release files

0.8.0

2 release files

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

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