User:Lonami/sandbox
Developer(s) | Lonami |
---|---|
Initial release | August 26, 2016 |
Stable release | 0.15.1
/ October 5, 2017[1] |
Written in | Python |
Operating system | Cross-platform |
Type | Software framework |
License | MIT License |
Website | github |
Telethon is a framework written purely in Python to interact with Telegram's API. It is MIT licensed.
The latest stable version of Telethon is 0.15.1 as of October 2017[2].
The library itself does not require other particular tools or libraries to be installed, besides Python itself and some other Python-based modules, and allows the user to interact with Telegram's API in the lowest level possible (through the use of "requests"), or with the use of some of the built-in abstractions the library features for an easier use.
One can easily extend the functionality of the library for easier use by overriding the central TelegramClient
class.
History
[edit]In 2016, Lonami had tried enhancing TLSharp to integrate automatically generated code that would implement all the types and requests defined in Telegram's Type Language, but the maintainer of the project refused to merge his work due to a misunderstanding of what the code exactly did, and Lonami eventually gave up to work on his own implementation. Later on, Afshin Arani made another pull request that finally got merged, and although he presumes he wrote the code generator, this hasn't been proven.
Some time later, Lonami moved to GNU Linux based distribution and started working with Python. Eventually, his own implementation turned to be written in Python, and the library was born.
Despite the lack of a major release, the stability of the library has been increasing and gaining more features with every release.
Features
[edit]- Uses the latest version of Telegram's API[3]
- Full access to all the available requests and types
- Built-in abstraction for common tasks
- Easy to set up as a script or scheduled task
- No dependendencies outside of Python
- Update dispatching through a variable amount of workers
Example
[edit]The following source code shows how to login and send a message to yourself on Telegram:
from telethon import TelegramClient
api_id = 12345
api_hash = '0123456789abcdef0123456789abcdef'
client = TelegramClient('session_name', api_id, api_hash)
client.connect()
client.sign_in(phone='+34600000000')
me = client.sign_in(code=input('Enter code: ')
client.send_message(me, 'Hello World!')
External links
[edit]
- ^ https://pypi.python.org/pypi/Telethon
- ^ "PyPI Telethon". Python Package Index. 2017-10-05. Retrieved 2016-09-18.
- ^ Although Telegram doesn't update the official documentation, the latest scheme can be found on https://github.com/telegramdesktop/tdesktop/blob/dev/Telegram/Resources/scheme.tl