mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-24 15:59:18 +00:00
538f1e3972
- Pyrogram core is now fully asynchronous - Ditched Python 3.5, welcome 3.6 as minimum version. - Moved all types to pyrogram.types - Turned the Filters class into a module (filters) - Moved all filters to pyrogram.filters - Moved all handlers to pyrogram.handlers - Moved all emoji to pyrogram.emoji - Renamed pyrogram.api to pyrogram.raw - Clock is now synced with server's time - Telegram schema updated to Layer 117 - Greatly improved the TL compiler (proper type-constructor hierarchy) - Added "do not edit" warning in generated files - Crypto parts are executed in a thread pool to avoid blocking the event loop - idle() is now a separate function (it doesn't deal with Client instances) - Async storage, async filters and async progress callback (optional, can be sync too) - Added getpass back, for hidden password inputs
59 lines
1.9 KiB
ReStructuredText
59 lines
1.9 KiB
ReStructuredText
Object Serialization
|
|
====================
|
|
|
|
Serializing means converting a Pyrogram object, which exists as Python class instance, to a text string that can be
|
|
easily shared and stored anywhere. Pyrogram provides two formats for serializing its objects: one good looking for
|
|
humans and another more compact for machines that is able to recover the original structures.
|
|
|
|
.. contents:: Contents
|
|
:backlinks: none
|
|
:depth: 1
|
|
:local:
|
|
|
|
-----
|
|
|
|
For Humans - str(obj)
|
|
---------------------
|
|
|
|
If you want a nicely formatted, human readable JSON representation of any object in the API -- namely, any object from
|
|
:doc:`Pyrogram types <../api/types/index>`, :doc:`raw functions <../telegram/functions/index>` and
|
|
:doc:`raw types <../telegram/types/index>` -- you can use ``str(obj)``.
|
|
|
|
.. code-block:: python
|
|
|
|
...
|
|
|
|
with app:
|
|
r = app.get_chat("haskell")
|
|
|
|
print(str(r))
|
|
|
|
.. tip::
|
|
|
|
When using ``print()`` you don't actually need to use ``str()`` on the object because it is called automatically, we
|
|
have done that above just to show you how to explicitly convert a Pyrogram object to JSON.
|
|
|
|
For Machines - repr(obj)
|
|
------------------------
|
|
|
|
If you want to share or store objects for future references in a more compact way, you can use ``repr(obj)``. While
|
|
still pretty much readable, this format is not intended for humans. The advantage of this format is that once you
|
|
serialize your object, you can use ``eval()`` to get back the original structure; just make sure to ``import pyrogram``,
|
|
as the process requires the package to be in scope.
|
|
|
|
.. code-block:: python
|
|
|
|
import pyrogram
|
|
|
|
...
|
|
|
|
with app:
|
|
r = app.get_chat("haskell")
|
|
|
|
print(repr(r))
|
|
print(eval(repr(r)) == r) # True
|
|
|
|
.. note::
|
|
|
|
Type definitions are subject to changes between versions. You should make sure to store and load objects using the
|
|
same Pyrogram version. |