Shirdal
A transport-agnostic, context-first Python framework for Telegram — featuring a built-in Bot API 10.5 engine and a native MTProto 2.0 core.
English | فارسی
Most Telegram frameworks force a choice: either use a Bot API library that cannot touch MTProto, or an MTProto client with heavy, tightly-coupled internals. Shirdal decouples your application logic (Dispatcher, Context, filters, FSM, AntiFlood, hot-reload plugins, and storage) behind a single TransportAdapter protocol—and ships both a zero-HTTP-dependency Bot API 10.5 engine and a clean 5-layer native MTProto 2.0 core.
Architecture
Your Handlers & Plugins (Context, Filters, FSM, Scheduler, MultiBot)
│
TransportAdapter
┌──────────────────────┼──────────────────────┐
▼ ▼ ▼
BotAPIAdapter NativeMTProtoAdapter Telethon / Hydrogram / Mock
(HTTP Keep-Alive + (TL Codec, AES-256-IGE, (Legacy MTProto wrappers
WebhookServer) TCP Abridged, PeerCache) & offline test adapter)
Why Shirdal?
| Capability | Shirdal | Pyrogram (Archived) | Telethon | aiogram |
|---|---|---|---|---|
| Transport independence | Bot API + Native MTProto + Wrappers + Mock | MTProto only | MTProto only | Bot API only |
| Bot API 9.4–10.5 (Colored Buttons, Custom Emoji, Rich Messages, Ephemeral, Draft Streaming) | Native & typed | Partial / raw | N/A | Requires external HTTP stack |
| Built-in Webhook Server | asyncio HTTP/1.1 (WebhookServer, zero deps) |
N/A | N/A | Requires aiohttp / FastAPI |
| Native MTProto 2.0 Core | 5-layer modular (shirdal.mtproto) + tlgen |
Monolithic | Monolithic | N/A |
| Production Primitives | AntiFlood, SQLite/Redis/MySQL, SecretBox, Hot-Reload, MultiBot |
Manual | Manual | FSM + Middleware |
Key Features
- Built-in Bot API Engine (
BotAPIAdapter): Keep-Alive HTTP/HTTPS client with optionalmsgspecJSON acceleration and a built-inasyncioWebhookServer(withX-Telegram-Bot-Api-Secret-Tokenverification andGET /health). - Bot API 10.5 Ready:
- Colored & Icon Buttons:
ButtonStyle(primary,success,danger),icon/icon_custom_emoji_id,disabled,copy_text,web_app_url,reply_button(), andreply_keyboard(..., force_reply=True). - Premium Emoji & Localized Time:
custom_emoji(),custom_emoji_entity(),date_time(), anddate_time_entity(). - Ephemeral Group Replies & AI Streaming:
ctx.reply_ephemeral(),async with ctx.stream()(sendMessageDraft), andasync with ctx.stream_rich()(sendRichMessageDraft). - Rich Messages:
ctx.reply_rich()and typed block builders (rich_heading,rich_table,rich_details,rich_blockquote,rich_code,rich_math,rich_buttons,rich_thinking). - Group Tags, Topics & Settings:
ctx.set_member_tag(),create_forum_topic(), andset_my_settings().
- Colored & Icon Buttons:
- Native MTProto 2.0 Core (
shirdal.mtproto&NativeMTProtoAdapter):- Zero-copy
TLReader/TLWriter+.tlschema codegen (generate_python_module) producing@dataclass(slots=True)models. AES-256-IGE, MTProto 2.0 KDF,AuthKey, Pollard's rho factorization, and 3-step DHHandshakeSession.TCPAbridgedTransport,MTProtoSessionState(SQLite persistence),MTProtoWire(msg_container,msgs_ack,bad_server_salt,gzip_packed,rpc_result).PeerCache(access_hashpersistence),UpdateStateTracker(pts/qts/seqgap detection), and parallel chunkedFileTransferManager.
- Zero-copy
- Resilience & Tooling:
AntiFloodAdapterwithFloodWaitErrorrecovery, live hot-reloadplugins/,StatesGroupFSM,EncryptedStorage(Encrypt-then-MAC),@bot.every()scheduler,MultiBot, andshirdalCLI (new,doctor,run).
Installation
pip install shirdal # Includes Bot API 10.5 + Native MTProto 2.0 (cryptography)
# Optional extras
pip install "shirdal[fast]" # uvloop + msgspec JSON speedups
pip install "shirdal[telethon]" # Telethon adapter
Quickstart: Modern Bot API
import os
from shirdal import (
BotAPIAdapter,
ButtonStyle,
Context,
Shirdal,
button,
callback,
command,
custom_emoji,
incoming,
inline_keyboard,
)
bot = Shirdal(BotAPIAdapter(os.environ["BOT_TOKEN"]))
@bot.on(incoming & command("start", prefix="/"))
async def start(ctx: Context) -> None:
badge = custom_emoji("5368324170671202286", "✨")
kb = inline_keyboard([
[
button("Approve", "act:ok", style=ButtonStyle.SUCCESS, icon="5368324170671202286"),
button("Reject", "act:no", style=ButtonStyle.DANGER),
]
])
await ctx.reply(f"{badge} <b>Select an action:</b>", reply_markup=kb)
@bot.on_callback(callback(prefix="act:"))
async def on_action(ctx: Context) -> None:
await ctx.answer("Recorded")
await ctx.reply_ephemeral(f"Triggered: <code>{ctx.callback_data}</code>")
if __name__ == "__main__":
bot.run()
Quickstart: Native MTProto 2.0
import os
from shirdal import Context, DeviceProfile, NativeMTProtoAdapter, Shirdal, command, outgoing
adapter = NativeMTProtoAdapter(
int(os.environ["API_ID"]),
os.environ["API_HASH"],
session_path="account.sqlite",
device=DeviceProfile.desktop(),
)
bot = Shirdal(adapter, plugins_dir="plugins", hot_reload=True)
@bot.on(command("ping") & outgoing)
async def ping(ctx: Context) -> None:
await ctx.edit("Pong from Native MTProto 2.0", auto_delete=10)
if __name__ == "__main__":
bot.run()
Documentation
- Getting Started & CLI
- Bot API 10.5 Features
- Rich Messages Guide
- Native MTProto 2.0 Core
- Webhook Server & Deployment
- مستندات کامل فارسی
Running Tests
PYTHONPATH=src python3 -m unittest discover -s tests -v
Security, Contributing & License
- Security vulnerabilities: see SECURITY.md
- Contributing guidelines: see CONTRIBUTING.md
- License: LGPL-3.0-or-later
Metadata
Release files for shirdal 1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| shirdal-1.0.7.tar.gz | 183.3 kB | With provenance | Details for shirdal-1.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| shirdal-1.0.7-py3-none-any.whl | Python 3 | none | any | Details for shirdal-1.0.7-py3-none-any.whl |
Total release size: 350.1 kB
Release files / shirdal-1.0.7.tar.gz
| Download URL | shirdal-1.0.7.tar.gz |
|---|---|
| Size | 183.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1aba1affdb9390dae03c0c2d7350be25812324f267ee157dfa13f537a21efd41
|
|
BLAKE2b-256 checksum How to use checksums |
4e542b568a4b4af565bee640a76c502ccd32a3c09b18f644113092a5619d26bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logRelease files / shirdal-1.0.7-py3-none-any.whl
| Download URL | shirdal-1.0.7-py3-none-any.whl |
|---|---|
| Size | 166.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
85709b064fda999c6caf6ec93a94b8887619c1091359b3d77abda3bdaae314c0
|
|
BLAKE2b-256 checksum How to use checksums |
3bd687fd2a1331e4125cbe7ab7efd447379b7a2c8fef0cda7c1439d87fcb0739
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logSecurity for shirdal 1.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for shirdal-1.0.7.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.