Skip to content

Commit 5182204

Browse files
committed
Docs revamp. Part 5
1 parent b6ea451 commit 5182204

14 files changed

Lines changed: 144 additions & 68 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ground up in Python and C. It enables you to easily create custom apps for both
5959
- **Documented**: Pyrogram API methods, types and public interfaces are well documented.
6060
- **Type-hinted**: Exposed Pyrogram types and method parameters are all type-hinted.
6161
- **Updated**, to make use of the latest Telegram API version and features.
62+
- **Bot API-like**: Similar to the Bot API in its simplicity, but much more powerful and detailed.
6263
- **Pluggable**: The Smart Plugin system allows to write components with minimal boilerplate code.
6364
- **Comprehensive**: Execute any advanced action an official client is able to do, and even more.
6465

docs/source/index.rst

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,15 @@ Welcome to Pyrogram
1414

1515
<br>
1616
<a href="https://github.com/pyrogram/pyrogram">
17-
GitHub
17+
Source Code
1818
</a>
19-
20-
<a href="https://t.me/Pyrogram">
21-
Community
22-
</a>
23-
2419
2520
<a href="https://github.com/pyrogram/pyrogram/releases">
2621
Releases
2722
</a>
2823
29-
<a href="https://pypi.org/project/Pyrogram">
30-
PyPI
31-
</a>
32-
<br>
33-
<a href="compiler/api/source/main_api.tl">
34-
<img src="https://img.shields.io/badge/schema-layer%2097-eda738.svg?longCache=true&colorA=262b30"
35-
alt="Schema Layer">
36-
</a>
37-
<a href="https://github.com/pyrogram/tgcrypto">
38-
<img src="https://img.shields.io/badge/tgcrypto-v1.1.1-eda738.svg?longCache=true&colorA=262b30"
39-
alt="TgCrypto Version">
24+
<a href="https://t.me/Pyrogram">
25+
Community
4026
</a>
4127
</p>
4228

@@ -59,7 +45,7 @@ C. It enables you to easily create custom apps for both user and bot identities
5945
`MTProto API`_.
6046

6147
.. _Telegram: https://telegram.org
62-
.. _MTProto API: https://core.telegram.org/api#telegram-api
48+
.. _MTProto API: topics/faq#what-can-mtproto-do-more-than-the-bot-api
6349

6450
How the Documentation is Organized
6551
----------------------------------
@@ -68,11 +54,11 @@ Contents are organized into self-contained topics and can be all accessed from t
6854
order using the Next button at the end of each page. Here below you can, instead, find a list of the most relevant
6955
pages for a quick access.
7056

71-
Getting Started
72-
^^^^^^^^^^^^^^^
57+
First Steps
58+
^^^^^^^^^^^
7359

74-
- `Quick Start`_ - Overview to get you started as fast as possible.
75-
- `Calling Methods`_ - How to use Pyrogram's API.
60+
- `Quick Start`_ - Overview to get you started quickly.
61+
- `Calling Methods`_ - How to call Pyrogram's methods.
7662
- `Handling Updates`_ - How to handle Telegram updates.
7763
- `Error Handling`_ - How to handle API errors correctly.
7864

@@ -83,7 +69,8 @@ Getting Started
8369

8470
API Reference
8571
^^^^^^^^^^^^^
86-
- `Client Class`_ - Details about the Client class.
72+
73+
- `Client Class`_ - Reference details about the Client class.
8774
- `Available Methods`_ - A list of available high-level methods.
8875
- `Available Types`_ - A list of available high-level types.
8976
- `Bound Methods`_ - A list of convenient bound methods.

docs/source/intro/auth.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Authorization
22
=============
33

44
Once a `project is set up`_, you will still have to follow a few steps before you can actually use Pyrogram to make
5-
API calls. This section provides all the information you need in order to authorize yourself as user or a bot.
5+
API calls. This section provides all the information you need in order to authorize yourself as user or bot.
66

77
User Authorization
88
------------------
@@ -51,7 +51,7 @@ the `Bot Father`_. Bot tokens replace the users' phone numbers only — you stil
5151

5252
The authorization process is automatically managed. All you need to do is choose a ``session_name`` (can be anything,
5353
usually your bot username) and pass your bot token using the ``bot_token`` parameter. The session file will be named
54-
after the session name, which will be ``pyrogrambot.session`` for the example below.
54+
after the session name, which will be ``my_bot.session`` for the example below.
5555

5656
.. code-block:: python
5757

docs/source/intro/install.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Use this command to install (note "asyncio.zip" in the link):
5555
$ pip3 install -U https://github.com/pyrogram/pyrogram/archive/asyncio.zip
5656
5757
58-
Pyrogram API remains the same and features are kept up to date from the non-async, default develop branch, but you
58+
Pyrogram's API remains the same and features are kept up to date from the non-async, default develop branch, but you
5959
are obviously required Python asyncio knowledge in order to take full advantage of it.
6060

6161

@@ -87,7 +87,7 @@ If no error shows up you are good to go.
8787
8888
>>> import pyrogram
8989
>>> pyrogram.__version__
90-
'0.12.0'
90+
'0.13.0'
9191
9292
.. _TgCrypto: ../topics/tgcrypto
9393
.. _`Github repo`: http://github.com/pyrogram/pyrogram

docs/source/intro/start.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Quick Start
22
===========
33

4-
The next few steps serve as a quick start for all new Pyrogrammers that want to get something done as fast as possible!
4+
The next few steps serve as a quick start for all new Pyrogrammers that want to get something done as fast as possible.
5+
Let's go!
56

67
Get Pyrogram Real Fast
78
----------------------

docs/source/start/errors.rst

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ to control the behaviour of your application. Pyrogram errors all live inside th
1111
RPCError
1212
--------
1313

14-
The father of all errors is named ``RPCError``. This error exists in form of a Python exception and is able to catch all
15-
Telegram API related errors.
14+
The father of all errors is named ``RPCError``. This error exists in form of a Python exception which is directly
15+
subclass-ed from Python's main ``Exception`` and is able to catch all Telegram API related errors. This error is raised
16+
every time a method call against Telegram's API was unsuccessful.
1617

1718
.. code-block:: python
1819
@@ -27,7 +28,7 @@ Error Categories
2728
----------------
2829

2930
The ``RPCError`` packs together all the possible errors Telegram could raise, but to make things tidier, Pyrogram
30-
provides categories of errors, which are named after the common HTTP errors:
31+
provides categories of errors, which are named after the common HTTP errors and subclass-ed from the RPCError:
3132

3233
.. code-block:: python
3334
@@ -41,6 +42,32 @@ provides categories of errors, which are named after the common HTTP errors:
4142
- `420 - Flood <../api/errors#flood>`_
4243
- `500 - InternalServerError <../api/errors#internalservererror>`_
4344

45+
Single Errors
46+
-------------
47+
48+
For a fine-grained control over every single error, Pyrogram does also expose errors that deal each with a specific
49+
issue. For example:
50+
51+
.. code-block:: python
52+
53+
from pyrogram.errors import FloodWait
54+
55+
These errors subclass directly from the category of errors they belong to, which in turn subclass from the father
56+
RPCError, thus building a class of error hierarchy such as this:
57+
58+
- RPCError
59+
- BadRequest
60+
- ``MessageEmpty``
61+
- ``UsernameOccupied``
62+
- ``...``
63+
- InternalServerError
64+
- ``RpcCallFail``
65+
- ``InterDcCallError``
66+
- ``...``
67+
- ``...``
68+
69+
.. _Errors: api/errors
70+
4471
Unknown Errors
4572
--------------
4673

docs/source/start/invoking.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Now instantiate a new Client object, "my_account" is a session name of your choi
3636
3737
app = Client("my_account")
3838
39-
To actually make use of any method, the client has to be started:
39+
To actually make use of any method, the client has to be started first:
4040

4141
.. code-block:: python
4242

docs/source/start/updates.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ Defining Updates
99

1010
First, let's define what are these updates. As hinted already, updates are simply events that happen in your Telegram
1111
account (incoming messages, new members join, bot button presses, etc...), which are meant to notify you about a new
12-
specific state that changed. These updates are handled by registering one or more callback functions in your app using
13-
`Handlers <../api/handlers>`_.
12+
specific state that has changed. These updates are handled by registering one or more callback functions in your app
13+
using `Handlers <../api/handlers>`_.
1414

1515
Each handler deals with a specific event and once a matching update arrives from Telegram, your registered callback
16-
function will be called and its body executed.
16+
function will be called back by the framework and its body executed.
1717

1818
Registering an Handler
1919
----------------------
@@ -63,8 +63,8 @@ above must only handle updates that are in form of a :obj:`Message <pyrogram.Mes
6363
my_handler = MessageHandler(my_function)
6464
6565
Third: the method :meth:`add_handler() <pyrogram.Client.add_handler>`. This method is used to actually register the
66-
handler and let Pyrogram know it needs to be taken into consideration when new updates arrive and the dispatching phase
67-
begins.
66+
handler and let Pyrogram know it needs to be taken into consideration when new updates arrive and the internal
67+
dispatching phase begins.
6868

6969
.. code-block:: python
7070
@@ -109,4 +109,4 @@ to do so is by decorating your callback function with the :meth:`on_message() <p
109109
``my_function[0].callback``, that is, the *callback* field of the *handler* object which is the first element in the
110110
tuple, accessed by bracket notation *[0]*.
111111

112-
.. _API methods: usage.html
112+
.. _API methods: invoking

docs/source/topics/faq.rst

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ Pyrogram FAQ
33

44
This FAQ page provides answers to common questions about Pyrogram and, to some extent, Telegram in general.
55

6+
.. tip::
7+
8+
If you think something interesting could be added here, feel free to propose it by opening a `Feature Request`_.
9+
610
.. contents:: Contents
711
:backlinks: none
812
:local:
13+
:depth: 1
914

1015
What is Pyrogram?
1116
-----------------
@@ -41,6 +46,7 @@ Why Pyrogram?
4146
- **Documented**: Pyrogram API methods, types and public interfaces are well documented.
4247
- **Type-hinted**: Exposed Pyrogram types and method parameters are all type-hinted.
4348
- **Updated**, to make use of the latest Telegram API version and features.
49+
- **Bot API-like**: Similar to the Bot API in its simplicity, but much more powerful and detailed.
4450
- **Pluggable**: The `Smart Plugin`_ system allows to write components with minimal boilerplate code.
4551
- **Comprehensive**: Execute any `advanced action`_ an official client is able to do, and even more.
4652

@@ -51,23 +57,41 @@ Why Pyrogram?
5157
What can MTProto do more than the Bot API?
5258
------------------------------------------
5359

54-
- Authorize both user and bot identities.
55-
- Upload & download any file, up to 1500 MB each.
56-
- Has less overhead due to direct connections to the actual Telegram servers.
57-
- Run multiple sessions at once, up to 10 per account (either bot or user).
58-
- Get information about any public chat by usernames, even if not a member.
59-
- Obtain information about any message existing in a chat using message ids.
60-
- retrieve the whole chat members list of either public or private chats.
61-
- Receive extra updates, such as the one about a user name change.
62-
- More meaningful errors in case something went wrong.
63-
- Get API version updates, and thus new features, sooner.
60+
Here you can find a list of all the known advantages in using MTProto-based libraries (Pyrogram) instead of the official
61+
HTTP Bot API:
62+
63+
- **Authorize both user and bot identities**: The Bot API only allows bot accounts.
64+
65+
- **Upload & download any file, up to 1500 MB each (~1.5 GB)**: The Bot API allows uploads and downloads of files only
66+
up to 50 MB / 20 MB in size (respectively).
67+
68+
- **Has less overhead due to direct connections to Telegram**: The Bot API uses an intermediate server to handle HTTP
69+
requests before they are sent to the actual Telegram servers.
70+
71+
- **Run multiple sessions at once, up to 10 per account (either bot or user)**: The Bot API intermediate server will
72+
terminate any other session in case you try to use the same bot again in a parallel connection.
73+
74+
- **Get information about any public chat by usernames, even if not a member**: The Bot API simply doesn't support this.
75+
76+
- **Obtain information about any message existing in a chat using their ids**: The Bot API simply doesn't support this.
77+
78+
- **Retrieve the whole chat members list of either public or private chats**: The Bot API simply doesn't support this.
79+
80+
- **Receive extra updates, such as the one about a user name change**: The Bot API simply doesn't support this.
81+
82+
- **Has more meaningful errors in case something went wrong**: The Bot API reports less detailed errors.
83+
84+
- **Has much more detailed types and powerful methods**: The Bot API types often miss some useful information about
85+
Telegram's type and some of the methods are limited as well.
86+
87+
- **Get API version updates, and thus new features, sooner**: The Bot API is simply slower in implementing new features.
6488

6589
Why do I need an API key for bots?
6690
----------------------------------
6791

68-
Requests against the official bot API endpoint are made via JSON/HTTP, but are handled by a backend application that
69-
implements the MTProto protocol -- just like Pyrogram -- and uses its own API key, which is always required, but hidden
70-
to the public.
92+
Requests against the official bot API endpoint are made via JSON/HTTP, but are handled by an intermediate server
93+
application that implements the MTProto protocol -- just like Pyrogram -- and uses its own API key, which is always
94+
required, but hidden to the public.
7195

7296
.. figure:: https://i.imgur.com/C108qkX.png
7397
:align: center
@@ -76,9 +100,7 @@ Using MTProto is the only way to communicate with the actual Telegram servers, a
76100
identify applications by means of a unique key; the bot token identifies a bot as a user and replaces the user's phone
77101
number only.
78102

79-
Why is the main API (MTProto) superiod
80-
81-
I started a client but nothing happens!
103+
I started a client and nothing happens!
82104
---------------------------------------
83105

84106
If you are connecting from Russia, China or Iran `you need a proxy`_, because Telegram could be partially or
@@ -93,6 +115,15 @@ in a bunch of seconds:
93115
import logging
94116
logging.basicConfig(level=logging.INFO)
95117
118+
Another way to confirm you aren't able to connect to Telegram is by pinging these IP addresses and see whether ping
119+
fails or not:
120+
121+
- DC1: ``149.154.175.50``
122+
- DC2: ``149.154.167.51``
123+
- DC3: ``149.154.175.100``
124+
- DC4: ``149.154.167.91``
125+
- DC5: ``91.108.56.149``
126+
96127
|bug report|
97128

98129
.. _you need a proxy: proxy
@@ -114,7 +145,16 @@ things:
114145

115146
**Note:** If you really believe this should not happen, kindly open a `Bug Report`_.
116147

117-
.. _Bug Report: https://github.com/pyrogram/pyrogram/issues/new?labels=bug&template=bug_report.md
148+
Can I use the same file_id across different accounts?
149+
-----------------------------------------------------
150+
151+
No, Telegram doesn't allow this.
152+
153+
File ids are bound to a specific user/bot, and an attempt in using a foreign file id will result in errors such as
154+
**[400 MEDIA_EMPTY]: The media is invalid**.
155+
156+
The only exception are stickers' file ids; you can use them across different accounts without any problem, like this
157+
one: ``CAADBAADyg4AAvLQYAEYD4F7vcZ43AI``.
118158

119159
My account has been deactivated/limited!
120160
----------------------------------------
@@ -150,4 +190,7 @@ for free under LGPLv3+.
150190

151191
In other words: you can use and integrate Pyrogram into your own code --- either open source, under the same or a
152192
different licence or even proprietary --- without being required to release the source code of your own applications.
153-
However, any modifications to the library itself are required to be published for free under the same LGPLv3+ license.
193+
However, any modifications to the library itself are required to be published for free under the same LGPLv3+ license.
194+
195+
.. _Bug Report: https://github.com/pyrogram/pyrogram/issues/new?labels=bug&template=bug_report.md
196+
.. _Feature Request: https://github.com/pyrogram/pyrogram/issues/new?labels=enhancement&template=feature_request.md

docs/source/topics/glossary.rst

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ Pyrogram Glossary
22
-----------------
33

44
This page contains a list of common words with brief explanations related to Pyrogram and, to some extent, Telegram in
5-
general.
5+
general. Some words may as well link to dedicated articles in case the topic is covered in a more detailed fashion.
6+
7+
.. tip::
8+
9+
If you think something interesting could be added here, feel free to propose it by opening a `Feature Request`_.
10+
611

712
.. glossary::
813

@@ -14,6 +19,18 @@ general.
1419
A secret code used to authenticate and/or authorize a specific application to Telegram in order for it to
1520
control how the API is being used, for example, to prevent abuses of the API.
1621

22+
DC
23+
Also known as *data center*, is a place where lots of computer systems are housed and used together in order to
24+
achieve high quality and availability for services.
25+
26+
RPC
27+
Acronym for Remote Procedure call, that is, a function which gets executed at some remote place (i.e. Telegram
28+
server) and not in your local.
29+
30+
RPCError
31+
An error caused by an RPC which must be returned in place of the successful result in order to let the caller
32+
know something went wrong.
33+
1734
MTProto
1835
The name of the custom-made, open encryption protocol by Telegram, implemented in Pyrogram.
1936

@@ -50,4 +67,6 @@ general.
5067
Decorators in Pyrogram are used to automatically register callback functions for `handling updates`_.
5168

5269
.. _Telegram Bot API: https://core.telegram.org/bots/api
53-
.. _handling updates: ../start/updates
70+
.. _handling updates: ../start/updates
71+
72+
.. _Feature Request: https://github.com/pyrogram/pyrogram/issues/new?labels=enhancement&template=feature_request.md

0 commit comments

Comments
 (0)