Skip to main content

CLI utility for downloading Telegram chat history to JSON

Project description

Telegram Chat Downloader

PyPI License: MIT Python Version

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 pip

pip install telegram-download-chat

Using uvx

uvx install git+https://github.com/popstas/telegram-download-chat.git

Configuration

API Credentials

To use this tool, you'll need to obtain API credentials from my.telegram.org:

  1. Go to API Development Tools
  2. Log in with your phone number
    • Important: Do not use a VPN when obtaining API credentials
  3. Create a new application
  4. Copy the api_id and api_hash to your config.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 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:

  1. [chat_name].json - Complete message data in JSON format
  2. [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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telegram_download_chat-0.1.1.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

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

telegram_download_chat-0.1.1-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file telegram_download_chat-0.1.1.tar.gz.

File metadata

  • Download URL: telegram_download_chat-0.1.1.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for telegram_download_chat-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e8de4e08c5a03212fae876355df02e3720c5b8fe48140b57fcbdde24c7555eab
MD5 5f7249810582ea0be907dfa09ddcdc22
BLAKE2b-256 8b4ca01004265f52f78668ea6cdb26e5750c983d910c8c0444c4b47843be519d

See more details on using hashes here.

File details

Details for the file telegram_download_chat-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for telegram_download_chat-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 513da16e318971cc4b3c5775562d79798cd2e352fe9a583deee8956bb3d73417
MD5 97f6eec783a7a64dc525b09ea7fd9668
BLAKE2b-256 4d118c1c9efb05d2f09b1e3b99eb30dd3163a622636286e1dbcf9da05e85eae9

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