Pyrogram - Telegram MTProto API Framework for Python.
Pyrogram is a modern, elegant and asynchronous MTProto API framework. It enables you to easily interact with the main Telegram API through a user account (custom client) or a bot identity (bot API alternative) using Python.
QuickStart
- Install Pyrogram with pip3 install -U pyrogram.
- Get your own Telegram API key from https://my.telegram.org/apps.
- Open the text editor of your choice and paste the following:
import asyncio
from pyrogram import Clientapi_id = 12345
api_hash = "0123456789abcdef0123456789abcdef"async def main():
async with Client("my_account", api_id, api_hash) as app:
await app.send_message("me", "Greetings from **Pyrogram**!")asyncio.run(main())
- Replace api_id and api_hash values with your own.
- Save the file as hello.py.
- Run the script with python3 hello.py
- Follow the instructions on your terminal to login.
- Watch Pyrogram send a message to yourself.