A Python Telegram API library based on the original OpenTele project by thedemons, 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.
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
crossDeleteinutils.pyto handle new dunder attributes introduced in Python 3.13 (__firstlineno__,__static_attributes__,__dict__,__weakref__,__qualname__) - Fixed
_on_logincalls intl/telethon.pythat 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.1to12.5.1to match current official Telegram Android - Added
DeviceInfo.to_dict()andDeviceInfo.from_dict()methods for serialization - Added
ResolveDevice()method that allows passing a specific device instead of always randomizing
Other changes
- Changed
isinstancecheck totype()comparison inAPIData.__eq__to avoid false positives with subclasses
Platform support
| Platform | Status |
|---|---|
| Linux | ✅ Tested on Python 3.13 |
NOTICE
Unfortunately, due to the lack of interest, I can no longer maintain this project and keep it up-to-date with the latest version of Telegram Desktop and Telethon.
If you have been using opentele for a while, I appreciate it, please consider contributing to the project, ask any questions in Discussion and I'll try to help.
Features
- Convert Telegram Desktop tdata sessions to telethon sessions and vice versa.
- Use telethon with official APIs to avoid bot detection.
- Randomize device info using real data that recognized by Telegram server.
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.
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
qrcodepackage: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?
- Example on readthedocs
- Example on github
Documentation 
- Read documentation on readthedocs
- Read documentation on github
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 opentele_tg-3.13.1.tar.gz.
File metadata
- Download URL: opentele_tg-3.13.1.tar.gz
- Upload date:
- Size: 55.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15a4489afb3458b9c3c087b6d8467c75ab4d052246d89239bd55509601aaaa21
|
|
| MD5 |
b09120bfb4d6f20887fcfd77b3a9c1ec
|
|
| BLAKE2b-256 |
431ecad1a0bd3879fd62d5da49691427f30e36ab395def38682f560fefa48c44
|
File details
Details for the file opentele_tg-3.13.1-py3-none-any.whl.
File metadata
- Download URL: opentele_tg-3.13.1-py3-none-any.whl
- Upload date:
- Size: 61.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30d0db6af51ca644e02ccd246f3a8a2db86dec2b0df4c30ae712f69795d5b9a7
|
|
| MD5 |
44530124c8ad6d8da1390fd4c3bab1fa
|
|
| BLAKE2b-256 |
b479f8e8a6aaebb0015fdd000bf11a4b6b9d8c0dfa14a070b0f1d399ab06ddea
|