Skip to main content

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

  1. Transport — TCP connect, send 0xef (abridged mode)
  2. Handshakereq_pq_multiresPQ → factorize pq → req_DH_paramsserver_DH_params_okset_client_DH_paramsdh_gen_ok
  3. Auth key — 256-byte shared secret saved to session file
  4. 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 key
  • server_salt — 8-byte server salt
  • user_id — logged-in user ID
  • access_hashes — cached peer access hashes for messaging

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

teleuz-0.3.1.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

teleuz-0.3.1-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

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

Hashes for teleuz-0.3.1.tar.gz
Algorithm Hash digest
SHA256 dc03838433285218a2e44369e61cd4c8c5d75fa5b2db4dfe0bdbbba285768806
MD5 221c0f3bfe1592dfb0bb08de036dfb90
BLAKE2b-256 050bda12858d50f18794f483b629793194a81c172490437f9e17a4dcca58feaf

See more details on using hashes here.

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

Hashes for teleuz-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5212145fbf3e4a575c7fd4245233a039f3986d811b079e27ed1475093245a7bf
MD5 a0520d8a9a422141b392718db52cec82
BLAKE2b-256 884842236e2cccc358e16afac385b31ae90e158c82b29b75a050f81731abb846

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