Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mtproto-0.2.2.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mtproto-0.2.2-py3-none-any.whl (34.3 kB view details)

Uploaded Python 3

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

Hashes for mtproto-0.2.2.tar.gz
Algorithm Hash digest
SHA256 5bc133efe7015ce6d7c5fa451d13137328205c2f87348f22d1f1ff594d409f5a
MD5 a01880e089187a01e28d373505b47b30
BLAKE2b-256 8a16a75d9b6c5803eae99a1ecb858b29cf2f448686438d113bb8199c4333d941

See more details on using hashes here.

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

Hashes for mtproto-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3826e25b5158e34b14e7d66bd307542a977d07d274ee5ae6455286a9651484c9
MD5 b939ba9300f19a86f69f33b03162eec6
BLAKE2b-256 cf9fdf7032233dc185a93ff609e71351589c003c73b4c7ce0408795dd48c89fb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page