mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Allow accessing Object fields using square brackets
This commit is contained in:
parent
e8193435a9
commit
c84c64a5e1
@ -51,35 +51,22 @@ Welcome to Pyrogram
|
|||||||
app.start()
|
app.start()
|
||||||
app.idle()
|
app.idle()
|
||||||
|
|
||||||
About
|
|
||||||
-----
|
|
||||||
|
|
||||||
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 by topic and can be accessed from the sidebar, or by following them one by one using the Next
|
||||||
button at the end of each page. But first, here's a brief overview of what is this all about:
|
button at the end of each page. But first, here's a brief overview of what is this all 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 building
|
||||||
custom Telegram applications in Python that interact with the MTProto API as both User and Bot.
|
custom Telegram applications that interact with the MTProto API as both User and Bot.
|
||||||
|
|
||||||
|
Awesomeness
|
||||||
|
-----------
|
||||||
|
|
||||||
Features
|
- 📦 **Easy to use**: You can easily install Pyrogram using pip and start building your app right away.
|
||||||
--------
|
- 🚀 **High-level**: All the low-level details of communication with Telegram servers are automatically handled.
|
||||||
|
- ⚡️ **Fast**: Critical parts are boosted up by TgCrypto_, a high-performance Crypto Library written in pure C.
|
||||||
- **Easy to setup**: Pyrogram can be easily installed using pip and requires very few lines of code to get started with.
|
- 🔄 **Updated** to the latest Telegram MTProto API version, currently Layer 76.
|
||||||
|
- 📖 **Documented**: Pyrogram public API methods are documented and resemble the Telegram Bot API.
|
||||||
- **Easy to use**: Pyrogram provides idiomatic, clean and readable Python code making the Telegram API simple to use.
|
- 🔋 **Full API**, allows to execute any advanced action an official client is able to do, and more.
|
||||||
|
|
||||||
- **High-level**: Pyrogram automatically handles all the low-level details of communication with Telegram servers.
|
|
||||||
|
|
||||||
- **Updated**: Pyrogram makes use of the latest Telegram MTProto API version, currently Layer 76.
|
|
||||||
|
|
||||||
- **Fast**: Pyrogram critical parts are boosted up by `TgCrypto`_, a high-performance Crypto Library written in pure C.
|
|
||||||
|
|
||||||
- **Documented**: Pyrogram API methods are documented and resemble the well established Telegram Bot API,
|
|
||||||
thus offering a familiar look to Bot developers.
|
|
||||||
|
|
||||||
- **Full API support**: Beside the simple Bot API-like methods, Pyrogram also provides an easy access to every single
|
|
||||||
Telegram MTProto API method allowing you to programmatically execute any action an official client is able to do, and more.
|
|
||||||
|
|
||||||
To get started, press the Next button.
|
To get started, press the Next button.
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ Pyrogram
|
|||||||
In this section you can find a detailed description of the Pyrogram package and its high-level API.
|
In this section you can find a detailed description of the Pyrogram package and its high-level API.
|
||||||
|
|
||||||
:class:`Client <pyrogram.Client>` is the main class. It exposes easy-to-use methods that are named
|
:class:`Client <pyrogram.Client>` is the main class. It exposes easy-to-use methods that are named
|
||||||
after the `Telegram Bot API`_ methods, thus offering a familiar look to Bot developers.
|
after the well established `Telegram Bot API`_ methods, thus offering a familiar look to Bot developers.
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
Client
|
Client
|
||||||
|
@ -26,15 +26,15 @@ ask you to input the phone code manually.
|
|||||||
return code # Must be string, e.g., "12345"
|
return code # Must be string, e.g., "12345"
|
||||||
|
|
||||||
|
|
||||||
client = Client(
|
app = Client(
|
||||||
session_name="example",
|
session_name="example",
|
||||||
phone_number="39**********",
|
phone_number="39**********",
|
||||||
phone_code=phone_code_callback,
|
phone_code=phone_code_callback,
|
||||||
password="password" # (if you have one)
|
password="password" # (if you have one)
|
||||||
)
|
)
|
||||||
|
|
||||||
client.start()
|
app.start()
|
||||||
print(client.get_me())
|
print(app.get_me())
|
||||||
|
|
||||||
Sign Up
|
Sign Up
|
||||||
-------
|
-------
|
||||||
@ -52,7 +52,7 @@ Telegram account in case the phone number you passed is not registered yet.
|
|||||||
return code # Must be string, e.g., "12345"
|
return code # Must be string, e.g., "12345"
|
||||||
|
|
||||||
|
|
||||||
client = Client(
|
app = Client(
|
||||||
session_name="example",
|
session_name="example",
|
||||||
phone_number="39**********",
|
phone_number="39**********",
|
||||||
phone_code=phone_code_callback,
|
phone_code=phone_code_callback,
|
||||||
@ -60,5 +60,5 @@ Telegram account in case the phone number you passed is not registered yet.
|
|||||||
last_name="" # Can be an empty string
|
last_name="" # Can be an empty string
|
||||||
)
|
)
|
||||||
|
|
||||||
client.start()
|
app.start()
|
||||||
print(client.get_me())
|
print(app.get_me())
|
@ -13,7 +13,7 @@ Inline Bots
|
|||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
# Get bot results for "Fuzz Universe" from the inline bot @vid
|
# Get bot results for "Fuzz Universe" from the inline bot @vid
|
||||||
bot_results = client.get_inline_bot_results("vid", "Fuzz Universe")
|
bot_results = app.get_inline_bot_results("vid", "Fuzz Universe")
|
||||||
|
|
||||||
.. figure:: https://i.imgur.com/IAqLs54.png
|
.. figure:: https://i.imgur.com/IAqLs54.png
|
||||||
:width: 90%
|
:width: 90%
|
||||||
@ -29,7 +29,7 @@ Inline Bots
|
|||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
# Send the first result (bot_results.results[0]) to your own chat (Saved Messages)
|
# Send the first result (bot_results.results[0]) to your own chat (Saved Messages)
|
||||||
client.send_inline_bot_result("me", bot_results.query_id, bot_results.results[0].id)
|
app.send_inline_bot_result("me", bot_results.query_id, bot_results.results[0].id)
|
||||||
|
|
||||||
.. figure:: https://i.imgur.com/wwxr7B7.png
|
.. figure:: https://i.imgur.com/wwxr7B7.png
|
||||||
:width: 90%
|
:width: 90%
|
||||||
|
@ -32,7 +32,7 @@ Usage
|
|||||||
|
|
||||||
from pyrogram import Client
|
from pyrogram import Client
|
||||||
|
|
||||||
client = Client(
|
app = Client(
|
||||||
session_name="example",
|
session_name="example",
|
||||||
proxy=dict(
|
proxy=dict(
|
||||||
hostname="11.22.33.44",
|
hostname="11.22.33.44",
|
||||||
@ -42,7 +42,7 @@ Usage
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
client.start()
|
app.start()
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ Examples
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
client.send_message(
|
app.send_message(
|
||||||
chat_id="me",
|
chat_id="me",
|
||||||
text=(
|
text=(
|
||||||
"**bold**, "
|
"**bold**, "
|
||||||
@ -71,7 +71,7 @@ Examples
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
client.send_message(
|
app.send_message(
|
||||||
chat_id="me",
|
chat_id="me",
|
||||||
text=(
|
text=(
|
||||||
# Code block language is optional
|
# Code block language is optional
|
||||||
@ -88,7 +88,7 @@ Examples
|
|||||||
|
|
||||||
from pyrogram import ParseMode
|
from pyrogram import ParseMode
|
||||||
|
|
||||||
client.send_message(
|
app.send_message(
|
||||||
chat_id="me",
|
chat_id="me",
|
||||||
text=(
|
text=(
|
||||||
"<b>bold</b>, <strong>bold</strong>, "
|
"<b>bold</b>, <strong>bold</strong>, "
|
||||||
|
@ -54,7 +54,7 @@ Using Filters
|
|||||||
-------------
|
-------------
|
||||||
|
|
||||||
For a finer grained control over what kind of messages will be allowed or not in your callback functions, you can use
|
For a finer grained control over what kind of messages will be allowed or not in your callback functions, you can use
|
||||||
:class:`Filters <pyrogram.Filters>`. The next example will show you how to handler only messages
|
:class:`Filters <pyrogram.Filters>`. The next example will show you how to handle only messages
|
||||||
containing an :obj:`Audio <pyrogram.api.types.pyrogram.Audio>` object:
|
containing an :obj:`Audio <pyrogram.api.types.pyrogram.Audio>` object:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
@ -97,7 +97,7 @@ Here are some examples:
|
|||||||
def my_handler(client, message):
|
def my_handler(client, message):
|
||||||
print(message)
|
print(message)
|
||||||
|
|
||||||
- Message is a **sticker** **and** is coming from a **channel** or a **private** chat.
|
- Message is a **sticker** **and** is coming from a **channel or** a **private** chat.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ can also accept arguments:
|
|||||||
def my_handler(client, message):
|
def my_handler(client, message):
|
||||||
print(message)
|
print(message)
|
||||||
|
|
||||||
- Message is a **text** message matching the given regex pattern.
|
- Message is a **text** message matching the given **regex** pattern.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ can also accept arguments:
|
|||||||
def my_handler(client, message):
|
def my_handler(client, message):
|
||||||
print(message)
|
print(message)
|
||||||
|
|
||||||
More handlers using different filters can be created as well:
|
More handlers using different filters can also live together:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
@ -9,31 +9,29 @@ Basic Usage
|
|||||||
Simple API Access
|
Simple API Access
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
The easiest way to interact with the Telegram API is via the :class:`Client <pyrogram.Client>` class,
|
The easiest way to interact with the Telegram API is via the :class:`Client <pyrogram.Client>` class, which
|
||||||
which exposes bot-like_ methods. The purpose of this Client class is to make it even simpler to work with the
|
exposes bot-like_ methods:
|
||||||
API by abstracting the raw functions listed in the schema.
|
|
||||||
|
|
||||||
The result is a much cleaner interface that allows you to:
|
|
||||||
|
|
||||||
- Get information about the authorized user:
|
- Get information about the authorized user:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
print(client.get_me())
|
print(app.get_me())
|
||||||
|
|
||||||
- Send a message to yourself (Saved Messages):
|
- Send a message to yourself (Saved Messages):
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
client.send_message("me", "Hi there! I'm using Pyrogram")
|
app.send_message("me", "Hi there! I'm using Pyrogram")
|
||||||
|
|
||||||
- Upload a photo (with caption):
|
- Upload a new photo (with caption):
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
client.send_photo("me", "/home/dan/perla.jpg", "Cute!")
|
app.send_photo("me", "/home/dan/perla.jpg", "Cute!")
|
||||||
|
|
||||||
.. seealso:: For a complete list of the available methods have a look at the :class:`Client <pyrogram.Client>` class.
|
.. seealso:: For a complete list of the available methods and an exhaustive description for each of them, have a look
|
||||||
|
at the :class:`Client <pyrogram.Client>` class.
|
||||||
|
|
||||||
.. _using-raw-functions:
|
.. _using-raw-functions:
|
||||||
|
|
||||||
@ -55,7 +53,7 @@ Here some examples:
|
|||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
client.send(
|
app.send(
|
||||||
functions.account.UpdateProfile(
|
functions.account.UpdateProfile(
|
||||||
first_name="Dan", last_name="Tès",
|
first_name="Dan", last_name="Tès",
|
||||||
about="Bio written from Pyrogram"
|
about="Bio written from Pyrogram"
|
||||||
@ -70,7 +68,7 @@ Here some examples:
|
|||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
client.send(
|
app.send(
|
||||||
functions.account.SetPrivacy(
|
functions.account.SetPrivacy(
|
||||||
key=types.InputPrivacyKeyStatusTimestamp(),
|
key=types.InputPrivacyKeyStatusTimestamp(),
|
||||||
rules=[types.InputPrivacyValueAllowContacts()]
|
rules=[types.InputPrivacyValueAllowContacts()]
|
||||||
@ -85,13 +83,13 @@ Here some examples:
|
|||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
client.send(
|
app.send(
|
||||||
functions.channels.InviteToChannel(
|
functions.channels.InviteToChannel(
|
||||||
channel=client.resolve_peer(123456789), # ID or Username
|
channel=app.resolve_peer(123456789), # ID or Username
|
||||||
users=[ # The users you want to invite
|
users=[ # The users you want to invite
|
||||||
client.resolve_peer(23456789), # By ID
|
app.resolve_peer(23456789), # By ID
|
||||||
client.resolve_peer("username"), # By username
|
app.resolve_peer("username"), # By username
|
||||||
client.resolve_peer("393281234567"), # By phone number
|
app.resolve_peer("393281234567"), # By phone number
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -21,7 +21,7 @@ Configuration
|
|||||||
|
|
||||||
There are two ways to configure a Pyrogram application project, and you can choose the one that fits better for you:
|
There are two ways to configure a Pyrogram application project, and you can choose the one that fits better for you:
|
||||||
|
|
||||||
Create a new ``config.ini`` file at the root of your working directory, copy-paste the following and replace the
|
- Create a new ``config.ini`` file at the root of your working directory, copy-paste the following and replace the
|
||||||
**api_id** and **api_hash** values with `your own <#api-keys>`_. This is the preferred method because allows you
|
**api_id** and **api_hash** values with `your own <#api-keys>`_. This is the preferred method because allows you
|
||||||
to keep your credentials out of your code without having to deal with how to load them:
|
to keep your credentials out of your code without having to deal with how to load them:
|
||||||
|
|
||||||
@ -31,15 +31,15 @@ to keep your credentials out of your code without having to deal with how to loa
|
|||||||
api_id = 12345
|
api_id = 12345
|
||||||
api_hash = 0123456789abcdef0123456789abcdef
|
api_hash = 0123456789abcdef0123456789abcdef
|
||||||
|
|
||||||
Alternatively, you can pass your API key to Pyrogram by simply using the *api_id* and *api_hash*
|
- Alternatively, you can pass your API key to Pyrogram by simply using the *api_id* and *api_hash*
|
||||||
parameters of the Client class. This way you can have full control on how to store and load your credentials:
|
parameters of the Client class. This way you can have full control on how to store and load your credentials:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from pyrogram import Client
|
from pyrogram import Client
|
||||||
|
|
||||||
client = Client(
|
app = Client(
|
||||||
session_name="example",
|
session_name="my_account",
|
||||||
api_id=12345
|
api_id=12345
|
||||||
api_hash="0123456789abcdef0123456789abcdef"
|
api_hash="0123456789abcdef0123456789abcdef"
|
||||||
)
|
)
|
||||||
@ -52,15 +52,15 @@ User Authorization
|
|||||||
|
|
||||||
In order to use the API, Telegram requires that Users be authorized via their phone numbers.
|
In order to use the API, Telegram requires that Users be authorized via their phone numbers.
|
||||||
Pyrogram automatically manages this access, all you need to do is create an instance of
|
Pyrogram automatically manages this access, all you need to do is create an instance of
|
||||||
the :class:`Client <pyrogram.Client>` class by passing to it a ``<session_name>`` of your choice
|
the :class:`Client <pyrogram.Client>` class by passing to it a ``session_name`` of your choice
|
||||||
(e.g.: "my_account") and call the :meth:`start() <pyrogram.Client.start>` method:
|
(e.g.: "my_account") and call the :meth:`start() <pyrogram.Client.start>` method:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from pyrogram import Client
|
from pyrogram import Client
|
||||||
|
|
||||||
client = Client("my_account")
|
app = Client("my_account")
|
||||||
client.start()
|
app.start()
|
||||||
|
|
||||||
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:
|
||||||
@ -90,11 +90,11 @@ Instead of phone numbers, Bots are authorized via their tokens which are created
|
|||||||
|
|
||||||
from pyrogram import Client
|
from pyrogram import Client
|
||||||
|
|
||||||
client = Client("123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11")
|
app = Client("123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11")
|
||||||
client.start()
|
app.start()
|
||||||
|
|
||||||
That's all, no further action is needed. The session file created will be named after the Bot user_id, which is
|
That's all, no further action is needed. The session file will be named after the Bot user_id, which is
|
||||||
``123456.session`` in the example above.
|
``123456.session`` for the example above.
|
||||||
|
|
||||||
.. _`Country Code`: https://en.wikipedia.org/wiki/List_of_country_calling_codes
|
.. _`Country Code`: https://en.wikipedia.org/wiki/List_of_country_calling_codes
|
||||||
.. _BotFather: https://t.me/botfather
|
.. _BotFather: https://t.me/botfather
|
Loading…
x
Reference in New Issue
Block a user