Metadata-Version: 2.4
Name: mtproto
Version: 0.3.1
Summary: Telegram MTProto protocol implementation
Author-email: RuslanUC <dev_ruslan_uc@protonmail.com>
License-Expression: MIT
Project-URL: homepage, https://github.com/RuslanUC/mtproto
Project-URL: repository, https://github.com/RuslanUC/mtproto
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Classifier: Topic :: Internet
Classifier: Topic :: Utilities
Requires-Python: <4.0,>=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: tgcrypto
Requires-Dist: tgcrypto<2.0,>=1.2.5; extra == "tgcrypto"
Provides-Extra: pyaes
Requires-Dist: pyaes<2.0,>=1.6.1; extra == "pyaes"
Provides-Extra: http
Requires-Dist: h11<1.0,>=0.16.0; extra == "http"
Provides-Extra: ws
Requires-Dist: h11<1.0,>=0.16.0; extra == "ws"
Requires-Dist: wsproto<2.0,>=1.3.2; extra == "ws"
Dynamic: license-file

# pyMTProto

This is a Telegram MTProto protocol library inspired by [h11](https://github.com/python-hyper/h11).

This library implements the following MTProto transports:
- Abridged
- Intermediate
- Padded Intermediate
- Obfuscated versions of all above
- Full
- HTTP
- Websocket

Also, this library has WIP "bring-your-own-I/O" implementation of the session layer or MTProto protocol.

## Installation

```shell
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) 
crypto library in square brackets (currently `tgcrypto` and `pyaes` are supported):

```shell
pip install mtproto[tgcrypto]
# or
pip install mtproto[pyaes]
```

To use http or websocket transport, you'd need to install `http` or ws `extra`:
```shell
pip install mtproto[http]
# or
pip install mtproto[ws]
```

## Usage
```python
from os import urandom

from mtproto import ConnectionRole
from mtproto.transport import Connection
from mtproto.transport import IntermediateTransport
from mtproto.transport.packets import UnencryptedMessagePacket

conn = Connection(
    ConnectionRole.CLIENT,
    # Transport class to use, supported: 
    #  AbridgedTransport, IntermediateTransport, PaddedIntermediateTransport, FullTransport, HttpTransport, WsTransport
    # Default is AbridgedTransport. You need to specify transport class only if you are using ConnectionRole.CLIENT role.
    #  When role is ConnectionRole.SERVER, transport is ignored
    transport=IntermediateTransport,
    # Whether to use transport obfuscation or not. Default is False. Obfuscation for FullTransport is not supported now. 
    obfuscated=True,
)

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 = ...
conn.data_received(received)
packet = conn.next_event()

print(packet)
# UnencryptedMessagePacket(message_id=..., message_data=b"...")
```
