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

  1. Install Hydrogram with pip3 install -U hydrogram.

  2. Obtain your API credentials from Telegram:

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.

  1. 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())
    
  2. Replace the placeholder api_id and api_hash values with your own.

  3. Save the file as hello.py.

  4. Run the script with python3 hello.py

  5. Log in to your account by following the prompts. You’ll only need to do this once.

  6. 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.

Join our community on Telegram for support and updates.