Skip to main content

Scolocrizm

Scolocrizm is a Python framework for the Telegram Bot API. It provides asynchronous and synchronous clients, lossless models, file uploads, long polling, webhooks, routing, and a small FSM layer.

The bundled schema is based on Telegram Bot API 10.2. It includes 185 API methods and 387 documented object names. New optional fields are preserved instead of discarded.

Installation

pip install Scolocrizm

For local development:

pip install -e '.[dev]'

Quick start

import asyncio
from scolocrizm import Bot

async def main() -> None:
    bot = Bot('123456:BOT_TOKEN')
    me = await bot.get_me()
    print(me.username)

    await bot.send_message(chat_id=123456789, text='Hello')

asyncio.run(main())

Every Bot API method is available in snake_case:

await bot.send_rich_message(chat_id=123456789, rich_message={'markdown': '# Hello'})
await bot.edit_ephemeral_message_text(chat_id=123456789, ephemeral_message_id=1, text='Updated')
await bot.post_story(chat_id=123456789, content={'type': 'photo', 'photo': 'FILE_ID'})

Routing and polling

import asyncio
from scolocrizm import Bot, Command, Dispatcher, F

router = Dispatcher()

@router.message(Command('start') & F.text.startswith('/start'))
async def start(message, bot):
    await bot.send_message(chat_id=message.chat.id, text='Ready.')

async def main() -> None:
    bot = Bot('123456:BOT_TOKEN')
    await router.run_polling(bot, allowed_updates=['message'])

asyncio.run(main())

Use router.on() for any Update field:

@router.on('subscription')
async def subscription_changed(subscription):
    print(subscription.raw)

Files

Use InputFile for bytes, paths, or binary streams. File references returned by Telegram remain ordinary strings.

from scolocrizm import Bot, InputFile
from scolocrizm.types import InputMediaPhoto

bot = Bot('123456:BOT_TOKEN')

await bot.send_photo(
    chat_id=123456789,
    photo=InputFile('cover.png'),
    caption='Cover',
)

await bot.send_media_group(
    chat_id=123456789,
    media=[InputMediaPhoto(media=InputFile('one.jpg'))],
)

Nested InputFile instances are converted to multipart attachments automatically.

Webhooks

asgi_app() returns a dependency-free ASGI application. Set the same secret with set_webhook(secret_token=...) and in the application.

from scolocrizm import asgi_app

async def handle(update):
    print(update.raw)

app = asgi_app(handle, secret_token='long-random-secret', path='/telegram')

The webhook handler checks X-Telegram-Bot-Api-Secret-Token with a constant-time comparison.

Callback data

from scolocrizm import CallbackCodec

codec = CallbackCodec('separate-random-secret')
data = codec.pack('order', id=42, action='pay')
assert codec.unpack(data, namespace='order').data['id'] == 42

The codec signs payloads and enforces Telegram's 64-byte callback-data limit.

State

from scolocrizm import FSMMiddleware

router.middleware(FSMMiddleware())

@router.message(Command('name'))
async def ask_name(message, state, bot):
    await state.set_state('awaiting_name')
    await bot.send_message(chat_id=message.chat.id, text='What is your name?')

MemoryStorage is suitable for a single process. Multi-worker deployments should provide a shared implementation of the StateStorage protocol.

Sync client

from scolocrizm import SyncBot

bot = SyncBot('123456:BOT_TOKEN')
bot.send_message(chat_id=123456789, text='Sent from a script')

SyncBot cannot run inside an active event loop. Use Bot in asynchronous applications.

Compatibility

The client preserves unknown response fields and accepts direct calls to methods that may be added after a package release:

result = await bot.call('futureMethod', chat_id=123456789)
print(result.raw)

Scolocrizm retries rate-limited requests after Telegram's retry_after delay. Calls that could create a duplicate message are not retried after an ambiguous transport error unless retry_unsafe=True is explicitly requested.

Development

PYTHONPATH=src pytest -q
ruff check src tests tools
python tools/audit_bot_api.py
python tools/generate_manifest.py
python -m build

The API audit and release verification are documented in reports/BOT_API_COVERAGE_REPORT.md.

License

MIT. Scolocrizm is an independent project and is not affiliated with Telegram.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scolocrizm-0.1.0.tar.gz (94.0 kB view details)

Uploaded Source

Built Distribution

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

scolocrizm-0.1.0-py3-none-any.whl (96.3 kB view details)

Uploaded Python 3

File details

Details for the file scolocrizm-0.1.0.tar.gz.

File metadata

  • Download URL: scolocrizm-0.1.0.tar.gz
  • Upload date:
  • Size: 94.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for scolocrizm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 63b990a735617625035479212c803c27fd1f3c5c1c4d514202329dfc2cd10894
MD5 8005b6a4251c7c0f297a345bd6a4c660
BLAKE2b-256 0e487d33f59bee69f5993e252e0f223c0c44d4d8f264787a86448468a2e28f7f

See more details on using hashes here.

File details

Details for the file scolocrizm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: scolocrizm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 96.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for scolocrizm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cccd97a1cc29cb604bf3c04b339319741cc5ad8b3e6127c1c9f05d1c19acfefe
MD5 ff4600654d8a1a5d195869e7e92f27db
BLAKE2b-256 0bda85c6c760d269447ff4f819b5cc5ce5d6c0e74410bb3e0dc9ecf9d248ebdf

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

2 files

Supported by

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