{"id":14834,"library":"pyrogram","title":"Pyrogram","description":"Pyrogram is an elegant, modern, and asynchronous Telegram MTProto API framework in Python, primarily used for building custom user clients and bots. While it offers extensive features for interacting with the Telegram API and is boosted by the high-performance TgCrypto library, the project is officially no longer maintained or supported as of December 2024.","status":"abandoned","version":"2.0.106","language":"en","source_language":"en","source_url":"https://github.com/pyrogram/pyrogram","tags":["telegram","bot","async","mtproto","client library","chat"],"install":[{"cmd":"pip install pyrogram","lang":"bash","label":"Basic Installation"},{"cmd":"pip install pyrogram[tgcrypto]","lang":"bash","label":"With C-based cryptography for performance"}],"dependencies":[{"reason":"Required for cryptographic operations or proxy support.","package":"pyaes | pysocks","optional":false},{"reason":"Optional C-based cryptography library for significantly better performance.","package":"tgcrypto","optional":true}],"imports":[{"symbol":"Client","correct":"from pyrogram import Client"},{"symbol":"filters","correct":"from pyrogram import filters"},{"note":"The `errors` package was moved and `Error` renamed to `RPCError` in v0.12.0.","wrong":"from pyrogram import Error","symbol":"RPCError","correct":"from pyrogram import errors; errors.RPCError"},{"note":"The `idle()` method was reworked to be a static function, not a client method, and no longer stops the client automatically.","wrong":"Client.idle()","symbol":"idle","correct":"from pyrogram import idle"}],"quickstart":{"code":"import os\nfrom pyrogram import Client, filters\nimport asyncio\n\nAPI_ID = os.environ.get('TG_API_ID', '')\nAPI_HASH = os.environ.get('TG_API_HASH', '')\nBOT_TOKEN = os.environ.get('TG_BOT_TOKEN', '') # Optional, for bot accounts\n\nasync def main():\n    if not API_ID or not API_HASH:\n        print(\"Please set TG_API_ID and TG_API_HASH environment variables.\")\n        return\n\n    # For a user account, use Client(\"my_account\", api_id, api_hash)\n    # For a bot account, use Client(\"my_bot\", api_id, api_hash, bot_token)\n    async with Client(\n        \"my_session\", # Session name, creates my_session.session file\n        api_id=int(API_ID),\n        api_hash=API_HASH,\n        bot_token=BOT_TOKEN if BOT_TOKEN else None # Pass bot_token only for bots\n    ) as app:\n        me = await app.get_me()\n        print(f\"Client started as {me.first_name} (@{me.username})\")\n\n        @app.on_message(filters.command(\"start\") & filters.private)\n        async def start_command(client, message):\n            await message.reply_text(\"Hello! I'm a Pyrogram client/bot.\")\n\n        # Keep the client running indefinitely. In a real app, you might use app.run()\n        # or integrate with other async loops.\n        print(\"Listening for messages...\")\n        await asyncio.Event().wait() # Keeps the client running indefinitely\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n","lang":"python","description":"This quickstart initializes a Pyrogram client (which can act as a user account or bot). It requires `api_id` and `api_hash` from my.telegram.org/apps set as environment variables `TG_API_ID` and `TG_API_HASH`. For bots, `TG_BOT_TOKEN` should also be set. The client will create a `.session` file for persistent login. It includes a simple `start` command handler."},"warnings":[{"fix":"Consider migrating to actively maintained alternatives or be prepared to fork and maintain the library yourself. Proceed with caution for new projects.","message":"Project is no longer maintained or supported. Users should be aware that new features, bug fixes, or security updates are unlikely.","severity":"breaking","affected_versions":"All versions from 2.0.106 onwards (as of December 2024)"},{"fix":"Update authorization logic to use the direct parameters or environmental variables for `api_id`, `api_hash`, `phone_number`, `password`, etc., and follow the interactive login flow if necessary.","message":"Authorization flow changed: Callback functions for `Client` arguments (e.g., `phone_number`, `password`) were removed in favor of a simpler, sequential authorization.","severity":"breaking","affected_versions":"Versions after Pyrogram v0.16.0"},{"fix":"Explicitly call `app.stop()` after `idle()` finishes if you want to terminate the client gracefully.","message":"The `idle()` method no longer automatically stops the client. It only idles.","severity":"breaking","affected_versions":"Versions after Pyrogram v0.16.0"},{"fix":"Understand the `name` and `in_memory` parameters of `Client` to control session storage. Use `export_session_string()` for portable in-memory sessions across restarts.","message":"Session persistence is managed via session files (SQLite by default). For ephemeral environments or explicit in-memory use, `in_memory=True` must be passed to `Client`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `await` with Pyrogram methods and other asynchronous libraries (e.g., `asyncio.sleep()`, `aiohttp`). Ensure your code is fully asynchronous.","message":"All Pyrogram operations are asynchronous. Blocking operations (e.g., `time.sleep()`, synchronous network requests) in handlers will freeze the event loop and prevent other updates from being processed.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[],"ecosystem":"pypi"}