Skip to main content

Read Telegram Desktop tdata folders into Telethon-ready accounts.

Project description

tdata_reader

Read Telegram Desktop's tdata folder and extract everything needed to spin up a Telethon client — without PyQt5 and without any native crypto extension.

The library is a stripped-down, dependency-light fork of the data-reading parts of opentele: it only does the read-tdata → Telethon-session direction, which is the common use case in account-management tools.

Install

pip install tdata-reader

The only runtime dependency is telethon. Telethon's pure-Python AES implementation is used as a fallback, so cryptg/tgcrypto are optional — install one of them for a noticeable speed-up if you plan to also use the resulting client at scale.

Usage

from tdata_reader import read_tdata

acc = read_tdata("/path/to/tdata")            # first account
print(acc.user_id, acc.dc_id)                 # extracted from tdata
print(acc.api_id, acc.api_hash)               # TelegramDesktop preset
print(acc.device_model, acc.system_version)   # ditto

session_string = acc.to_string_session()       # ready for StringSession

Plug into Telethon:

from telethon import TelegramClient
from telethon.sessions import StringSession

client = TelegramClient(
    StringSession(session_string),
    **acc.as_init_connection_kwargs(),
)

Passcode-protected tdata:

acc = read_tdata("/path/to/tdata", passcode="my-local-passcode")

Multi-account tdata (TDesktop supports up to 3 accounts):

from tdata_reader import read_all_tdata

for acc in read_all_tdata("/path/to/tdata"):
    print(acc.user_id, acc.to_string_session())

Mask the session as a different official client:

from tdata_reader import read_tdata, TelegramAndroid

acc = read_tdata("/path/to/tdata", api=TelegramAndroid)
# acc.api_id / acc.api_hash / acc.device_model now match TelegramAndroid

Returned data

TDataAccount fields:

Field Source Notes
user_id tdata Telegram user id
dc_id tdata Main data-center id (1–5)
auth_key tdata 256-byte authorization key for the main DC
dc_ip, dc_port built-in Production endpoint for dc_id
extra_auth_keys tdata {dc_id: 256-byte key} for non-main DCs
api_id, api_hash API preset Defaults to TelegramDesktop (2040)
device_model, system_version, app_version API preset Used by Telethon's initConnection
lang_code, system_lang_code, lang_pack API preset Same

Note on device fields. device_model, system_version, app_version, lang_code, system_lang_code are not stored inside tdata — Telegram clients send them in initConnection at runtime. The library exposes the official preset values so that the resulting Telethon client looks identical to a real Telegram Desktop.

Exceptions

All exceptions inherit from TDataError:

  • TDataFileNotFound — required files (key_data*, data*, …) missing.
  • TDataBadDecryptKey — wrong passcode or tampered/corrupt encrypted blob.
  • TDataCorrupted — files are present but their contents don't parse.
  • TDataUnsupportedDc — account references a DC id not in the built-in production endpoint table.

License

MIT.

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

tdata_reader-0.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

tdata_reader-0.1.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file tdata_reader-0.1.0.tar.gz.

File metadata

  • Download URL: tdata_reader-0.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for tdata_reader-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a0de207bc11139738b4eb7183f76f27e39b3df39882a88d997f2611ab7a76a3a
MD5 520cf320143df4d5b1da65d62e6784cc
BLAKE2b-256 79d1e4e3dfb34b7a2dac7d6c1c8fc4ca1b56fbbf4d878a4f7b29b6090b9f1446

See more details on using hashes here.

File details

Details for the file tdata_reader-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tdata_reader-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for tdata_reader-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f83a4e45f82ff963d461ceb28d375ad133558decad49e2a976ab0e68c35baea
MD5 b9db34f4c3e4dd5c05c1436d4e4b086c
BLAKE2b-256 d74f32098b7d06c24c0393e1ec0b12dad98ba096e45f8230aa8df9437c169914

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