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

Repository

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

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"),
)


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


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 vs. invoice_paid/invoice_expired/invoice_cancelled) — running both is safe, just make handlers idempotent since the same payment could be reported by each.

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

Good to know

  • create_invoice(amount=...) takes human units5, 5.5, Decimal("5.5") — and converts them to the wire format for you. Pass a str if you already have the raw smallest-unit value and want it sent through unchanged. Don't mix the two up: amount=5 is always 5 whole coins, never smallest units.
  • The wire format itself is smallest-unit strings, never floatsInvoice.amount on a response stays a str for that reason; use Invoice.amount_int for an int.
  • 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 header isn't named in the docs — only the algorithm is (HMAC-SHA256 hex, sha256= prefix, raw body). aiopaysell defaults to X-Paysell-Signature; confirm the real name in your shop's settings and pass Paysell(..., signature_header="...") if it differs.
  • There's a single network (https://pay.saleprofit.dev) — 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
502 BadGatewayError (safe to retry with the same idempotency_key)

All inherit aiopaysell.exceptions.APIErrorPaysellError.

License

MIT

aiopl

Release files for aiopaysell 0.5.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.5.0
File Size Uploaded
aiopaysell-0.5.0.tar.gz 145.3 kB Details

Built distribution (wheel)

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

Total release size: 183.2 kB

Release files / aiopaysell-0.5.0.tar.gz

Download URL aiopaysell-0.5.0.tar.gz
Size 145.3 kB
Tags Source
SHA-256 checksum
How to use checksums
01d1cd626708bd64b6e73633319496e58a59ce6cd361e7d5052c7a4d97fb553f
BLAKE2b-256 checksum
How to use checksums
21fe175a50c19d1993a8b0ef4b2f96fef86d4abce9cff14e4c3287ee27690c9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","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.5.0-py3-none-any.whl

Download URL aiopaysell-0.5.0-py3-none-any.whl
Size 37.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2cdfcfd623387a27ec3b5c5a8c8adeb0a5b392631f541e550bdc6aec1406c133
BLAKE2b-256 checksum
How to use checksums
802ebae657251c62eb55703bb40e17a9f0587d84550d614a33b4854aa9835271
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","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

0.7.0

2 release files

0.6.0

2 release files

This release

0.5.0 This release

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