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())

Observability

Scolocrizm depends on ScoloLogger for structured request and update events. It does not configure logging automatically. Configure it once in the application when JSON logs or request timing are needed:

from scolologger import configure

configure(level='DEBUG', json_output=True)

The scolocrizm logger records method name, attempt, elapsed time, retry delay, response status, and polling update ID. Bot tokens and request payloads are never written to these events.

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.2.tar.gz (95.7 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.2-py3-none-any.whl (97.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scolocrizm-0.1.2.tar.gz
  • Upload date:
  • Size: 95.7 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.2.tar.gz
Algorithm Hash digest
SHA256 87d7df13f7d64fe389ae466545e7dcfff806c37860cdd47bdf26c6cfc1023a5d
MD5 afa248ee30a0f6d22c83820040e543d3
BLAKE2b-256 08e0cefff5a61e1b2337fbadcb889dc5bb37240f4ecb2ad2a7293900c7cb7a3c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scolocrizm-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 97.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 32396b5f510dc5bae066381b7da66471caf4fbeaf9d43b7be9aba1cca5ed1772
MD5 62682e57622f4d035a8f583bcd04d17a
BLAKE2b-256 c6cfeef733d4d6207c51afa880d005734a63d3193e945e83a5c4cb35306d9cc6

See more details on using hashes here.

Supported by

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