Binary CallbackData serialization for aiogram 3.x
Project description
aiogram-bincallback
Bitwise serialization of CallbackData for aiogram 3.x instead of the text format prefix:field1:field2. Each field occupies a fixed number of bits - more data fits into the Telegram limit (64 bytes), and the payload size is known at class definition time.
Ru README
Installation
pip install aiogram-bincallback
Dependencies: 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 and version are class inheritance arguments, not model fields. Both are required.
cb = OrderCb(order_id=42, status=Status.PENDING)
packed = cb.pack()
restored = OrderCb.unpack(packed)
OrderCb is simultaneously a pydantic.BaseModel and an aiogram.CallbackData, used in filters like a regular 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.2.tar.gz.
File metadata
- Download URL: aiogram_bincallback-0.3.2.tar.gz
- Upload date:
- Size: 31.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e7ec80744ac05e959a58556124ec535e2ab68ee34d842921b81c13d6be7fb99
|
|
| MD5 |
bad938d212bb9eab5e28cc95c1f328f4
|
|
| BLAKE2b-256 |
580fc6b0e7e2de4dc35ac84371ac19545c084f4d6198957615214cc77a0fc2b8
|
Provenance
The following attestation bundles were made for aiogram_bincallback-0.3.2.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.2.tar.gz -
Subject digest:
5e7ec80744ac05e959a58556124ec535e2ab68ee34d842921b81c13d6be7fb99 - Sigstore transparency entry: 2194686089
- Sigstore integration time:
-
Permalink:
boykopovar/aiogram-bincallback@16bf168bef0de443e7ac7a7dbf7647e55d3a1b8b -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/boykopovar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@16bf168bef0de443e7ac7a7dbf7647e55d3a1b8b -
Trigger Event:
push
-
Statement type:
File details
Details for the file aiogram_bincallback-0.3.2-py3-none-any.whl.
File metadata
- Download URL: aiogram_bincallback-0.3.2-py3-none-any.whl
- Upload date:
- Size: 20.8 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 |
8bea71a47d3b81b9f1a8d4aa8337eb07b271cff1f621bf3daddac8d15bf98295
|
|
| MD5 |
61759d8e573078d06cfe17886c2ca5eb
|
|
| BLAKE2b-256 |
596008938ec553e3937a738455268591e9ea91e5937c191a5032143a1e38dde4
|
Provenance
The following attestation bundles were made for aiogram_bincallback-0.3.2-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.2-py3-none-any.whl -
Subject digest:
8bea71a47d3b81b9f1a8d4aa8337eb07b271cff1f621bf3daddac8d15bf98295 - Sigstore transparency entry: 2194686097
- Sigstore integration time:
-
Permalink:
boykopovar/aiogram-bincallback@16bf168bef0de443e7ac7a7dbf7647e55d3a1b8b -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/boykopovar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@16bf168bef0de443e7ac7a7dbf7647e55d3a1b8b -
Trigger Event:
push
-
Statement type: