Pyrogram Versions Save

Elegant, modern and asynchronous Telegram MTProto API framework in Python for users and bots

v0.15.1

4 years ago

New Features and Enhancements

  • API schema updated to Layer 102.

  • TgCrypto updated to v1.2.0.

  • Goodbye JSON-based session files, you served very well, but is now time for Storage Engines. This version brings two built-in implementations based on SQLite: File Storage and Memory Storage. Extra storage engines for different storage options (such as Redis, MySQL, MongoDB, ...) can be easily implemented as well. (proposal by @bakatrouble, which provided an implementation in #220 that got refactored).

  • Added export_session_string() method to export a session string. Session strings are useful when you want to run authorized Pyrogram clients completely in-memory on platforms like Heroku, where their ephemeral filesystems makes it much harder for a file-based storage engine to properly work as intended.

  • Text Formatting re-done from scratch. You can now style message texts and captions using extra styles like underline and strikethrough styles, in both Markdown and HTML. You can nest and combine multiple styles together on the same text too, such as in this example (bold, italic and strikethrough text) and also disable the parser completely by passing None as argument to the parse_mode parameter.

  • Added archive_chats() and unarchive_chats() methods to archive and unarchive your chats.

  • Added archive() and unarchive() bound methods to User and Chat types as convenience shortcuts for archive_chats() and unarchive_chats().

  • Added new methods to edit messages sent by inline bots: edit_inline_text(), edit_inline_caption(), edit_inline_media() and edit_inline_reply_markup(). The reason behind having 4+4 methods for editing normal messages and messages sent by inline bots is because of Telegram requiring a special inline_message_id that is mutually exclusive with the usual pair of chat_id+message_id.

  • Added new CallbackQuery bound-methods for editing messages: edit_message_text(), edit_message_caption(), edit_message_media() and edit_message_reply_markup().

  • Added friendly methods to block and unblock users: block_user() and unblock_user() (contributed by @ColinTheShark in #256).

  • Added new Chat bound-methods: set_title(), set_description(), set_photo(), kick_member(), unban_member(), restrict_member() and promote_member() (contributed by @mendelmaleh in #260).

  • Added some new FAQs about: DC migration, DC IP addresses, library stability and reliability.

  • Added a bunch of new errors: FOLDER_DEAC_AUTOFIX_ALL, FOLDER_ID_INVALID, MEGAGROUP_PREHISTORY_HIDDEN, CHAT_LINK_EXISTS, LINK_NOT_MODIFIED, BROADCAST_ID_INVALID and MEGAGROUP_ID_INVALID, START_PARAM_INVALID, MSGID_DECREASE_RETRY.

  • Removed Messages, ChatMembers, Dialogs, ProfilePhotos and GameHighScores types. These types were just annoying wrappers around bare lists and removing them means that now you get a simple list of objects:

    • Messages → List of Message objects.
    • ChatMembers → List of ChatMember objects.
    • Dialogs → List of Dialog objects.
    • ProfilePhotos → List of Photo objects.
    • GameHighScores → List of GameHighScore objects.

    Dealing with methods which returned such types has also become easier. Instead of doing the following:

    history = app.get_history("pyrogramchat")
    print(history.messages[0])
    

    you can omit .messages because the returned type is a simple list:

    history = app.get_history("pyrogramchat")
    print(history[0])
    

    To get the total count of items each old type contained, you have to use the respective methods: get_history_count(), get_chat_members_count(), get_dialogs_count(), get_profile_photos_count().

  • Unknown errors with known error codes are now raised by their category error instead of 520 UnknownError. For example, an unknown error that has the known error code 400 will be raised as BadRequest. Totally unknown errors (with both unknown message and error code) will still be raised as UnknownError.

  • Error messages now contain information about which raw method caused the RPC error. For example: [400 MESSAGE_EMPTY]: The message sent is empty (caused by "messages.SendMessage").

Bug Fixes

  • Fixed get_profile_photos() method not working when passing me or self as argument.

  • Fixed plugins not getting reloaded properly when restarting a client.

  • Fixed download_media() ignoring the file_name argument which also lead to files being saved with random names generated by the framework.

  • Fixed script executions not working outside the current directory (addressed #41).

  • Fixed texts being sliced incorrectly when trying to use the offsets and lengths from message entities.

  • Fixed delete_profile_photos() not working since that last update (addressed #259).

  • Fixed objects failing to print in case there's no __slots__ attribute.

Breaking Changes

  • ChatMembers, Dialogs, ProfilePhotos, Messages and GameHighScores types are now gone and replaced with simple lists of objects (as explained in the section above).

  • The name argument of Filters.create() is now optional and moved behind. The simplest custom filter you can create will now look like this: flt = Filters.create(lambda _, m: ...).

v0.14.1

4 years ago

New Features

  • API Schema updated to Layer 100.
  • Pyrogram is now able to handle message floods without slowing down. While there's still a lot of room for extra performance, thanks to the community and in particular to @Talocan who helped with load tests, I was able to fix this major bottleneck which would have slowed down the library in case of huge amount of messages received - we are talking about 50-80 messages per second, which is quite a lot for a single user/bot to handle.
  • Added get_user_dc() to get a user's assigned DC (Data Center).
  • Added read_history() to read (marking as read, double-tick) a chat history.
  • Added Filters.callback_data to filter callback query data (contributed by @ColinTheShark in #248 ).
  • Added send_animated_sticker() to send the new Telegram animated stickers in .tgs format. Note: this is still an experimental feature, not even all official clients properly support animated stickers and Telegram has not announced anything yet about this new feature.
  • Added iter_profile_photos() to iterate over a user or a chat profile photos sequentially.
  • Added a new section in the documentation: Debugging and Release Notes.
  • Added new FAQs in the documentation.
  • Added easter eggs.

Enhancements

  • Added the unsave parameter to send_animation(). Pass True in order to remove the GIF animation from your own collection (the server automatically adds them).
  • Bare lists, such as [1, 2, 3, 4, 5] when coming from the Telegram raw API are now printed nicely.
  • The PhotoSize type has been replaced by Thumbnail, a much more interesting and useful name.
  • The Photo type has been revamped: forget message.photo.sizes[-1].file_id, you can now simply use message.photo.file_id to get the highest quality available, all the other sizes are kept as a list of thumbnails in the thumbs attribute.
  • All applicable media now have a thumbs attribute to store all the available thumbnails (there can be more than one, sorted by ascending size).
  • When printing Pyrogram objects, phone numbers are now hidden and each digit replaced with a star *. E.g. 391234567890************. Date attributes are shown as human-readable dates instead of a unix timestamps. E.g. 15597426282019-06-05 15:50:28. Note this is just a visual modification, when accessing the inner attributes, you will still get the same values (full number, unix timestamp).
  • get_profile_photos() and get_profile_photos_count() now work for both users and chats.
  • Chat and User types have new attributes:
    • is_verified
    • is_restricted
    • is_scam
    • is_support (user only).

Bug Fixes

Breaking Changes

v0.13.0

5 years ago

This version features a massive overhaul of the documentation structure and a shiny new domain name: https://pyrogram.org. After well over a week spent working solely on the documentation website, here's what's new:

That's all about the documentation, for now. I hope you enjoy it! Let's now go ahead with listing the new features this version brings in the library itself:

New Features

Enhancements

  • get_chat() method is now able to fetch the pinned message in your own chat (saved messages).
  • Increased media thumbnail size from 90px to 320px side length.
  • Added is_member attribute to the ChatMember type to check wether a restricted user is still a member of a chat.
  • Added back the automatic mime type detection for new uploads.
  • Sending and receiving callback_data (with inline buttons and callback query respectively) has gained back support for strings. If you pass strings for which you are 100% sure they will be valid UTF-8 texts, you can rely on the library reporting back string types, otherwise you'll get a bytes type. This is due to how Telegram handles callback queries data (only bytes allowed) and it's a matter of convenience to allow strings as well.
  • Added supports_streaming attribute to the Video type.
  • Hint about which client is loading which plugins folder when you start them.
  • Added a timeout parameter to Message.click()
  • Allowed Message.click() to be called without any argument for clicking the first button.

Bug Fixes

  • Method delete_messages() and Message.delete() will now return False in case they fail to delete (they used to always return True due to how Telegram handles this method; the server doesn't raise any error).
  • get_messages() is now able to get more than one reply using the replies parameter. Up to unlimited replies.

Breaking Changes

  • Method close_poll() was renamed to stop_poll().
  • Attribute forward_from_name of Message was renamed to forward_sender_name.
  • Poll ids are now strings and not integers.
  • ParseMode module was removed. It was pretty much useless, better just use "markdown" and "html" string literals.
  • ChatAction module was removed too, same reason of ParseMode.
  • Removed get_chat_preview() method, get_chat() will take care of both Chat and ChatPreview objects.

v0.12.0

5 years ago

New Features

Enhancements

  • Added Python __slots__ in every single type to help reduce the memory footprint.
  • The send_media_group() method will now return a Messages object.
  • Added a retry mechanism when uploading file chunks.
  • The get_contacts() method will now return a list of User objects.
  • Embedded an updated version of typing.py as an attempt to fix Python 3.5.0-3.5.2 issues.
  • All send_* methods dealing with media messages (audio, document, animation, etc...) will now always send the correct Telegram media kind, regardless of the uploaded file.
  • Keyboard buttons' texts are now automatically coerced to str.
  • The join_chat() method will now return a Chat object (contributed by @bakatrouble in #206).
  • Use a lower timeout when starting a session to speed up re-connections.
  • Updated the restrict_chat_member() method with new permissions and made it return a Chat object.
  • Printed object (e.g.: when using print(message)) will now display UTF-8 characters instead of ASCII representations of their code points.
  • You can now forward messages as copy with the new as_copy parameter in forward_messages() method and Message.forward() bound method (contributed by @bakatrouble in #227 ).
  • Added support for forwarded messages with hidden users; the new forward_from_name attribute of a Message will contain the user first name only (as string) of the author as opposed to a full User object.

Bug Fixes

  • Fixed a loss of thumbnails after editing media messages (contributed by @23rd in #216).
  • Fixed plugins not working under Windows because of broken paths (contributed by @bakatrouble in #223).
  • Fixed "ModuleNotFoundError is not defined" error for Python <3.6.
  • Fixed the get_chat_member() method not working when passing "me" in basic groups.
  • Fixed flood wait errors generated when iterating over basic chat members.
  • Fixed library not loading for Python 3.5.0-3.5.2 (contributed by @Bfaschat in #236).
  • Fixed set_chat_description() not working anymore after the new Layer update.

Breaking Changes

  • When using raw functions and types, you now must fill in the parameters using named arguments.
  • The errors package has been moved; it is now importable with from pyrogram import errors, and the Error exception has been renamed to RPCError.

v0.11.0

5 years ago

What's New

  • Smart Plugins revamp: you can now specify exactly which plugins to include or exclude and in which exact order to load each of them.
  • no_updates Client parameter. Pass True in order to completely disable incoming updates from Telegram. Useful in batch programs, for example, when you want to broadcast a message to many users and have no need to handle incoming messages or other updates whatsoever.
  • takeout Client parameter. Pass True in order to use a special takeout session instead of a normal one. Useful for exporting your Telegram data; methods invoked inside a takeout session (such as get_history, download_media, ...) are less prone to throw FloodWait exceptions.
  • Message and caption texts are now automatically casted to str. This makes possible to send objects that implement a string representation without having to manually cast, for example:
    • app.send_message(chat_id, 123456) sends "123456" (int) text message as string.
    • message.reply(message) replies with the message (Message) itself.
  • Filters.me, useful for filtering messages coming from you yourself. Does the same as Filters.user("me").
  • close_poll method for closing (stopping) polls.
  • New convenience methods to make iterating through entities such as history messages, dialogs and chat members easier: iter_history, iter_dialogs, iter_chat_members.
  • Game, GameHighScore and GameHighScores types for messages dealing with games, game and game_high_score attributes inside Message as well as Filters.game, Filters.game_score filters and send_game, set_game_score, get_game_high_scores methods.
  • It's now possible to recover the account while logging in, in case you forget your cloud password.
  • Client's arguments phone_number, password, first_name and last_name can now be callback functions.
  • Filters.regex now works on captions too.
  • New Filters.media_group for filtering photos or videos being part of an album.
  • New stop_transmission method useful to stop uploads and downloads.
  • New restart convenience method to automatically stop and start the Client.
  • The ChatMember type has been extended with extra attributes: date, inviter_by, promoted_by and restricted_by.
  • New Voice Calls page in documentation. Thanks to @bakatrouble for the working proof-of-concept.
  • A way to continue propagating the same update to the next handler within the same group with .continue_propagation() update's bound-method.
  • A bunch of new common Telegram errors regarding takeout sessions and poll messages.

Bug Fixes

  • Polls in Layer 91 were reporting a wrong id and in some cases they were also flagged as "closed" when they were in fact not. This is due to a small issue in the TL schema (which will eventually get fixed in the next Layer update by Telegram itself). Nevertheless, from now on Pyrogram will be able to generate the correct code even in case such issues happen again. Relevant commit: c7b1d6f70a97674fc59afc21b1334cd10f024b87
  • kick_chat_members and get_dialogs docstrings were reporting a wrong return type.
  • Handle develop installation for pip. Thanks @bakatrouble for the hint!
  • All raw updates that were not part of those for which a parser was implemented were being discarded and never passed to raw update handlers. #211

Breaking Changes

  • get_history's reversed parameter has been renamed to reverse because it was colliding with the built-in "reversed" function.

v0.10.3

5 years ago

Notice: Python 3.5.2 is bugged and breaks with Pyrogram. More info at https://t.me/PyrogramChat/49171

What's new

Bug Fixes

  • ChatMember parser was working on already parsed Users.
  • get_chat wasn't working properly in case you passed invite links of public channels/supergroups.

v0.10.2

5 years ago

Happy New Year 2019!

This last update of the year turns out to be the biggest ever made, featuring quite important internal changes – which worth mentioning – as well as lots of new additions. More updates will come in the future, such as the work-in-progress inline mode. Keep Pyrogramming!

Under the Hood

  • Refactored types: Pyrogram types have been rewritten from scratch using cleaner code which increases maintainability and readability and also allows future extensibility with ease.
  • Type hints: Pyrogram type and method parameters are now type hinted. This means that, with smart IDEs, whenever you try to access any Pyrogram object field you will be hinted about all the available options.

What's New

  • API schema updated to Layer 91.
  • Normal bots (created by BotFather) are now able to send messages to all the users who contacted them in the past anytime just by their IDs. Bots can also send messages to group chats and channels they are members of without having to manually kick and re-add them again. Thanks Manuel and TDLib devs in PyrogramLounge for suggesting this was possible!
  • Normal bots are now able to edit and delete their own messages via Message's bound methods .edit() and .delete().
  • New Message.web_page attribute for messages sent with web page previews. Note that support for web pages is still basic; a simple boolean is set in case the message contains a web page preview. In future versions this attribute could turn into a full web page object that contains more details. (contributed by @zeroone2numeral2 in #166).
  • New Filters.web_page to filter messages containing web page previews (contributed by @zeroone2numeral2 in #166).
  • New Filters.via_bot to filter messages coming from inline bots.
  • Client.start() and Client.stop() will now return the Client instance itself to make chaining possible.
  • Sticker packs are now automatically cached once they are retrieved for the first time. This change increases Message parsing performance a lot in case there are many stickers in a chat coming from the same pack.
  • First name of users/bots is now shown when logging in the first time.
  • It is now possible to recover password-protected accounts at login time (only if a password recovery e-mail was previously set) Thanks @hoolihoolihooli for testing with me in PyrogramChat.
  • New Poll and PollOption objects which represent the new native polls in Telegram among with send_poll, vote_poll and retract_vote methods to interact with polls and Filters.poll to filter messages containing polls.
  • Pin/unpin_chat_message method has been updated to work on basic groups and users' own private chats as well (previously working on channels and supergroups only).
  • New hide_via argument for send_inline_bot_result used to hide via @bot captions (currently doesn't work as official clients or the server itself seem to ignore this).
  • get_history is now able to return Messages in reversed (natural) order with the new reversed parameters set to True (contributed by @YoilyL in #94).
  • New get_chat_preview method, which can be used to get the preview of a chat you haven't joined yet by its invite link; the new ChatPreview object will be returned. get_chat has been modified as well to accept invite links of already joined chats. All other methods, such as send_message, still need the chat_id as integer to work in private groups and channels (you can take that from get_chat's result).
  • Many new common Telegram errors have been added.
  • Three new documentation sections: Test Servers, Advanced Usage and Changelog.
  • The future branch is now gone, all changes have been merged into the default develop branch, meaning this update contains all of them!

Bug Fixes

  • The raw update handler was handling parsed updates (contributed by @Jafte in #159).
  • Videos sent inside an album were ignoring the custom thumbnails.
  • download_media was not working properly in case of empty progress_args.
  • A download progress callback was always reporting 0 as current bytes in case of downloads from file ids.
  • Fixed a critical bug which caused random errors because of dicts not keeping keys order for Python <3.6.

Breaking Changes

  • Yet another subtle update that changes how current callback queries work: CallbackQuery.data type is now bytes instead of str, because of Telegram API actually allowing clients to send arbitrary bytes; forcing the decoding to turn bytes data into strings could lead to errors.
  • get_dialogs now expects an offset_date as integer instead of a Dialog chunk as offset.

v0.9.3

5 years ago

What's New

  • Pyrogram now uses TCPAbridgedO protocol by default. TCPAbridgedO is an Obfuscated packet-level protocol that helps bypass some DPI and thus allowing Pyrogram to work fine even in case your ISP is trying to block Telegram.
  • The Dispatcher has been reworked and optimized for better performance.
  • Message.mentioned field and Filters.mentioned filter useful for handling messages that contain mentions to you (contributed by @Furoin in #154).
  • Filters.chat and Filters.user can now accept "me" and "self" as arguments, thus enabling an easy way to filter yourself and your own chat (contributed by @Furoin in #155 and #157).
  • Message.download() bound method missing arguments are now added to match Client.download_media() (contributed by @VANKINEENITAWRUN in #156).
  • Message.edit() bound method to make message edits less verbose code-wise.
  • MESSAGE_DELETE_FORBIDDEN error.
  • Message.empty field to tell empty (deleted or non-existent) messages apart.
  • Message.service field and a more efficient Filters.service to tell service messages apart.
  • Message.media field and a more efficient Filters.media to tell media messages apart.
  • Decorators of different Client instances can now be stacked on top of the same callback function. E.g.:
    ...
    
    @app1.on_message(...)
    @app2.on_message(...)
    @app3.on_message(...)
    def on_message(client, message):
        ...
    

Bug Fixes

  • Fixed a rare MESSAGE_IDS_EMPTY error raised in case of a message replying to another was pinned and the replied message was deleted at the same time.

v0.9.1

5 years ago

Bug Fixes

  • Fix AttributeError: 'ChannelForbidden' object has no attribute 'restriction_reason'.
  • Fix MESSAGE_IDS_EMPTY error.
  • Fix UnicodeDecodeError raised by invalid UTF-8 data inside inline buttons callback data.
  • FIx ChatMember.total_count not being available when fetching members from supergroups and channels.

Breaking Changes

  • InlineKeyboardButton.callback_data type is now bytes instead of str in order to fix the bug above.

v0.9.0

5 years ago

What's New

  • A smart and lightweight Plugin System to seamlessly write and share pluggable Pyrogram components with minimal boilerplate code.
  • User.status field, UserStatus type and UserStatusHandler handler (with its own on_user_status decorator) for handling user status updates that arrive each time your contacts go online or offline.
  • User.restriction_reason and Chat.restriction_reason fields used to store the restriction reason of Bots, Supergroups and Channels.
  • Examples are now dedicated to the public domain under the CC0 1.0 Universal license and have also been updated using new methods and features.
  • set_user_profile_photo method for uploading new user profile photos.
  • You can now specify more than one prefix in Filters.command by passing a list of them.
  • It is now possible to use those "special" IPv4 proxies that only allow IPv6 connections to Telegram:
    Pyrogram     Proxy        Telegram
    [IPv4] <---> [IPv4]  -X-  [IPv4]
    [IPv6]  -X-  [IPv6] <---> [IPv6] 
    

Bug Fixes

  • Fixed handler groups that broke in case one of the registered handler raised an unhandled exception. Now, only the single handler will stop and Pyrogram will continue with the next handlers.
  • Fixed an annoying CHANNEL_PRIVATE error that flooded the console (not really a bug).
  • Fixed bots that weren't able to get other bot's messages in case of users mentioning them in groups.
  • Lots of other bug fixes and minor improvements to both code and documentation.

Breaking Changes

  • For consistency with other method names delete_profile_photos has been renamed to delete_user_profile_photos.
  • The keyword for installing TgCrypto as extra dependency when installing Pyrogram is now fast: pip3 install -U pyrogram[fast].