Telegram MTProto protocol implementation
Project description
pyMTProto
This is a Telegram MTProto protocol library inspired by h11.
This library implements the following MTProto transports:
- Abridged
- Intermediate
- Padded Intermediate
- Full
- Obfuscated versions of all above (except Full)
Installation
pip install mtproto
Note that in order to use obfuscated transports or encrypt/decrypt mtproto messages, you MUST specify at least one (if you install both, only tgcrypto will be used) a crypto library in square brackets (currently tgcrypto and pyaes are supported):
pip install mtproto[tgcrypto]
or
pip install mtproto[pyaes]
Usage
from os import urandom
from mtproto import Connection, ConnectionRole
from mtproto.transports import IntermediateTransport
from mtproto.packets import UnencryptedMessagePacket
conn = Connection(
ConnectionRole.CLIENT,
# Transport class to use, supported: AbridgedTransport, IntermediateTransport, PaddedIntermediateTransport, FullTransport
# Default is AbridgedTransport. You need to specify transport class only if you are using ConnectionRole.CLIENT role.
transport_cls=IntermediateTransport,
# Whether to use transport obfuscation or not. Default is False. Obfuscation for FullTransport is not supported now.
transport_obf=False,
)
to_send = conn.send(UnencryptedMessagePacket(
message_id=123456789,
message_data=b"\xbe\x7e\x8e\xf1"[::-1] + urandom(16) # req_pq_multi#be7e8ef1 nonce:int128
))
# Send data to telegram server
...
# Receive data from telegram server
received = ...
packet = conn.receive(received)
print(packet)
# UnencryptedMessagePacket(message_id=..., message_data=b"...")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mtproto-0.2.2.tar.gz.
File metadata
- Download URL: mtproto-0.2.2.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.14.3 Linux/6.19.6-200.fc43.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bc133efe7015ce6d7c5fa451d13137328205c2f87348f22d1f1ff594d409f5a
|
|
| MD5 |
a01880e089187a01e28d373505b47b30
|
|
| BLAKE2b-256 |
8a16a75d9b6c5803eae99a1ecb858b29cf2f448686438d113bb8199c4333d941
|
File details
Details for the file mtproto-0.2.2-py3-none-any.whl.
File metadata
- Download URL: mtproto-0.2.2-py3-none-any.whl
- Upload date:
- Size: 34.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.14.3 Linux/6.19.6-200.fc43.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3826e25b5158e34b14e7d66bd307542a977d07d274ee5ae6455286a9651484c9
|
|
| MD5 |
b939ba9300f19a86f69f33b03162eec6
|
|
| BLAKE2b-256 |
cf9fdf7032233dc185a93ff609e71351589c003c73b4c7ce0408795dd48c89fb
|