2019-01-25 08:21:21 +00:00
|
|
|
Configuration File
|
|
|
|
==================
|
|
|
|
|
2019-06-07 13:50:15 +00:00
|
|
|
As already mentioned in previous pages, Pyrogram can be configured by the use of an INI file.
|
|
|
|
This page explains how this file is structured, how to use it and why.
|
2019-01-25 08:21:21 +00:00
|
|
|
|
2020-04-01 18:08:46 +00:00
|
|
|
.. contents:: Contents
|
|
|
|
:backlinks: none
|
2020-08-22 06:05:05 +00:00
|
|
|
:depth: 1
|
2020-04-01 18:08:46 +00:00
|
|
|
:local:
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
2019-01-25 08:21:21 +00:00
|
|
|
Introduction
|
|
|
|
------------
|
|
|
|
|
2019-04-12 13:52:06 +00:00
|
|
|
The idea behind using a configuration file is to help keeping your code free of private settings information such as
|
2019-06-07 13:50:15 +00:00
|
|
|
the API Key and Proxy, without having you to even deal with how to load such settings. The configuration file, usually
|
2019-01-25 08:40:55 +00:00
|
|
|
referred as ``config.ini`` file, is automatically loaded from the root of your working directory; all you need to do is
|
2019-01-25 08:21:21 +00:00
|
|
|
fill in the necessary parts.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The configuration file is optional, but recommended. If, for any reason, you prefer not to use it, there's always an
|
|
|
|
alternative way to configure Pyrogram via Client's parameters. Doing so, you can have full control on how to store
|
|
|
|
and load your settings (e.g.: from environment variables).
|
|
|
|
|
|
|
|
Settings specified via Client's parameter have higher priority and will override any setting stored in the
|
|
|
|
configuration file.
|
|
|
|
|
|
|
|
|
|
|
|
The config.ini File
|
|
|
|
-------------------
|
|
|
|
|
2019-01-25 08:40:55 +00:00
|
|
|
By default, Pyrogram will look for a file named ``config.ini`` placed at the root of your working directory, that is,
|
|
|
|
the same folder of your running script. You can change the name or location of your configuration file by specifying it
|
|
|
|
in your Client's parameter *config_file*.
|
2019-01-25 08:21:21 +00:00
|
|
|
|
|
|
|
- Replace the default *config.ini* file with *my_configuration.ini*:
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
from pyrogram import Client
|
|
|
|
|
|
|
|
app = Client("my_account", config_file="my_configuration.ini")
|
|
|
|
|
|
|
|
|
|
|
|
Configuration Sections
|
|
|
|
----------------------
|
|
|
|
|
2019-01-25 08:40:55 +00:00
|
|
|
These are all the sections Pyrogram uses in its configuration file:
|
2019-01-25 08:21:21 +00:00
|
|
|
|
|
|
|
Pyrogram
|
|
|
|
^^^^^^^^
|
|
|
|
|
2019-04-12 13:52:06 +00:00
|
|
|
The ``[pyrogram]`` section contains your Telegram API credentials: *api_id* and *api_hash*.
|
2019-01-25 08:21:21 +00:00
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
[pyrogram]
|
|
|
|
api_id = 12345
|
|
|
|
api_hash = 0123456789abcdef0123456789abcdef
|
|
|
|
|
2019-05-13 16:04:44 +00:00
|
|
|
`More info about API Key. <../intro/setup#api-keys>`_
|
2019-01-25 08:21:21 +00:00
|
|
|
|
|
|
|
Proxy
|
|
|
|
^^^^^
|
|
|
|
|
2019-01-25 08:40:55 +00:00
|
|
|
The ``[proxy]`` section contains settings about your SOCKS5 proxy.
|
2019-01-25 08:21:21 +00:00
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
[proxy]
|
|
|
|
enabled = True
|
|
|
|
hostname = 11.22.33.44
|
|
|
|
port = 1080
|
|
|
|
username = <your_username>
|
|
|
|
password = <your_password>
|
|
|
|
|
2019-05-13 16:04:44 +00:00
|
|
|
`More info about SOCKS5 Proxy. <proxy>`_
|
2019-01-25 08:40:55 +00:00
|
|
|
|
|
|
|
Plugins
|
|
|
|
^^^^^^^
|
|
|
|
|
|
|
|
The ``[plugins]`` section contains settings about Smart Plugins.
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
[plugins]
|
|
|
|
root = plugins
|
|
|
|
include =
|
|
|
|
module
|
|
|
|
folder.module
|
|
|
|
exclude =
|
|
|
|
module fn2
|
|
|
|
|
2019-05-13 16:04:44 +00:00
|
|
|
`More info about Smart Plugins. <smart-plugins>`_
|