StdGram
StdGram is a modern, asynchronous Telegram MTProto client and framework for Python.
Built as an actively maintained, drop-in alternative to Pyrogram, StdGram addresses long-standing developer pain points around rate-limiting, missing MTProto features, and conversation state management. It allows developers to build bots, userbots, and custom Telegram tools with clean, readable async/await syntax.
Highlights
- Drop-in Pyrogram Compatibility: Switch existing codebases by simply updating imports. Handlers, filters, and methods remain fully compatible.
- Automatic FloodWait Handling: No more wrapping calls in repetitive
try...except FloodWaitblocks. StdGram queues throttled calls and retries them automatically. - Native Conversations (
client.ask): Ask interactive questions and wait for user replies in a single line of code, without third-party monkey patches. - Modern Telegram Layer Support: Full MTProto support for recent Telegram additions, including Stories, Gifts, Forum Topics, and Business Accounts.
- Fast Cryptography: High-performance encryption powered by
TgCryptoC-extensions, with automatic pure-Python fallback.
Installation
Install the stable release from PyPI:
pip install stdgram
For optional dependencies (fast crypto, cloud database sessions, async file utilities):
pip install stdgram[all]
Quickstart
1. Basic Bot
from stdgram import Client, filters
app = Client(
"my_bot",
api_id=12345,
api_hash="0123456789abcdef0123456789abcdef",
bot_token="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
)
@app.on_message(filters.command("start"))
async def start_handler(client, message):
await message.reply_text(f"Hello {message.from_user.first_name}! Powered by StdGram.")
@app.on_message(filters.text & filters.private)
async def echo_handler(client, message):
# Automatically rate-limit safe
await message.reply_text(message.text)
if __name__ == "__main__":
app.run()
2. Interactive Conversations (client.ask)
Gather user input sequentially without complicated state machines:
from stdgram import Client, filters
from stdgram.errors import ConversationTimeout
app = Client("conversation_bot", bot_token="YOUR_BOT_TOKEN")
@app.on_message(filters.command("register"))
async def register(client, message):
chat_id = message.chat.id
try:
name_msg = await client.ask(chat_id, "What is your name?", timeout=60)
age_msg = await client.ask(chat_id, "How old are you?", timeout=60)
await message.reply_text(
f"Registration complete!\n"
f"Name: {name_msg.text}\n"
f"Age: {age_msg.text}"
)
except ConversationTimeout:
await message.reply_text("Session timed out. Please run /register again.")
app.run()
3. Migrating from Pyrogram
If you have an existing Pyrogram project, migrate in two steps:
-
Update your dependencies:
pip uninstall pyrogram pip install stdgram
-
Replace the import statement:
# Old from pyrogram import Client, filters # New from stdgram import Client, filters
All existing handler definitions, filters, sessions, and methods work as expected.
Examples
Check the examples/ directory for working starter templates:
01_simple_bot.py— Standard bot commands and echo logic.02_conversation_bot.py— Multi-step registration conversation flow.03_userbot.py— User account automation with.pingand self-commands.
License & Acknowledgements
StdGram is free and open-source software licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0) with GNU GPLv3 terms. See the LICENSE and COPYING.lesser files for complete details.
StdGram is maintained by STD-DEEPANSHU and contributors. It builds upon foundational engineering from the open-source Telegram community, notably:
Metadata
Release files for stdgram 1.0.1
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 |
|---|---|---|---|---|
| stdgram-1.0.1.tar.gz | 1.4 MB | Without provenance | Details for stdgram-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stdgram-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for stdgram-1.0.1-py3-none-any.whl |
Total release size: 7.7 MB
Release files / stdgram-1.0.1.tar.gz
| Download URL | stdgram-1.0.1.tar.gz |
|---|---|
| Size | 1.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7b9f451a98c3da0803a63685787de5c5da55b9104ae41c85d9f02674ade1ec9
|
|
BLAKE2b-256 checksum How to use checksums |
50d12e31d184b5694552ebdf455ce48342286969441cbf8be072246a348c9fd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.5
|
Release files / stdgram-1.0.1-py3-none-any.whl
| Download URL | stdgram-1.0.1-py3-none-any.whl |
|---|---|
| Size | 6.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fea790e986b577976845954892f9fee68a0a5a097bdf3ea8fe38dfb2ed7dca23
|
|
BLAKE2b-256 checksum How to use checksums |
7ec3116ba49fdd77d1491ebe086f8ba7659d49d0ce9e7e0c2328899c71963147
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.5
|
Security for stdgram 1.0.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.