CLI utility for downloading Telegram chat history to JSON
Project description
Telegram Chat Downloader
A command-line utility to download Telegram chat history to JSON and TXT format.
Features
- Download complete chat history from any Telegram chat, group, or channel
- Save messages in JSON format with full message metadata
- Save messages in TXT format with user-friendly display names
- Simple configuration with YAML config file
- Support for resuming interrupted downloads
Installation
Using uvx (recommended)
-
Install
uvxif you haven't already:pip install uvx
-
Install the package in development mode:
uvx install -e .
Or install it directly from the repository:
uvx install git+https://github.com/yourusername/telegram-download-chat.git
Manual Installation
-
Clone this repository or download the source code
-
Install the required dependencies:
pip install -r requirements.txt
-
Copy the example config file and update it with your API credentials:
cp config.example.yml config.yml
Configuration
API Credentials
To use this tool, you'll need to obtain API credentials from my.telegram.org:
- Go to API Development Tools
- Log in with your phone number
- Important: Do not use a VPN when obtaining API credentials
- Create a new application
- Copy the
api_idandapi_hashto yourconfig.yml
Configuration File (config.yml)
telegram_app:
api_id: your_api_id # Get from https://my.telegram.org
api_hash: your_api_hash # Get from https://my.telegram.org
# Map user IDs to display names for text exports
users_map:
123456: "Alice"
789012: "Bob"
# full settings: see config.example.yml
Usage
Basic Usage
python telegram-download-chat.py https://t.me/username
Command Line Options
usage: telegram-download-chat.py [-h] [-o OUTPUT] [--limit LIMIT] [--until DATE] [-s] chat
Download Telegram chat history to JSON
positional arguments:
chat Chat identifier (group URL, @username, or invite link)
options:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Output JSON filename (default: chat_history.json)
--limit LIMIT Number of messages per API request (50-1000, default: 500)
--until DATE Only download messages until this date (format: YYYY-MM-DD)
-s, --silent Suppress progress output (default: False)
Examples
# Download chat to default output file (chat_history.json)
python telegram-download-chat.py https://t.me/username
# Download messages until a specific date (exclusive)
python telegram-download-chat.py https://t.me/username --until 2025-05-01
# Combine with other options
python telegram-download-chat.py @username --limit 100 --until 2025-01-01 -o my_chat.json
Output Format
The tool generates two files for each chat:
[chat_name].json- Complete message data in JSON format[chat_name].txt- Human-readable text version of the chat
Notes
- For the first run, you will need to log in to your Telegram account
- Session is saved in
./data/session.session - For work requires Python 3.7+
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 telegram_download_chat-0.1.0.tar.gz.
File metadata
- Download URL: telegram_download_chat-0.1.0.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d9f82e453e9e40d5342a3f898b490c41e093ba74c3ba08a756a2a36bfae8b92
|
|
| MD5 |
34e4766cfb5fadb99b71b7ffbeaa2659
|
|
| BLAKE2b-256 |
c4f7b79bb50f26fc83f2b1043d01e121cfff0c3a928b342818fe880d83bd7d29
|
File details
Details for the file telegram_download_chat-0.1.0-py3-none-any.whl.
File metadata
- Download URL: telegram_download_chat-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2536b2bdb68cf4476d7f41688a8b20201d57b918b5dc6391ecb33d432e721074
|
|
| MD5 |
6d9c0425233c7bb0c6f29858f63f58bc
|
|
| BLAKE2b-256 |
252a23626f4e562315f9dc850e665868bd29965f95b23fe5195ece2742674ca3
|