Pyrogram Client

You have entered the API Reference section where you can find detailed information about Pyrogram’s API. The main Client class, all available methods and types, filters, handlers, decorators and bound-methods detailed descriptions can be found starting from this page.

This page is about the Client class, which 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!")

Details

class pyrogram.Client

Pyrogram Client, the main means for interacting with Telegram.

Parameters
  • session_name (str) – Pass a string of your choice to give a name to the client session, e.g.: “my_account”. This name will be used to save a file on disk that stores details needed to reconnect without asking again for credentials. Alternatively, if you don’t want a file to be saved on disk, pass the special name ":memory:" to start an in-memory session that will be discarded as soon as you stop the Client. In order to reconnect again using a memory storage without having to login again, you can use export_session_string() before stopping the client to get a session string you can pass here as argument.

  • api_id (int | str, 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 set it if you don’t want to use the config.ini file.

  • app_version (str, optional) – Application version. Defaults to “Pyrogram 1.2.4”. 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”). The 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. Only applicable for new sessions and will be ignored in case previously created sessions are loaded. Defaults to False.

  • 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. This is an alternative way to set it if you don’t want to use the config.ini file.

  • phone_number (str, optional) – Pass your phone number as string (with your Country Code prefix included) to avoid entering it manually. Only applicable for new sessions.

  • phone_code (str, optional) – Pass the phone code as string (for test numbers only) to avoid entering it manually. 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. Only applicable for new sessions.

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

  • workers (int, optional) – Number of maximum concurrent workers for handling incoming updates. Defaults to min(32, os.cpu_count() + 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 the parent directory of the main script.

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

  • parse_mode (str, optional) – The parse mode, can be any of: “combined”, for the default combined mode. “markdown” or “md” to force Markdown-only styles. “html” to force HTML-only styles. None to disable the parser completely.

  • 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).

  • sleep_threshold (int, optional) – Set a sleep threshold for flood wait exceptions happening globally in this client instance, below which any request that raises a flood wait will be automatically invoked again after sleeping for the required amount of time. Flood wait exceptions requiring higher waiting times will be raised. Defaults to 10 seconds.

  • hide_password (bool, optional) – Pass True to hide the password when typing it during the login. Defaults to False, because getpass (the library used) is known to be problematic in some terminal environments.