Pure-Python asyncio Telegram MTProto client library
Project description
TeleUz
Pure-Python asyncio Telegram client implementing MTProto from scratch.
No Telethon, Pyrogram, TDLib, or MadelineProto — only cryptography and rsa for crypto primitives.
Installation
pip install -e .
Quick start
import asyncio
from teleuz import Client
async def main():
client = Client(
api_id=12345,
api_hash="YOUR_API_HASH",
session_path="my.session",
)
await client.connect()
await client.login(phone="+123456789")
message_id = await client.send_message(
user_id=123456789,
message="Hello from TeleUz",
)
print(f"Sent message id: {message_id}")
await client.disconnect()
asyncio.run(main())
Interactive login test
Telethon uslubidagi prompt bilan tekshirish:
python teleuz_test_login.py
Skript quyidagilarni ketma-ket so'raydi:
- API ID
- API hash
- telefon raqam
- SMS/Telegram kod
- agar kerak bo'lsa 2FA parol
Va keyin 8296599550 ID ga TeleUz orqali yuborildi xabarini yuborishga urinadi.
Architecture
teleuz/
├── client.py # High-level async client
├── session.py # JSON session persistence
├── transport/
│ └── abridged.py # MTProto abridged TCP transport
├── mtproto/
│ ├── auth.py # req_pq_multi
│ ├── requests.py # Handshake request builders
│ ├── respq.py # resPQ parser
│ ├── dh_exchange.py # DH key exchange (req_DH_params, set_client_DH_params)
│ ├── message.py # Unencrypted message framing
│ └── encrypted.py # MTProto 2.0 AES-IGE encryption
├── crypto/
│ ├── aes_ige.py # AES-IGE mode
│ ├── dh.py # Diffie-Hellman
│ ├── factorization.py# Pollard's rho for pq factorization
│ ├── kdf.py # MTProto 2.0 key derivation
│ ├── keys.py # Telegram RSA public keys
│ └── nonce.py # Nonce generation
└── tl/
├── primitives.py # TL serializers (int32, bytes, vectors)
├── schema.py # API method serializers
└── parser.py # Response deserializers
Protocol flow
- Transport — TCP connect, send
0xef(abridged mode) - Handshake —
req_pq_multi→resPQ→ factorize pq →req_DH_params→server_DH_params_ok→set_client_DH_params→dh_gen_ok - Auth key — 256-byte shared secret saved to session file
- Encrypted RPC — AES-IGE encrypted
auth.sendCode/auth.signIn/messages.sendMessage
Session file
Sessions are stored as JSON (teleuz.session by default):
auth_key— 256-byte MTProto authorization keyserver_salt— 8-byte server saltuser_id— logged-in user IDaccess_hashes— cached peer access hashes for messaging
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 teleuz-0.3.1.tar.gz.
File metadata
- Download URL: teleuz-0.3.1.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc03838433285218a2e44369e61cd4c8c5d75fa5b2db4dfe0bdbbba285768806
|
|
| MD5 |
221c0f3bfe1592dfb0bb08de036dfb90
|
|
| BLAKE2b-256 |
050bda12858d50f18794f483b629793194a81c172490437f9e17a4dcca58feaf
|
File details
Details for the file teleuz-0.3.1-py3-none-any.whl.
File metadata
- Download URL: teleuz-0.3.1-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5212145fbf3e4a575c7fd4245233a039f3986d811b079e27ed1475093245a7bf
|
|
| MD5 |
a0520d8a9a422141b392718db52cec82
|
|
| BLAKE2b-256 |
884842236e2cccc358e16afac385b31ae90e158c82b29b75a050f81731abb846
|