Binary CallbackData serialization for aiogram 3.x
Project description
aiogram-bincallback
Побитовая сериализация CallbackData для aiogram 3.x вместо текстового формата prefix:field1:field2. Каждое поле занимает фиксированное число бит - в лимит Telegram (64 байта) помещается больше данных, размер payload известен на этапе определения класса.
Установка
pip install aiogram-bincallback
Зависимости: aiogram>=3.0,<4.0, pydantic>=2.0,<3.0, Python 3.8+.
from enum import Enum, IntEnum
from aiogram_bincallback import BinaryCallbackData, bfield
class CbPrefix(IntEnum):
ORDER = 1
HOME = 2
class Status(str, Enum):
PENDING = "pending"
SHIPPED = "shipped"
class OrderCb(BinaryCallbackData, prefix=CbPrefix.ORDER.value, version=1):
order_id: int = bfield(bits=16, signed=False)
status: Status = bfield(bits=4)
prefix и version - аргументы наследования класса, не поля модели. Оба обязательны.
cb = OrderCb(order_id=42, status=Status.PENDING)
packed = cb.pack()
restored = OrderCb.unpack(packed)
OrderCb - одновременно pydantic.BaseModel и aiogram.CallbackData, используется в фильтрах как обычный CallbackData:
from aiogram import Router
router = Router()
@router.callback_query(OrderCb.filter())
async def handle_order(callback, callback_data: OrderCb):
...
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiogram_bincallback-0.3.1.tar.gz.
File metadata
- Download URL: aiogram_bincallback-0.3.1.tar.gz
- Upload date:
- Size: 31.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46790a5d9ba2511211eb7f5aefb522fa37b3100158f89157171d920435a08bec
|
|
| MD5 |
38688386368b37da1b35c863da1efcea
|
|
| BLAKE2b-256 |
d5137d9ac2f60f39408530390886085e1f2507f1590760120b4d6a5053eca63c
|
Provenance
The following attestation bundles were made for aiogram_bincallback-0.3.1.tar.gz:
Publisher:
release.yml on boykopovar/aiogram-bincallback
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiogram_bincallback-0.3.1.tar.gz -
Subject digest:
46790a5d9ba2511211eb7f5aefb522fa37b3100158f89157171d920435a08bec - Sigstore transparency entry: 2190707996
- Sigstore integration time:
-
Permalink:
boykopovar/aiogram-bincallback@61e335b2901e92c2838fb3ba37a2d8a04791519e -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/boykopovar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@61e335b2901e92c2838fb3ba37a2d8a04791519e -
Trigger Event:
push
-
Statement type:
File details
Details for the file aiogram_bincallback-0.3.1-py3-none-any.whl.
File metadata
- Download URL: aiogram_bincallback-0.3.1-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3657525b6fee96dd6acf45b979868c3a7104ce2026428c5bfd6212a20cfde9e
|
|
| MD5 |
59012de70858c7b80e0316a5d9e94bc5
|
|
| BLAKE2b-256 |
254d9d0c117093566fbfb8de94e9a2eb0cd6dc574002c675549eb043cba732db
|
Provenance
The following attestation bundles were made for aiogram_bincallback-0.3.1-py3-none-any.whl:
Publisher:
release.yml on boykopovar/aiogram-bincallback
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiogram_bincallback-0.3.1-py3-none-any.whl -
Subject digest:
a3657525b6fee96dd6acf45b979868c3a7104ce2026428c5bfd6212a20cfde9e - Sigstore transparency entry: 2190708070
- Sigstore integration time:
-
Permalink:
boykopovar/aiogram-bincallback@61e335b2901e92c2838fb3ba37a2d8a04791519e -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/boykopovar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@61e335b2901e92c2838fb3ba37a2d8a04791519e -
Trigger Event:
push
-
Statement type: