telegram-export-md
Turn Telegram's unreadable
result.jsonexport into clean, searchable Markdown files.
🌐 Languages: English · فارسی
Telegram Desktop's built-in Export chat history gives you a giant result.json
(plus folders full of media) — technically complete, practically unreadable.
telegram-export-md converts it into one tidy Markdown file per chat, with
formatting, replies, forwards, polls, and media all preserved.
Zero dependencies. Pure Python standard library.
Before → After
Before — raw export JSON:
{"id": 183, "type": "message", "date": "2021-01-01T10:00:00",
"from": "Arian", "text": [{"type": "plain", "text": "hello "},
{"type": "bold", "text": "everyone"}, {"type": "plain", "text": "?"}]}
After — rendered Markdown:
**2021-01-01 10:00 — Arian**
hello **everyone**?
---
**2021-01-02 18:30 — Arian**

*1920×1080*
Features
- 📄 One Markdown file per chat, plus an
index.mdtable of contents - 📡
fetchmode (optional extra) — pull chats straight from Telegram's servers, no desktop app needed - 🎨 Telegram formatting preserved — bold, italic, code, pre, strikethrough, underline, links
- 💬 Replies resolved — quoted with sender and a snippet of the original message
- ↩️ Forwards, edits, and polls rendered faithfully
- 🖼 Media support — photos embed, everything else links;
--copy-mediamakes the backup self-contained - 🔍 Filters — pick chats by name or id, slice by date range
- 🧹 Service messages (joins, pins, calls) can be excluded
- 🐍 No dependencies — works on Python 3.10+, Windows/macOS/Linux
Install
# from PyPI
pipx install telegram-export-md
# optional: fetch mode (pull chats from Telegram's servers via their API)
pipx install 'telegram-export-md[fetch]'
# or directly from this repo
uv tool install git+https://github.com/Retro-Zero/telegram-export-md.git
# or
pip install git+https://github.com/Retro-Zero/telegram-export-md.git
Usage
1. Export your data
In Telegram Desktop: Settings → Advanced → Export chat history.
Tick JSON as the format and check Include photos and videos if you want media.
This creates a folder containing result.json and media subfolders.
2. Convert
tg-export-md ~/Downloads/Telegram-Export -o ~/telegram-backup
Result:
telegram-backup/
├── index.md
├── Gaming Crew.md
├── Saved Messages.md
└── media/
└── Gaming Crew/
├── photo_1.jpg
└── video_1.mp4
Options
| Option | Description |
|---|---|
export |
Path to the export folder (containing result.json) or to result.json itself |
-o, --output |
Output directory (default: ./markdown) |
--chat TEXT |
Only export chats whose name or id contains TEXT |
--since YYYY-MM-DD |
Only messages on or after this date |
--until YYYY-MM-DD |
Only messages on or before this date |
--copy-media |
Copy media into the output folder (self-contained backup) |
--no-media |
Omit media references entirely |
--no-service |
Skip service messages (joins, pins, calls, …) |
--quiet |
Only print errors |
Examples
# One chat, as a searchable text archive
tg-export-md export/ -o backup --chat "Gaming Crew" --copy-media
# Everything from 2022, text only
tg-export-md export/ -o backup --since 2022-01-01 --no-media
# Point straight at the JSON file
tg-export-md export/result.json -o backup
Automatic backup with fetch
No desktop app? No problem. tg-export-md fetch pulls chats straight from
Telegram's servers into the same result.json + media format the desktop
export produces — so the converter above works unchanged, and you get backups
you can schedule.
Setup (once)
-
Get free API keys at my.telegram.org → API development tools
-
Make the keys available — either:
export TG_API_ID=123456 export TG_API_HASH=yourhash
or save them in
~/.config/telegram-export-md/config.ini:[telegram] api_id = 123456 api_hash = yourhash
-
Install with the extra:
pipx install 'telegram-export-md[fetch]'
Run
Run without flags for an interactive picker: after login it lists your chats and lets you choose which ones to export, which media types to download (photo, video, voice, audio, document, sticker, animation), and optional limits — last N messages per chat, a per-file size cap, and a date range.
tg-export-md fetch -o ~/telegram-export
The first run asks for your phone number and a login code Telegram sends you — the session is saved, so later runs are automatic. Everything the picker asks is also available as a flag, so cron jobs stay hands-free:
tg-export-md fetch -o ~/telegram-export --chat "Family" --media-types photo,video --last 500 --max-size 100mb
tg-export-md ~/telegram-export -o ~/telegram-backup
| Flag | Description |
|---|---|
--chat TEXT |
only fetch chats whose name or id contains TEXT |
--since / --until YYYY-MM-DD |
date range |
--last N (alias --limit) |
only the last N messages per chat (newest) |
--media |
download all media types |
--media-types TYPES |
which media to download: photo,video,voice,audio,document,sticker,animation |
--max-size SIZE |
skip files larger than this (e.g. 50mb, 1gb) |
Notes
- Large exports — the whole
result.jsonis loaded into memory; exports up to a few hundred MB work fine on a modern laptop. Streaming support is on the roadmap. - Media paths without
--copy-mediapoint back into your original export folder. Use--copy-mediafor a backup you can move or archive. - Export JSON is generated by Telegram Desktop (Windows/macOS/Linux). Exports from other clients may differ slightly — open an issue if something doesn't parse.
Roadmap
- Streaming parse for huge exports
- Support the HTML export format
- Per-year splitting (
--split) -
--format obsidianfor vault-friendly output
Contributing
Bug reports, feature requests, and PRs are welcome. Please open an issue first for anything beyond a small fix.
License
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_export_md-0.3.1.tar.gz.
File metadata
- Download URL: telegram_export_md-0.3.1.tar.gz
- Upload date:
- Size: 264.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4da0885546972c2112bd79f1371340ec4688b63cde6bf969ea5df761d080092
|
|
| MD5 |
dd937b80e0be5ba386dd549787e0607d
|
|
| BLAKE2b-256 |
3a7ff62426f02dacab5ac250ada6baf51863ec82a30c44ba814fe8bead77a95d
|
Provenance
The following attestation bundles were made for telegram_export_md-0.3.1.tar.gz:
Publisher:
release.yml on Retro-Zero/telegram-export-md
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
telegram_export_md-0.3.1.tar.gz -
Subject digest:
d4da0885546972c2112bd79f1371340ec4688b63cde6bf969ea5df761d080092 - Sigstore transparency entry: 2469475445
- Sigstore integration time:
-
Permalink:
Retro-Zero/telegram-export-md@b0cd75c4d271a24edb76666412f390ad0d0ef902 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/Retro-Zero
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b0cd75c4d271a24edb76666412f390ad0d0ef902 -
Trigger Event:
push
-
Statement type:
File details
Details for the file telegram_export_md-0.3.1-py3-none-any.whl.
File metadata
- Download URL: telegram_export_md-0.3.1-py3-none-any.whl
- Upload date:
- Size: 22.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
855b68abdd05cdc7fc190277b7c5b55c07e74a35148017a6383d9aa034b587b6
|
|
| MD5 |
5363cc4ba2cb5c637c25d820090a9eeb
|
|
| BLAKE2b-256 |
2a0e1df2c39df8fa27b0d1fdb2aab6809798523d39e3a08f7bfbcf4d17cf1541
|
Provenance
The following attestation bundles were made for telegram_export_md-0.3.1-py3-none-any.whl:
Publisher:
release.yml on Retro-Zero/telegram-export-md
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
telegram_export_md-0.3.1-py3-none-any.whl -
Subject digest:
855b68abdd05cdc7fc190277b7c5b55c07e74a35148017a6383d9aa034b587b6 - Sigstore transparency entry: 2469475891
- Sigstore integration time:
-
Permalink:
Retro-Zero/telegram-export-md@b0cd75c4d271a24edb76666412f390ad0d0ef902 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/Retro-Zero
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b0cd75c4d271a24edb76666412f390ad0d0ef902 -
Trigger Event:
push
-
Statement type: