Quick Start¶
Welcome to Hydrogram! This guide will help you set up and run your first Telegram bot or client application in minutes.
What is Hydrogram?¶
Hydrogram is a modern, elegant Python framework that allows you to interact with the Telegram API. With Hydrogram, you can:
Create Telegram bots with advanced features
Build user clients (userbot)
Access and manage your Telegram account programmatically
Automate Telegram-related tasks
Handle updates and respond to messages
Let’s get started with a simple example:
Getting Started¶
Install Hydrogram with
pip3 install -U hydrogram.Obtain your API credentials from Telegram:
Go to https://my.telegram.org/apps and log in with your phone number
Create a new application to get your
api_idandapi_hash
Note
Make sure you understand and abide by Telegram’s terms of service and API usage rules explained at https://core.telegram.org/api/obtaining_api_id.
Create your first script by opening your favorite text editor and pasting the following code:
import asyncio from hydrogram import Client # Replace these with your own values api_id = 12345 api_hash = "0123456789abcdef0123456789abcdef" async def main(): # Create a new client instance async with Client("my_account", api_id, api_hash) as app: # Send a message to yourself await app.send_message("me", "Greetings from **Hydrogram**!") # Get information about yourself me = await app.get_me() print(f"Successfully logged in as {me.first_name} ({me.id})") asyncio.run(main())
Replace the placeholder
api_idandapi_hashvalues with your own.Save the file as
hello.py.Run the script with
python3 hello.pyLog in to your account by following the prompts. You’ll only need to do this once.
Watch Hydrogram in action as it sends a message to your Saved Messages.
What’s Next?¶
This was just a brief introduction to get you started quickly. Hydrogram offers many more powerful features for building Telegram applications.
Learn about different ways to Invoking Methods from the API
Explore how to Handling Updates from Telegram
Check out complete Examples to see what’s possible
Join our community on Telegram for support and updates.