mirror of
https://github.com/pyrogram/pyrogram
synced 2025-09-01 06:45:39 +00:00
Merge branch 'develop' into plugins
This commit is contained in:
@@ -23,13 +23,13 @@ Welcome to Pyrogram
|
|||||||
<a href="https://t.me/PyrogramChat">
|
<a href="https://t.me/PyrogramChat">
|
||||||
Community
|
Community
|
||||||
</a>
|
</a>
|
||||||
<br><br>
|
<br>
|
||||||
<a href="https://github.com/pyrogram/pyrogram/blob/master/compiler/api/source/main_api.tl">
|
<a href="https://github.com/pyrogram/pyrogram/blob/master/compiler/api/source/main_api.tl">
|
||||||
<img src="https://img.shields.io/badge/SCHEME-LAYER%2082-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
|
<img src="https://img.shields.io/badge/schema-layer%2082-eda738.svg?longCache=true&colorA=262b30"
|
||||||
alt="Scheme Layer">
|
alt="Scheme Layer">
|
||||||
</a>
|
</a>
|
||||||
<a href="https://github.com/pyrogram/tgcrypto">
|
<a href="https://github.com/pyrogram/tgcrypto">
|
||||||
<img src="https://img.shields.io/badge/TGCRYPTO-V1.1.1-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30"
|
<img src="https://img.shields.io/badge/tgcrypto-v1.1.1-eda738.svg?longCache=true&colorA=262b30"
|
||||||
alt="TgCrypto">
|
alt="TgCrypto">
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
@@ -49,14 +49,14 @@ Welcome to Pyrogram
|
|||||||
app.run()
|
app.run()
|
||||||
|
|
||||||
Welcome to Pyrogram's Documentation! Here you can find resources for learning how to use the library.
|
Welcome to Pyrogram's Documentation! Here you can find resources for learning how to use the library.
|
||||||
Contents are organized by topic and can be accessed from the sidebar, or by following them one by one using the Next
|
Contents are organized into self-contained topics and can be accessed from the sidebar, or by following them in order
|
||||||
button at the end of each page. But first, here's a brief overview of what is this all about.
|
using the Next button at the end of each page. But first, here's a brief overview of what is this all about.
|
||||||
|
|
||||||
About
|
About
|
||||||
-----
|
-----
|
||||||
|
|
||||||
**Pyrogram** is a brand new Telegram_ Client Library written from the ground up in Python and C. It can be used for building
|
**Pyrogram** is a brand new Telegram_ Client Library written from the ground up in Python and C. It can be used for
|
||||||
custom Telegram applications that interact with the MTProto API as both User and Bot.
|
building custom Telegram applications that interact with the MTProto API as both User and Bot.
|
||||||
|
|
||||||
Features
|
Features
|
||||||
--------
|
--------
|
||||||
@@ -64,7 +64,7 @@ Features
|
|||||||
- **Easy to use**: You can easily install Pyrogram using pip and start building your app right away.
|
- **Easy to use**: You can easily install Pyrogram using pip and start building your app right away.
|
||||||
- **High-level**: The low-level details of MTProto are abstracted and automatically handled.
|
- **High-level**: The low-level details of MTProto are abstracted and automatically handled.
|
||||||
- **Fast**: Crypto parts are boosted up by TgCrypto_, a high-performance library written in pure C.
|
- **Fast**: Crypto parts are boosted up by TgCrypto_, a high-performance library written in pure C.
|
||||||
- **Updated** to the latest Telegram API version, currently Layer 81 on top of MTProto 2.0.
|
- **Updated** to the latest Telegram API version, currently Layer 82 on top of MTProto 2.0.
|
||||||
- **Documented**: The Pyrogram API is well documented and resembles the Telegram Bot API.
|
- **Documented**: The Pyrogram API is well documented and resembles the Telegram Bot API.
|
||||||
- **Full API**, allowing to execute any advanced action an official client is able to do, and more.
|
- **Full API**, allowing to execute any advanced action an official client is able to do, and more.
|
||||||
|
|
||||||
|
@@ -2,15 +2,15 @@ Update Handling
|
|||||||
===============
|
===============
|
||||||
|
|
||||||
Updates are events that happen in your Telegram account (incoming messages, new channel posts, new members join, ...)
|
Updates are events that happen in your Telegram account (incoming messages, new channel posts, new members join, ...)
|
||||||
and can be handled by registering one or more callback functions in your app by using an `Handler <../pyrogram/Handlers.html>`_.
|
and can be handled by registering one or more callback functions in your app by using `Handlers <../pyrogram/Handlers.html>`_.
|
||||||
|
|
||||||
To put it simply, whenever an update is received from Telegram it will be dispatched and your previously defined callback
|
To put it simply, whenever an update is received from Telegram it will be dispatched and your previously defined callback
|
||||||
function(s) will be called back with the update itself as argument.
|
function(s) matching it will be called back with the update itself as argument.
|
||||||
|
|
||||||
Registering an Handler
|
Registering an Handler
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
To explain how `Handlers <../pyrogram/Handlers.html>`_ work let's have a look at the most used one, the
|
To explain how handlers work let's have a look at the most used one, the
|
||||||
:obj:`MessageHandler <pyrogram.MessageHandler>`, which will be in charge for handling :obj:`Message <pyrogram.Message>`
|
:obj:`MessageHandler <pyrogram.MessageHandler>`, which will be in charge for handling :obj:`Message <pyrogram.Message>`
|
||||||
updates coming from all around your chats. Every other handler shares the same setup logic; you should not have troubles
|
updates coming from all around your chats. Every other handler shares the same setup logic; you should not have troubles
|
||||||
settings them up once you learn from this section.
|
settings them up once you learn from this section.
|
||||||
|
@@ -4,11 +4,12 @@ Installation
|
|||||||
Being a Python library, Pyrogram requires Python to be installed in your system.
|
Being a Python library, Pyrogram requires Python to be installed in your system.
|
||||||
We recommend using the latest version of Python 3 and pip.
|
We recommend using the latest version of Python 3 and pip.
|
||||||
|
|
||||||
Get Python 3 from https://www.python.org/downloads/ or with your package manager and pip
|
Get Python 3 from https://www.python.org/downloads/ (or with your package manager) and pip
|
||||||
by following the instructions at https://pip.pypa.io/en/latest/installing/.
|
by following the instructions at https://pip.pypa.io/en/latest/installing/.
|
||||||
|
|
||||||
.. note::
|
.. important::
|
||||||
Pyrogram supports Python 3 only, starting from version 3.4 and PyPy.
|
|
||||||
|
Pyrogram supports **Python 3** only, starting from version 3.4. **PyPy** is supported too.
|
||||||
|
|
||||||
Install Pyrogram
|
Install Pyrogram
|
||||||
----------------
|
----------------
|
||||||
@@ -29,7 +30,7 @@ Bleeding Edge
|
|||||||
-------------
|
-------------
|
||||||
|
|
||||||
If you want the latest development version of Pyrogram, you can install it straight from the develop_
|
If you want the latest development version of Pyrogram, you can install it straight from the develop_
|
||||||
branch using this command:
|
branch using this command (you might need to install **git** first):
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
|
@@ -53,6 +53,7 @@ fits better for you:
|
|||||||
)
|
)
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
The examples below assume you have created a ``config.ini`` file, thus they won't show the *api_id*
|
The examples below assume you have created a ``config.ini`` file, thus they won't show the *api_id*
|
||||||
and *api_hash* parameters usage.
|
and *api_hash* parameters usage.
|
||||||
|
|
||||||
@@ -74,7 +75,7 @@ the :class:`Client <pyrogram.Client>` class by passing to it a ``session_name``
|
|||||||
This starts an interactive shell asking you to input your **phone number** (including your `Country Code`_)
|
This starts an interactive shell asking you to input your **phone number** (including your `Country Code`_)
|
||||||
and the **phone code** you will receive:
|
and the **phone code** you will receive:
|
||||||
|
|
||||||
.. code::
|
.. code-block:: text
|
||||||
|
|
||||||
Enter phone number: +39**********
|
Enter phone number: +39**********
|
||||||
Is "+39**********" correct? (y/n): y
|
Is "+39**********" correct? (y/n): y
|
||||||
@@ -84,7 +85,9 @@ After successfully authorizing yourself, a new file called ``my_account.session`
|
|||||||
Pyrogram executing API calls with your identity. This file will be loaded again when you restart your app,
|
Pyrogram executing API calls with your identity. This file will be loaded again when you restart your app,
|
||||||
and as long as you keep the session alive, Pyrogram won't ask you again to enter your phone number.
|
and as long as you keep the session alive, Pyrogram won't ask you again to enter your phone number.
|
||||||
|
|
||||||
.. important:: Your ``*.session`` files are personal and must be kept secret.
|
.. important::
|
||||||
|
|
||||||
|
Your ``*.session`` files are personal and must be kept secret.
|
||||||
|
|
||||||
Bot Authorization
|
Bot Authorization
|
||||||
-----------------
|
-----------------
|
||||||
|
@@ -10,25 +10,38 @@ High-level API
|
|||||||
The easiest and recommended way to interact with Telegram is via the high-level Pyrogram methods_ and types_, which are
|
The easiest and recommended way to interact with Telegram is via the high-level Pyrogram methods_ and types_, which are
|
||||||
named after the `Telegram Bot API`_.
|
named after the `Telegram Bot API`_.
|
||||||
|
|
||||||
Examples (more on `GitHub <https://github.com/pyrogram/pyrogram/tree/develop/examples>`_):
|
Here's a simple example:
|
||||||
|
|
||||||
- Get information about the authorized user:
|
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
from pyrogram import Client
|
||||||
|
|
||||||
|
app = Client("my_account")
|
||||||
|
|
||||||
|
app.start()
|
||||||
|
|
||||||
print(app.get_me())
|
print(app.get_me())
|
||||||
|
app.send_message("me", "Hi there! I'm using **Pyrogram**")
|
||||||
|
app.send_location("me", 51.500729, -0.124583)
|
||||||
|
|
||||||
- Send a message to yourself (Saved Messages):
|
app.stop()
|
||||||
|
|
||||||
|
You can also use Pyrogram in a context manager with the ``with`` statement. The Client will automatically
|
||||||
|
:meth:`start <pyrogram.Client.start>` and :meth:`stop <pyrogram.Client.stop>` gracefully, even in case of unhandled
|
||||||
|
exceptions in your code:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
app.send_message("me", "Hi there! I'm using Pyrogram")
|
from pyrogram import Client
|
||||||
|
|
||||||
- Upload a new photo (with caption):
|
app = Client("my_account")
|
||||||
|
|
||||||
.. code-block:: python
|
with app:
|
||||||
|
print(app.get_me())
|
||||||
|
app.send_message("me", "Hi there! I'm using **Pyrogram**")
|
||||||
|
app.send_location("me", 51.500729, -0.124583)
|
||||||
|
|
||||||
app.send_photo("me", "/home/dan/perla.jpg", "Cute!")
|
More examples on `GitHub <https://github.com/pyrogram/pyrogram/tree/develop/examples>`_.
|
||||||
|
|
||||||
Raw Functions
|
Raw Functions
|
||||||
-------------
|
-------------
|
||||||
@@ -38,7 +51,9 @@ you have to use the raw :mod:`functions <pyrogram.api.functions>` and :mod:`type
|
|||||||
``pyrogram.api`` package and call any Telegram API method you wish using the :meth:`send() <pyrogram.Client.send>`
|
``pyrogram.api`` package and call any Telegram API method you wish using the :meth:`send() <pyrogram.Client.send>`
|
||||||
method provided by the Client class.
|
method provided by the Client class.
|
||||||
|
|
||||||
.. hint:: Every high-level method mentioned in the section above is built on top of these raw functions.
|
.. hint::
|
||||||
|
|
||||||
|
Every high-level method mentioned in the section above is built on top of these raw functions.
|
||||||
|
|
||||||
Nothing stops you from using the raw functions only, but they are rather complex and `plenty of them`_ are already
|
Nothing stops you from using the raw functions only, but they are rather complex and `plenty of them`_ are already
|
||||||
re-implemented by providing a much simpler and cleaner interface which is very similar to the Bot API.
|
re-implemented by providing a much simpler and cleaner interface which is very similar to the Bot API.
|
||||||
@@ -54,17 +69,13 @@ Examples (more on `GitHub <https://github.com/pyrogram/pyrogram/tree/develop/exa
|
|||||||
from pyrogram import Client
|
from pyrogram import Client
|
||||||
from pyrogram.api import functions
|
from pyrogram.api import functions
|
||||||
|
|
||||||
app = Client("my_account")
|
with Client("my_account") as app:
|
||||||
app.start()
|
app.send(
|
||||||
|
functions.account.UpdateProfile(
|
||||||
app.send(
|
first_name="Dan", last_name="Tès",
|
||||||
functions.account.UpdateProfile(
|
about="Bio written from Pyrogram"
|
||||||
first_name="Dan", last_name="Tès",
|
)
|
||||||
about="Bio written from Pyrogram"
|
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
app.stop()
|
|
||||||
|
|
||||||
- Share your Last Seen time only with your contacts:
|
- Share your Last Seen time only with your contacts:
|
||||||
|
|
||||||
@@ -73,17 +84,13 @@ Examples (more on `GitHub <https://github.com/pyrogram/pyrogram/tree/develop/exa
|
|||||||
from pyrogram import Client
|
from pyrogram import Client
|
||||||
from pyrogram.api import functions, types
|
from pyrogram.api import functions, types
|
||||||
|
|
||||||
app = Client("my_account")
|
with Client("my_account") as app:
|
||||||
app.start()
|
app.send(
|
||||||
|
functions.account.SetPrivacy(
|
||||||
app.send(
|
key=types.InputPrivacyKeyStatusTimestamp(),
|
||||||
functions.account.SetPrivacy(
|
rules=[types.InputPrivacyValueAllowContacts()]
|
||||||
key=types.InputPrivacyKeyStatusTimestamp(),
|
)
|
||||||
rules=[types.InputPrivacyValueAllowContacts()]
|
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
app.stop()
|
|
||||||
|
|
||||||
- Invite users to your channel/supergroup:
|
- Invite users to your channel/supergroup:
|
||||||
|
|
||||||
@@ -92,21 +99,17 @@ Examples (more on `GitHub <https://github.com/pyrogram/pyrogram/tree/develop/exa
|
|||||||
from pyrogram import Client
|
from pyrogram import Client
|
||||||
from pyrogram.api import functions, types
|
from pyrogram.api import functions, types
|
||||||
|
|
||||||
app = Client("my_account")
|
with Client("my_account") as app:
|
||||||
app.start()
|
app.send(
|
||||||
|
functions.channels.InviteToChannel(
|
||||||
app.send(
|
channel=app.resolve_peer(123456789), # ID or Username
|
||||||
functions.channels.InviteToChannel(
|
users=[ # The users you want to invite
|
||||||
channel=app.resolve_peer(123456789), # ID or Username
|
app.resolve_peer(23456789), # By ID
|
||||||
users=[ # The users you want to invite
|
app.resolve_peer("username"), # By username
|
||||||
app.resolve_peer(23456789), # By ID
|
app.resolve_peer("393281234567"), # By phone number
|
||||||
app.resolve_peer("username"), # By username
|
]
|
||||||
app.resolve_peer("393281234567"), # By phone number
|
)
|
||||||
]
|
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
app.stop()
|
|
||||||
|
|
||||||
.. _methods: ../pyrogram/Client.html#messages
|
.. _methods: ../pyrogram/Client.html#messages
|
||||||
.. _plenty of them: ../pyrogram/Client.html#messages
|
.. _plenty of them: ../pyrogram/Client.html#messages
|
||||||
|
Reference in New Issue
Block a user