2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-09-01 06:45:39 +00:00

Rename folder

This commit is contained in:
Dan
2018-02-08 16:24:28 +01:00
parent a7dd753ec5
commit 077eb386de
3 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
Basic Usage
===========
.. note::
All the snippets below assume you have successfully created and started a :obj:`pyrogram.Client` instance.
You also must be authorized, that is, a valid *.session file does exist in your working directory.
Simple API Access
-----------------
The easiest way to interact with the API is via the :obj:`pyrogram.Client` class which exposes bot-like_ methods.
The purpose of this Client class is to make it even simpler to work with Telegram's API by abstracting the
raw functions listed in the API scheme.
The result is a much cleaner interface that allows you to:
- Get information about the authorized user:
.. code-block:: python
print(client.get_me())
- Send a message to yourself (Saved Messages):
.. code-block:: python
client.send_message(
chat_id="me",
text="Hi there! I'm using Pyrogram"
)
.. seealso:: For a complete list of the available methods have a look at the :obj:`pyrogram.Client` class.
.. _using-raw-functions:
Using Raw Functions
-------------------
If you want **complete**, low-level access to the Telegram API you have to use the raw
:obj:`functions <pyrogram.api.functions>` and :obj:`types <pyrogram.api.types>` exposed by the ``pyrogram.api``
package and call any Telegram API method you wish using the :obj:`send <pyrogram.Client.send>` method provided by
the Client class.
Here some examples:
- Update first name, last name and bio:
.. code-block:: python
from pyrogram.api import functions
client.send(
functions.account.UpdateProfile(
first_name="Dan", last_name="Tès",
about="Bio written from Pyrogram"
)
)
- Share your Last Seen time only with your contacts:
.. code-block:: python
from pyrogram.api import functions, types
client.send(
functions.account.SetPrivacy(
key=types.InputPrivacyKeyStatusTimestamp(),
rules=[types.InputPrivacyValueAllowContacts()]
)
)
.. _bot-like: https://core.telegram.org/bots/api#available-methods

View File

@@ -0,0 +1,66 @@
Project Setup
=============
This section provides all the information you need to setup your project with Pyrogram.
There are a few steps you have to follow before you can actually use the library to make API calls.
API Keys
--------
The very first step requires you to obtain a valid Telegram API key.
If you already have one you can skip this, 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**
.. important:: This key should be kept secret.
Configuration
-------------
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>`_:
.. code-block:: ini
[pyrogram]
api_id = 12345
api_hash = 0123456789abcdef0123456789abcdef
Authorization
-------------
Telegram requires that users be authorized in order to use the API.
Pyrogram automatically manages this access, all you need to do is create an instance of
the :class:`pyrogram.Client` class by passing to it a ``<session_name>`` of your choice
and call the :obj:`start <pyrogram.Client.start>` method:
.. code-block:: python
from pyrogram import Client
client = Client(session_name="example")
client.start()
This starts an interactive shell asking you to input your **phone number** (including your `Country Code`_)
and the **phone code** you will receive:
.. code::
Enter phone number: +39**********
Is "+39**********" correct? (y/n): y
Enter phone code: 32768
After successfully authorizing yourself, a new file called ``example.session`` will be created allowing
Pyrogram executing API calls with your identity.
.. important:: Your *.session file(s) must be kept secret.
.. note::
The authorization process is executed only once.
However, the code above is always required; as long as a valid session file exists,
Pyrogram will use that and won't ask you to enter your phone number again when you restart your script.
.. _`Country Code`: https://en.wikipedia.org/wiki/List_of_country_calling_codes

View File

@@ -0,0 +1,41 @@
Quick Installation
==================
The most straightforward and recommended way to install or upgrade Pyrogram is by using **pip**:
.. code-block:: bash
$ pip install --upgrade pyrogram
.. important::
Pyrogram only works on Python 3.3 or higher; if your **pip** points to Python 2.x use **pip3** instead.
Bleeding Edge
-------------
If you want the latest development version of the library, you can either install it automatically with:
.. code-block:: bash
$ pip install --upgrade git+https://github.com/pyrogram/pyrogram.git
or manually, using:
.. code-block:: bash
$ git clone https://github.com/pyrogram/pyrogram.git
$ cd pyrogram
$ python setup.py install
Verifying
---------
To verify that Pyrogram is correctly installed, open a Python shell and try to import it.
If no errors show up you are good to go.
.. code-block:: bash
>>> import pyrogram
>>> pyrogram.__version__
'0.4.2'