Skip to main content

A Python Telegram API Library for converting between tdata and telethon sessions, with built-in official Telegram APIs.

Project description

opentele

Fork of thedemons/opentele with Python 3.13 compatibility, updated device spoofing and QR Code login.

logo

pypi version pypi status documentation workflow tests issues github last commit github commits pypi installs pypi license code format


A Python Telegram API Library for converting between tdata and telethon sessions, with built-in official Telegram APIs. Read the documentation.


What's changed from the original

Python 3.13 compatibility

  • Fixed crossDelete in utils.py to handle new dunder attributes introduced in Python 3.13 (__firstlineno__, __static_attributes__, __dict__, __weakref__, __qualname__)
  • Fixed _on_login calls in tl/telethon.py that broke under Python 3.13's coroutine handling
  • Removed deprecated TDesktop storage keys (customEmoji, searchSuggestions, webviewTokens) that caused parsing errors with recent tdata versions

QR Code login

  • Added a new session creation method via QR Code scan, no need to convert tdata or existing session files
  • The app generates a QR code in the terminal, the user scans it from the official Telegram app on their phone, and the session is authorized automatically
  • Supports 2FA (two-factor authentication) if enabled on the account

Updated device spoofing logic

  • Replaced the hardcoded device list with a structured system that maps real Android SDK versions to devices that officially support that version
  • Each Android version (Android 13/SDK 33, Android 14/SDK 34, Android 15/SDK 35) is mapped to real devices that were officially released or updated to that version
  • Updated app version from 8.4.1 to 12.5.1 to match current official Telegram Android
  • Added DeviceInfo.to_dict() and DeviceInfo.from_dict() methods for serialization
  • Added ResolveDevice() method that allows passing a specific device instead of always randomizing

Other changes

  • Changed isinstance check to type() comparison in APIData.__eq__ to avoid false positives with subclasses

Platform support

Platform Status
Linux ✅ Tested on Python 3.13

Features

Dependencies

  • telethon - Widely used Telegram's API library for Python.
  • tgcrypto - AES-256-IGE encryption to works with tdata.
  • pyQt5 - Used by Telegram Desktop to streams data from files.
  • qrcode - QR code generation for terminal-based login.

⚠️ Warning

This tool uses Telegram's official authentication. It must be properly configured.

The following actions may cause Telegram to freeze your accounts:

  • Manually defining API_ID and API_HASH (the tool already manages these)
  • Making rapid or repeated authentication attempts
  • Using a different connection method or device than the one used to create the session
  • Mixing different Telegram clients or libraries
  • Logging in with multiple accounts from the same IP address or device
  • Using new virtual numbers or numbers with no prior activity

Notes:

  • If you created a session with an official device (e.g., Android), you must continue using that same method for that session
  • Using your own API_ID and API_HASH may cause authentication inconsistencies

Installation

  • Install from PyPI:
pip install --upgrade opentele

First Run

Load TDesktop from tdata folder and convert it to telethon, with a custom API:

from opentele.td import TDesktop
from opentele.tl import TelegramClient
from opentele.api import API, CreateNewSession, UseCurrentSession
import asyncio

async def main():
    
    # Load TDesktop client from tdata folder
    tdataFolder = r"C:\Users\<username>\AppData\Roaming\Telegram Desktop\tdata"
    tdesk = TDesktop(tdataFolder)

    # Using official iOS API with randomly generated device info
    # print(api) to see more
    api = API.TelegramIOS.Generate()

    # Convert TDesktop session to telethon client
    # CreateNewSession flag will use the current existing session to
    # authorize the new client by `Login via QR code`.
    client = await tdesk.ToTelethon("newSession.session", CreateNewSession, api)

    # Although Telegram Desktop doesn't let you authorize other
    # sessions via QR Code (or it doesn't have that feature),
    # it is still available across all platforms (APIs).

    # Connect and print all logged in devices
    await client.connect()
    await client.PrintSessions()

asyncio.run(main())

QR Code Login (New)

Create a session by scanning a QR code from the official Telegram app. No tdata or session file conversion needed.

from opentele.tl import TelegramClient
from opentele.api import API
from telethon.errors import SessionPasswordNeededError
from getpass import getpass
import qrcode
import asyncio
import os

async def main():
    os.makedirs("sessions", exist_ok=True)
    session_path = "sessions/my_account.session"
    api = API.TelegramAndroid.Generate(unique_id=session_path)
    client = TelegramClient(session_path, api=api)

    await client.connect()

    if await client.is_user_authorized():
        print("Session already authorized.")
        await client.disconnect()
        return

    qr_login = await client.qr_login()

    # Generates a QR code in the terminal
    qr = qrcode.QRCode(border=1)
    qr.add_data(qr_login.url)
    qr.make(fit=True)
    print("\nScan this QR from Telegram on your phone:\n")
    qr.print_ascii(invert=True)

    try:
        await qr_login.wait()
    except SessionPasswordNeededError:
        password = getpass("2FA Password: ")
        await client.sign_in(password=password)

    if await client.is_user_authorized():
        print("Session created successfully.")
        me = await client.get_me()
        if me:
            print(f"User: {me.id} | {me.first_name}")
        await client.PrintSessions()
    else:
        print("Could not authorize the session.")

    await client.disconnect()

asyncio.run(main())

Note: Requires qrcode package: pip install qrcode

Authorization

opentele offers the ability to use official APIs, which are used by official apps. You can check that out here.

According to Telegram TOS: all accounts that sign up or log in using unofficial Telegram API clients are automatically put under observation to avoid violations of the Terms of Service.

It also uses the lang_pack parameter, of which telethon can't use because it's for official apps only.
Therefore, there are no differences between using opentele and official apps, the server can't tell you apart.

Incoming Features

  • Writing data to tdata for converting telethon sessions to tdesktop.
  • Random device information for initConnection to avoid spam-detection.
  • QR Code login without tdata or session conversion.
  • Add support for pyrogram.
  • Develop opentele-tui using textual for non-experience user.

Examples

The best way to learn anything is by looking at the examples. Am I right?

Documentation documentation

  • Read documentation on readthedocs

  • Read documentation on github

  • Usa siempre el cliente proporcionado por esta librería (opentele)

Úsala bajo tu propia responsabilidad.


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

opentele_tg-1.15.3.tar.gz (56.0 kB view details)

Uploaded Source

Built Distribution

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

opentele_tg-1.15.3-py3-none-any.whl (61.4 kB view details)

Uploaded Python 3

File details

Details for the file opentele_tg-1.15.3.tar.gz.

File metadata

  • Download URL: opentele_tg-1.15.3.tar.gz
  • Upload date:
  • Size: 56.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for opentele_tg-1.15.3.tar.gz
Algorithm Hash digest
SHA256 423e7ed2d87b61f2e9ebb84f6744e1bfee8338da53d2c7313bf5a4568cf9be80
MD5 f4dd17df60e3b4354e5f0d69c98ad156
BLAKE2b-256 05b52092c5fa9f17d62b3f0eab036e59e5a69e5d77a46f25c602154a0b20ddc2

See more details on using hashes here.

File details

Details for the file opentele_tg-1.15.3-py3-none-any.whl.

File metadata

  • Download URL: opentele_tg-1.15.3-py3-none-any.whl
  • Upload date:
  • Size: 61.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for opentele_tg-1.15.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6afef3a711403dc0c2efde986dc3cd50efa7714686164d6c41729fcbc239b432
MD5 0170f08b50cfd9c9f048eb680cdea759
BLAKE2b-256 54f2f8b019d16c83b3d4cf8b7585c10e30a68bc02d9e0c6e91e99af0b6f4a911

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