A powerful and sophisticated console-based tool to export your Telegram chat history into beautiful, self-contained HTML files. Engineered for efficiency and reliability, it uses an SQLite backend to handle even massive chats with minimal memory usage and includes a fully-featured interactive media gallery.
- 🗂️ Efficient & Robust: Utilizes a temporary SQLite database to process chats of any size with very low memory overhead. The entire export process is a single, continuous operation.
- 🖼️ Interactive Media Gallery: The exported HTML file includes a beautiful, built-in media viewer. Click any image or video to open a full-screen gallery with keyboard (←/→) and touch-swipe navigation.
- 🔒 Export Private Content: Seamlessly export messages and media from private chats, groups, and channels that you have access to.
- 🔐 Secure Session Management: Authenticate once and reuse your session for future exports. Your credentials are never stored in plain text.
- 🎨 Beautiful HTML Output: Generates a clean, modern, and fully self-contained HTML file. No external dependencies are needed to view the exported chat.
- ⚙️ Advanced Export Options:
- Browse and select chats from an interactive list.
- Search for chats by name.
- Export directly using a User/Chat/Channel ID or username.
- Choose to export with or without media files.
- Set a maximum file size for media downloads to skip large files.
- 🛡️ Configurable: Features adjustable request delays with built-in presets (Safe, Balanced, Risky) to protect your account from API rate limits.
This is an unofficial tool and is not affiliated with Telegram. Using the Telegram API for automation always carries some risk.
- API Rate Limits: Sending too many requests in a short period can result in temporary limitations from Telegram (FloodWaitError). This tool is designed to handle these errors gracefully, but very frequent use is discouraged. Please note that export speed is often dictated by these API limits and your internet connection speed, not just by the performance of the script or your computer.
- Account Suspension: While highly unlikely with normal use, excessive or aggressive usage could potentially lead to the suspension of your Telegram account.
- Recommendation: For your primary or important accounts, it is strongly recommended to use the "Safe" or "Balanced" delay settings within the tool to minimize risks.
The developers of this tool are not responsible for any consequences resulting from its use. Use it at your own risk.
The project is organized into a modular structure for clarity and maintainability.
telegram-chat-exporter/
│
├── core/ # Core application logic
│ ├── client_manager.py # Manages Telethon sessions
│ ├── exporter.py # Main export logic
│ ├── html_generator.py # Generates the final HTML
│ ├── media_handler.py # Handles media downloads
│ ├── merger.py # Merges two exports
│ ├── settings.py # Manages delay settings
│ ├── ui.py # Command-line user interface
│ └── utils.py # Utility functions
│
├── exports/ # Created automatically to store your exports
│
├── sessions/ # Stores your *.session files
│
├── main.py # Main entry point
├── requirements.txt # Dependencies
├── README.md # This file
└── settings.json # Created automatically when you change settings
- Python 3.8+
- Telegram API Credentials (
API IDandAPI Hash): You must obtain these from my.telegram.org. - Required libraries listed in
requirements.txt.
-
Clone the repository:
git clone [https://github.com/seuyh/telegram-chat-exporter.git](https://github.com/your-username/telegram-chat-exporter.git) cd telegram-chat-exporter -
Install the required libraries:
pip install -r requirements.txt
-
Run the script from your terminal:
python main.py
-
First-Time Setup (Create a Session):
- On your first run, choose
Create new session. - Enter your
API ID,API Hash, phone number, and a name for the session file (e.g.,my_account). - You will receive a login code from Telegram. Enter it when prompted.
- If you have 2-Step Verification enabled, you will also be asked for your password.
- Your session will be saved in the
sessions/folder.
Note on Sessions: This tool uses Telethon for session management. Only session files created by this tool or other Telethon-based applications are compatible.
- On your first run, choose
-
Exporting a Chat:
- On subsequent runs, choose
Use existing sessionto log in instantly. - From the main menu, you can browse, search, or directly specify the chat you wish to export.
- Follow the on-screen prompts to configure your export (e.g., download media, set a max file size).
- On subsequent runs, choose
-
Viewing the Result:
- Once the process is complete, you will find a new folder inside the
exports/directory containing yourmessages.htmlfile and any downloaded media. - Open the
messages.htmlfile in any modern web browser to view your exported chat.
- Once the process is complete, you will find a new folder inside the
Found a bug, have a suggestion for a new feature, or need an improvement? We'd love to hear from you!
Please feel free to open an issue on the GitHub Issues page.