Skip to main content

Binary CallbackData serialization for aiogram 3.x

Project description

aiogram-bincallback

PyPI version Python versions License aiogram

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):
    ...

Documentation

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

aiogram_bincallback-0.3.2.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiogram_bincallback-0.3.2-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

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

Hashes for aiogram_bincallback-0.3.2.tar.gz
Algorithm Hash digest
SHA256 5e7ec80744ac05e959a58556124ec535e2ab68ee34d842921b81c13d6be7fb99
MD5 bad938d212bb9eab5e28cc95c1f328f4
BLAKE2b-256 580fc6b0e7e2de4dc35ac84371ac19545c084f4d6198957615214cc77a0fc2b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiogram_bincallback-0.3.2.tar.gz:

Publisher: release.yml on boykopovar/aiogram-bincallback

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiogram_bincallback-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for aiogram_bincallback-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8bea71a47d3b81b9f1a8d4aa8337eb07b271cff1f621bf3daddac8d15bf98295
MD5 61759d8e573078d06cfe17886c2ca5eb
BLAKE2b-256 596008938ec553e3937a738455268591e9ea91e5937c191a5032143a1e38dde4

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiogram_bincallback-0.3.2-py3-none-any.whl:

Publisher: release.yml on boykopovar/aiogram-bincallback

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page