How TGConvertor works
masterTelegramSession object based on this data. This object provides a high-level interface to export that session data into various supported formats (Telethon, Pyrogram, Kurigram, or Tdata).repository·master·Indexed 41 days ago
https://github.com/nazar220160/tgconvertorA utility module and CLI tool for converting Telegram authorization sessions between various formats, including Telethon, Pyrogram, Kurigram, and Telegram Desktop (tdata). Version 0.1.4 supports session conversion via files or strings and provides a SessionManager Python API for programmatic access.
TelegramSession object based on this data. This object provides a high-level interface to export that session data into various supported formats (Telethon, Pyrogram, Kurigram, or Tdata).Use the convert command to transform sessions. You must specify the source format (-f), the target format (-t), and the output destination (-o).
| Scenario | Command Example |
|---|---|
| File to File | tgconvertor convert session.session -f telethon -t pyrogram -o new_session.session |
| String to File | tgconvertor convert "1:AAFqwer..." -f telethon -t pyrogram -o session.session |
| File to String | tgconvertor convert session.session -f telethon -t pyrogram -o string |
| String to String | tgconvertor convert "1:AAFqwer..." -f telethon -t pyrogram -o string |
| String to tdata | tgconvertor convert "1:AAFqwer..." -f telethon -t tdata -o tdata_folder |
| tdata to String | tgconvertor convert tdata_folder/tdata -f tdata -t telethon -o string |
You can specify the client API type using the --api flag. Supported values are:
desktop (default)androidiosmacoswebExample: tgconvertor convert session.session -f telethon -t pyrogram --api android
# Convert from file to file
tgconvertor convert session.session -f telethon -t pyrogram -o new_session.sessionInstall the base package using pip. You can also install optional dependencies for specific format support using extras:
pip install TGConvertor[pyrogram]pip install TGConvertor[kurigram]$ pip install TGConvertor[pyrogram]
# OR
$ pip install TGConvertor[kurigram]For programmatic access, use the SessionManager class from the TGConvertor module. The workflow involves creating a session instance from a source and then calling a conversion method.
Note: Some methods are asynchronous and require await.
from TGConvertor import SessionManager
# Convert from string (Synchronous example)
session = SessionManager.from_pyrogram_string('session_str')
print(session.to_pyrogram_string())
# Convert from file (Asynchronous example)
import asyncio
async def main():
# Convert from file
session = await SessionManager.from_telethon_file('session.session')
await session.to_pyrogram_file('new_session.session')
asyncio.run(main())telethon: Telethon session files (.session)pyrogram: Pyrogram session files (.session)tdata: Telegram Desktop format (directory)desktop: Telegram Desktop client (default)android: Telegram Android clientios: Telegram iOS clientmacos: Telegram macOS clientweb: Telegram Web clientUse the info command to view details of an existing session. You must provide the input path and the format (-f).
# Show Telethon session info
tgconvertor info session.session -f telethon
# Show Pyrogram session info
tgconvertor info my_session.session -f pyrogramtgconvertor info session.session -f telethonThe tgconvertor command-line tool allows you to convert Telegram sessions between different formats and inspect session details.
tgconvertor --help: Show help and available commands.tgconvertor list-formats: List all supported formats and API types.tgconvertor convert <input> ...: The primary command for session conversion.tgconvertor info <input> ...: Inspect session details.tgconvertor --help
tgconvertor list-formatsThe following Telegram API types can be specified using the --api or -a flag:
| Type | Description |
|---|---|
desktop | Telegram Desktop client |
android | Telegram Android client |
ios | Telegram iOS client |
macos | Telegram macOS client |
The following formats are supported for both input and output:
| Format | Description |
|---|---|
telethon | Telethon session format (.session files) |
pyrogram | Pyrogram session format (.session files) |
tdata | Telegram Desktop tdata format (directory) |
Use the info command to inspect a session file and view its metadata, such as DC ID, User ID, Phone number, and validity status.
session_path: The path to the session file or directory.--format, -f: The format of the session (telethon, pyrogram, or tdata).# Show Telethon session info
tgconvertor info session.session -f telethon
# Show Pyrogram session info
tgconvertor info my_session.session -f pyrogramUse the list_formats command to see all available session formats and Telegram API types supported by the converter.
tgconvertor list_formats