Pyrogram Client

This is the Client class. It exposes high-level methods for an easy access to the API.

from pyrogram import Client

app = Client("my_account")

with app:
    app.send_message("me", "Hi!")
class pyrogram.Client

Pyrogram Client, the main means for interacting with Telegram.

Parameters
  • session_name (str) – Name to uniquely identify a session of either a User or a Bot, e.g.: “my_account”. This name will be used to save a file to disk that stores details needed for reconnecting without asking again for credentials.

  • api_id (int, optional) – The api_id part of your Telegram API Key, as integer. E.g.: 12345 This is an alternative way to pass it if you don’t want to use the config.ini file.

  • api_hash (str, optional) – The api_hash part of your Telegram API Key, as string. E.g.: “0123456789abcdef0123456789abcdef”. This is an alternative way to pass it if you don’t want to use the config.ini file.

  • app_version (str, optional) – Application version. Defaults to “Pyrogram X.Y.Z” This is an alternative way to set it if you don’t want to use the config.ini file.

  • device_model (str, optional) – Device model. Defaults to platform.python_implementation() + ” ” + platform.python_version() This is an alternative way to set it if you don’t want to use the config.ini file.

  • system_version (str, optional) – Operating System version. Defaults to platform.system() + ” ” + platform.release() This is an alternative way to set it if you don’t want to use the config.ini file.

  • lang_code (str, optional) – Code of the language used on the client, in ISO 639-1 standard. Defaults to “en”. This is an alternative way to set it if you don’t want to use the config.ini file.

  • ipv6 (bool, optional) – Pass True to connect to Telegram using IPv6. Defaults to False (IPv4).

  • proxy (dict, optional) – Your SOCKS5 Proxy settings as dict, e.g.: dict(hostname=”11.22.33.44”, port=1080, username=”user”, password=”pass”). username and password can be omitted if your proxy doesn’t require authorization. This is an alternative way to setup a proxy if you don’t want to use the config.ini file.

  • test_mode (bool, optional) – Enable or disable login to the test servers. Defaults to False. Only applicable for new sessions and will be ignored in case previously created sessions are loaded.

  • bot_token (str, optional) – Pass your Bot API token to create a bot session, e.g.: “123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11” Only applicable for new sessions.

  • phone_number (str | callable, optional) – Pass your phone number as string (with your Country Code prefix included) to avoid entering it manually. Or pass a callback function which accepts no arguments and must return the correct phone number as string (e.g., “391234567890”). Only applicable for new sessions.

  • phone_code (str | callable, optional) – Pass the phone code as string (for test numbers only) to avoid entering it manually. Or pass a callback function which accepts a single positional argument (phone_number) and must return the correct phone code as string (e.g., “12345”). Only applicable for new sessions.

  • password (str, optional) – Pass your Two-Step Verification password as string (if you have one) to avoid entering it manually. Or pass a callback function which accepts a single positional argument (password_hint) and must return the correct password as string (e.g., “password”). Only applicable for new sessions.

  • recovery_code (callable, optional) – Pass a callback function which accepts a single positional argument (email_pattern) and must return the correct password recovery code as string (e.g., “987654”). Only applicable for new sessions.

  • force_sms (str, optional) – Pass True to force Telegram sending the authorization code via SMS. Only applicable for new sessions.

  • first_name (str, optional) – Pass a First Name as string to avoid entering it manually. Or pass a callback function which accepts no arguments and must return the correct name as string (e.g., “Dan”). It will be used to automatically create a new Telegram account in case the phone number you passed is not registered yet. Only applicable for new sessions.

  • last_name (str, optional) – Same purpose as first_name; pass a Last Name to avoid entering it manually. It can be an empty string: “”. Only applicable for new sessions.

  • workers (int, optional) – Thread pool size for handling incoming updates. Defaults to 4.

  • workdir (str, optional) – Define a custom working directory. The working directory is the location in your filesystem where Pyrogram will store your session files. Defaults to “.” (current directory).

  • config_file (str, optional) – Path of the configuration file. Defaults to ./config.ini

  • plugins (dict, optional) – Your Smart Plugins settings as dict, e.g.: dict(root=”plugins”). This is an alternative way to setup plugins if you don’t want to use the config.ini file.

  • no_updates (bool, optional) – Pass True to completely disable incoming updates for the current session. When updates are disabled your client can’t receive any new message. Useful for batch programs that don’t need to deal with updates. Defaults to False (updates enabled and always received).

  • takeout (bool, optional) – Pass True to let the client use a takeout session instead of a normal one, implies no_updates=True. Useful for exporting your Telegram data. Methods invoked inside a takeout session (such as get_history, download_media, …) are less prone to throw FloodWait exceptions. Only available for users, bots will ignore this parameter. Defaults to False (normal session).