tbank
Асинхронный и синхронный Python SDK для API Т-Банка (ex-Тинькофф).
tbank — типизированная библиотека для интеграции с платёжными и банковскими сервисами Т-Банка: интернет-эквайринг (приём платежей, СБП, рекуррент, фискализация 54-ФЗ) и открытый банковский API Т-Бизнеса (счета, выписки, рублёвые платежи, инвойсы, СБП-ссылки). Один пакет — оба мира, с общим ядром.
✨ Особенности
- 🚀 Async и sync — один API в двух вариантах на общем ядре (
httpx). - 🛡️ Строгая типизация — pydantic v2,
mypy --strictбез ошибок,py.typed. - 🔌 Полное покрытие — эквайринг (EACQ) и открытый банк (T-API) в одном пакете.
- 🔐 Аутентификация из коробки — SHA-256 Token-подпись (эквайринг), Bearer и mTLS (открытый банк).
- 💸 Корректные деньги — копейки (
int) для эквайринга,Decimalдля открытого банка (без float-погрешности). - 🔁 Надёжность — ретраи с экспоненциальным бэкоффом, уважение
Retry-After, идемпотентность. - 🧪 Проверено — 111 тестов, 99% покрытие.
📦 Установка
pip install tbank
Зависимости: Python 3.9+, pydantic>=2, httpx.
🚀 Быстрый старт
Эквайринг — приём платежа (redirect)
import asyncio
from tbank.acquiring import AcquiringClient
from tbank.acquiring.models import InitRequest
async def main() -> None:
async with AcquiringClient(terminal_key="...", password="...") as client:
payment = await client.init(InitRequest(amount=150000, order_id="A-1"))
print(payment.payment_url) # редиректим покупателя сюда
state = await client.get_state(payment.payment_id)
print(state.status)
asyncio.run(main())
Синхронный вариант — тот же API без async/await:
from tbank.acquiring.sync import AcquiringClient
with AcquiringClient(terminal_key="...", password="...") as client:
payment = client.init(InitRequest(amount=150000, order_id="A-1"))
Открытый банк — счета и выписки
from decimal import Decimal
from tbank.business import BusinessClient
from tbank.business.models import StatementParams
from datetime import datetime, timezone
async def main() -> None:
client = BusinessClient(token="...") # self-service токен из ЛК
accounts = await client.get_accounts() # счета + балансы (Decimal)
async for op in client.iter_statement(
StatementParams(account_number="40802...", from_=datetime(2026, 1, 1, tzinfo=timezone.utc))
):
print(op.operation_id, op.operation_amount) # авто-пагинация по nextCursor
await client.aclose()
🧩 Что покрыто
| Домен | Возможности |
|---|---|
tbank.acquiring (EACQ) |
Приём платежей (init/get_state/confirm/cancel), вебхуки, рекуррент (charge), клиенты и карты (add_customer/get_card_list/remove_card), СБП QR (get_qr/get_qr_members) и СБП-рекуррент (add_account_qr/charge_qr), фискализация 54-ФЗ (Receipt/send_closing_receipt), привязка карт (add_card/get_add_card_state) |
tbank.business (T-API) |
Счета и балансы (get_accounts), выписки с курсорной авто-пагинацией (get_statement/iter_statement/get_bank_statement), рублёвые платежи с налоговым блоком через mTLS (create_ruble_payment/get_payment_status), инвойсы (send_invoice), СБП-ссылки b2b (create_onetime_qr/create_reusable_qr) |
📋 Примеры
Рекуррентный платёж (эквайринг)
# 1) при первом платеже сохраняем карту:
await client.init(InitRequest(amount=150000, order_id="A-1", customer_key="c1", recurrent="Y"))
# → RebillId приходит в вебхуке на статус AUTHORIZED
# 2) последующие списания без покупателя:
await client.charge(payment_id, rebill_id)
СБП QR (эквайринг)
from tbank.acquiring.enums import QrDataType
payment = await client.init(InitRequest(amount=150000, order_id="A-1"))
qr = await client.get_qr(payment.payment_id, data_type=QrDataType.PAYLOAD)
print(qr.data) # ссылка qr.nspk.ru
Рублёвый платёж с mTLS (открытый банк)
from decimal import Decimal
from tbank.business import BusinessClient
from tbank.business.models import CreatePaymentRequest, PaymentFrom, ReceiverRequisites
client = BusinessClient(token="...", cert=("client.pem", "key.pem")) # mTLS-сертификат из ЛК
pid = await client.create_ruble_payment(CreatePaymentRequest(
from_=PaymentFrom(account_number="40802..."),
to=ReceiverRequisites(name="ООО Ромашка", inn="7700000000", account_number="40702...", bik="044525974"),
purpose="Оплата по счёту 1", amount=Decimal("12345.67"),
))
status = await client.get_payment_status(pid)
Фискализация 54-ФЗ (эквайринг)
from tbank.acquiring.models import Receipt, ReceiptItem
from tbank.acquiring.enums import Tax, Taxation, PaymentObject
await client.init(InitRequest(
amount=100000, order_id="A-1",
receipt=Receipt(
taxation=Taxation.USN_INCOME, email="client@example.com",
items=[ReceiptItem(name="Товар", price=100000, quantity=1, amount=100000,
tax=Tax.VAT_22, payment_object=PaymentObject.COMMODITY)],
),
))
⚠️ Обработка ошибок
Все ошибки наследуются от tbank.core.errors.TBankError:
from tbank.core.errors import TBankAPIError, TBankNetworkError, InsufficientFundsError
try:
await client.charge(payment_id, rebill_id)
except InsufficientFundsError:
... # недостаточно средств (типизированное исключение)
except TBankAPIError as e:
print(e.code, e.message) # прочие ошибки API
except TBankNetworkError:
... # сеть/таймаут после ретраев
🔗 Ссылки
- 📚 Документация: https://tbank.readthedocs.io
- 🐙 Репозиторий: https://github.com/masasibata/tbank
- 🏦 API Т-Банка: https://developer.tbank.ru/docs/api
🧪 Разработка
poetry install
poetry run pytest --cov=tbank # тесты + покрытие
poetry run mypy tbank # строгая типизация
poetry run black tbank tests && poetry run isort tbank tests
📄 Лицензия
MIT — см. LICENSE.
Metadata
Release files for tbank 1.14.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| tbank-1.14.0.tar.gz | 88.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tbank-1.14.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 257.4 kB
Release files / tbank-1.14.0.tar.gz
| Download URL | tbank-1.14.0.tar.gz |
|---|---|
| Size | 88.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
984298d891b15c9e1a1d66d47ab00ae8352fcfc657396cb6efca979c65e93f57
|
|
BLAKE2b-256 checksum How to use checksums |
e1664c0af7660fe703c91d3618770f20e5e08a198b3ed0eae813b8e78bbb2281
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.12.11 Linux/6.14.0-37-generic
|
Release files / tbank-1.14.0-py3-none-any.whl
| Download URL | tbank-1.14.0-py3-none-any.whl |
|---|---|
| Size | 169.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5331b20e23cfef8cfb7379688a2bbcd321ad7ed0950753b05a07f34cf2e5d024
|
|
BLAKE2b-256 checksum How to use checksums |
1d14a2f87a915adb21374ea10c80ba25628a4925ab630f8f1312e07eb2d7d8a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.12.11 Linux/6.14.0-37-generic
|
Security for tbank 1.14.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.