tgsession
Telegram Session Toolkit Generate, inspect, dump, and convert Telegram sessions between Telethon and Pyrogram.
tgsession is designed to be clean, explicit, and predictable — no magic, no broken conversions, no messy side effects.
✨ Features
-
Generate Telethon sessions
-
Generate Pyrogram sessions
-
Convert sessions:
- Telethon → Pyrogram (string)
- Pyrogram → Telethon (planned)
-
Inspect Telethon
.sessionfiles -
Dump Telethon session metadata as JSON
-
Clean, colored CLI output (Colorama)
-
Works on Linux / Termux / GitHub Actions
⚠️ File-based Pyrogram session conversion is experimental. String sessions are the recommended and stable format.
📦 Installation
git clone https://github.com/ankit-chaubey/tgsession.git
cd tgsession
pip install -e .
Or from PyPI release:
pip install tgsession
🚀 Usage
General Help
tgsession --help
🔧 Generate Sessions
Generate a Telethon session
tgsession gen tl myaccount
Creates:
myaccount.session(Telethon SQLite session)
Generate a Pyrogram session
tgsession gen pyro myaccount
Creates:
- Pyrogram string session (recommended)
🔍 Inspect Sessions
Inspect a Telethon session
tgsession inspect myaccount.session
Shows:
- DC ID
- Server address
- Port
📤 Dump Sessions
Dump Telethon session as JSON
tgsession dump myaccount.session
Outputs structured metadata useful for debugging and tooling.
🔄 Convert Sessions
Telethon → Pyrogram (string session)
tgsession convert tl myaccount.session pyro
Output:
- Pyrogram string session (printed to stdout)
🧠 Design Philosophy
- Explicit > Implicit
- No hidden authorization steps
- No silent session mutation
- One clear source of truth per session
If something converts — it really converts.
🗂 Project Structure
tgsession/
├── cli.py # CLI entry point
├── gen/
│ ├── telethon_gen.py # Telethon generator
│ └── pyrogram_gen.py # Pyrogram generator
├── inspect/
│ └── telethon_inspect.py
├── dump/
│ └── telethon_dump.py
├── convert/
│ ├── tl_to_pyro.py
│ └── pyro_to_tl.py
└── core/
└── utils.py
🛣 Roadmap
- Stable Pyrogram → Telethon conversion
- Optional Pyrogram file session export
- Non-interactive mode (CI friendly)
- Plugin system
👤 Author
Ankit Chaubey GitHub: https://github.com/ankit-chaubey
📄 License
MIT License
Metadata
Release files for tgsession 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| tgsession-0.1.0.tar.gz | 7.1 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tgsession-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.7 kB
Release files / tgsession-0.1.0.tar.gz
| Download URL | tgsession-0.1.0.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de02acd37a8ba8daf3ffefa16f6acc7dbcc0e8761fafe113ddde36767e0509df
|
|
BLAKE2b-256 checksum How to use checksums |
abf4ea27f8fd7d4c80966b4101dc2e8054769a83ecbcb3d93232949915a56cb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 29, 2026.
Transparency logRelease files / tgsession-0.1.0-py3-none-any.whl
| Download URL | tgsession-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1eb5deebb552b4debbe8d78bd40c70096389feae324c382ea089c69541e8617e
|
|
BLAKE2b-256 checksum How to use checksums |
375ecb589c87e4b449750a89cbb327b1e659fa6b6b32b9135d81b872bf7ae9ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 29, 2026.
Transparency logSecurity for tgsession 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for tgsession-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.