2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 13:27:47 +00:00

Update docs

This commit is contained in:
Dan 2018-04-15 20:56:06 +02:00
parent e469115138
commit 0a3c1827aa
6 changed files with 66 additions and 65 deletions

View File

@ -23,7 +23,7 @@ import sys
sys.path.insert(0, os.path.abspath('../..'))
# Import after sys.path.insert() to avoid issues
# from pyrogram import __version__
from pyrogram import __version__
# -- General configuration ------------------------------------------------
@ -68,9 +68,9 @@ author = 'Dan Tès'
# built documents.
#
# The short X.Y version.
# version = "version " + __version__
version = "version " + __version__
# The full version, including alpha/beta/rc tags.
# release = version
release = version
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@ -111,7 +111,7 @@ html_theme_options = {
'collapse_navigation': False,
'sticky_navigation': False,
'logo_only': True,
'display_version': False
'display_version': True
}
# The name of an image file (relative to this directory) to place at the top

View File

@ -53,23 +53,23 @@ Welcome to Pyrogram
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
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.
Overview
--------
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 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**: The low-level details of MTProto are automatically handled by the library.
- ⚡️ **Fast**: Crypto parts are boosted up by TgCrypto_, a high-performance library written in pure C.
- 🔄 **Updated** to the latest Telegram MTProto API version, currently Layer 76.
- 📖 **Documented**: Pyrogram API methods are documented and resemble the Telegram Bot API.
- 🔋 **Full API**, allows to execute any advanced action an official client is able to do, and more.
- **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.
- **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 76 running on MTProto 2.0.
- **Documented**: Pyrogram API methods are documented and resemble the Telegram Bot API.
- **Full API**, allowing to execute any advanced action an official client is able to do, and more.
To get started, press the Next button.
@ -85,13 +85,13 @@ To get started, press the Next button.
:hidden:
:caption: Resources
resources/TextFormatting
resources/UpdateHandling
resources/ErrorHandling
resources/SOCKS5Proxy
resources/AutoAuthorization
resources/TgCrypto
resources/AutoAuthorization
resources/TextFormatting
resources/BotsInteraction
resources/ErrorHandling
.. toctree::
:hidden:

View File

@ -11,73 +11,74 @@ Registering an Handler
We shall examine the :obj:`MessageHandler <pyrogram.MessageHandler>`, which will be in charge for handling
:obj:`Message <pyrogram.api.types.pyrogram.Message>` objects.
The easiest and nicest way to register a MessageHandler is by decorating your function with the
:meth:`on_message() <pyrogram.Client.on_message>` decorator. Here's a full example that prints out the content
of a message as soon as it arrives.
- The easiest and nicest way to register a MessageHandler is by decorating your function with the
:meth:`on_message() <pyrogram.Client.on_message>` decorator. Here's a full example that prints out the content
of a message as soon as it arrives.
.. code-block:: python
.. code-block:: python
from pyrogram import Client
from pyrogram import Client
app = Client("my_account")
app = Client("my_account")
@app.on_message()
def my_handler(client, message):
print(message)
@app.on_message()
def my_handler(client, message):
print(message)
app.start()
app.idle()
app.start()
app.idle()
If you prefer not to use decorators, there is an alternative way for registering Handlers.
This is useful, for example, if you want to keep your callback functions in a separate file.
- If you prefer not to use decorators, there is an alternative way for registering Handlers.
This is useful, for example, when you want to keep your callback functions in a separate file.
.. code-block:: python
.. code-block:: python
from pyrogram import Client, MessageHandler
from pyrogram import Client, MessageHandler
def my_handler(client, message):
print(message)
def my_handler(client, message):
print(message)
app = Client("my_account")
app = Client("my_account")
app.add_handler(MessageHandler(my_handler))
app.start()
app.idle()
app.add_handler(MessageHandler(my_handler))
app.start()
app.idle()
Using Filters
-------------
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 handle only messages
containing an :obj:`Audio <pyrogram.api.types.pyrogram.Audio>` object:
:class:`Filters <pyrogram.Filters>`.
.. code-block:: python
- This example will show you how to handle only messages containing an :obj:`Audio <pyrogram.api.types.pyrogram.Audio>`
object:
from pyrogram import Filters
.. code-block:: python
from pyrogram import Filters
@app.on_message(Filters.audio)
def my_handler(client, message):
print(message)
@app.on_message(Filters.audio)
def my_handler(client, message):
print(message)
or, without decorators:
- or, without decorators:
.. code-block:: python
.. code-block:: python
from pyrogram import Filters, Messagehandler
from pyrogram import Filters, Messagehandler
def my_handler(client, message):
print(message)
def my_handler(client, message):
print(message)
app.add_handler(MessageHandler(my_handler, Filters.audio))
app.add_handler(MessageHandler(my_handler, Filters.audio))
Combining Filters
-----------------
@ -142,5 +143,5 @@ More handlers using different filters can also live together:
@app.on_message(Filters.chat("PyrogramChat"))
def my_handler(client, message):
def from_pyrogramchat(client, message):
print("New message in @PyrogramChat")

View File

@ -10,7 +10,7 @@ Simple API Access
-----------------
The easiest way to interact with the Telegram API is via the :class:`Client <pyrogram.Client>` class, which
exposes bot-like_ methods:
exposes `Bot API-like`_ methods:
- Get information about the authorized user:
@ -94,4 +94,4 @@ Here some examples:
)
)
.. _bot-like: https://core.telegram.org/bots/api#available-methods
.. _`Bot API-like`: https://core.telegram.org/bots/api#available-methods

View File

@ -12,7 +12,7 @@ If you already have one you can skip this step, otherwise:
#. Visit https://my.telegram.org/apps and log in with your Telegram Account.
#. Fill out the form to register a new Telegram application.
#. Done. The Telegram API key consists of two parts: the **App api_id** and the **App api_hash**
#. Done. The Telegram API key consists of two parts: the **App api_id** and the **App api_hash**.
.. important:: This key should be kept secret.

View File

@ -1,17 +1,17 @@
Quick Installation
==================
The easiest way to install and upgrade Pyrogram is by using **pip**:
- The easiest way to install and upgrade Pyrogram is by using **pip**:
.. code-block:: bash
.. code-block:: bash
$ pip3 install --upgrade pyrogram
$ pip3 install --upgrade pyrogram
or, with TgCrypto_ (recommended):
- or, with TgCrypto_ (recommended):
.. code-block:: bash
.. code-block:: bash
$ pip3 install --upgrade pyrogram[tgcrypto]
$ pip3 install --upgrade pyrogram[tgcrypto]
Bleeding Edge
-------------
@ -32,6 +32,6 @@ If no error shows up you are good to go.
>>> import pyrogram
>>> pyrogram.__version__
'0.6.5'
'0.7.0'
.. _TgCrypto: https://docs.pyrogram.ml/resources/TgCrypto