Skip to main content

tg-chat-dump

PyPI Python Telethon License: MIT Donate

Over 100,000 messages per minute: ~115,000 with tg-chat-dump, ~29,000 with Telegram Desktop's export, ~6,000 through the regular API

Interactive mode: find a chat with live suggestions, then dump 421,393 messages in 3m 47s
A 421,393-message group dumped in 3m 47s with two accounts (the download part is sped up 12×; account names are blurred).

Dump an entire Telegram chat into SQLite and a folder per forum topic at over 100,000 messages a minute. It runs Telegram's own data-export mode with parallel workers on several accounts, so a chat of several hundred thousand messages is done in minutes: about 4× faster than Telegram Desktop's own export, and a whole forum in one pass instead of topic by topic.

out/1234567890_My_Chat/
├── index.html          the offline reader (html extra)
├── 1_General/
│   ├── messages.jsonl
│   └── messages.txt
├── 12_Off-topic/
│   ├── messages.jsonl
│   └── messages.txt
└── 37_Announcements/
    ├── messages.jsonl
    └── messages.txt

Features

  • Over 100,000 messages a minute with Telegram's export mode and two accounts: about 4× Telegram Desktop's export and 10× the regular API (see Performance).
  • Run it without arguments for the interactive mode: log in with a QR code, find a chat as you type or paste its link, update everything you dumped before in one go, watch a progress bar with ETA.
  • A whole forum in one pass. Messages are sorted into topics as they arrive.
  • The chat is split into message-id ranges that several workers download at once. Telegram limits each account separately, so every extra account adds about as much speed as the first.
  • Progress is committed to SQLite every 100 messages. An interrupted run resumes where it stopped, and later runs fetch only new messages and append them to the files, so a repeat run of a large chat takes seconds. When a forum topic is renamed, its folder is renamed too.
  • Everything the Telegram app shows with a message, not only its text: rich messages laid out in blocks, file names and sizes, link previews, polls and checklists, places and contacts, buttons with their links, quotes in replies, replies to other chats, forward sources, author signatures and admin titles, fact checks, service actions with their details.
  • Optional extras, each a toggle: reactions and views, formatting with hidden links, comments under channel posts, and Telegram's export mode (see Extras).
  • Filters by date range, author or message type, such as links or documents.
  • On FLOOD_WAIT the run sleeps and then continues on its own.
  • SOCKS5 and HTTP proxies, for networks where Telegram is blocked.
  • index.html to read the dump in a browser, offline; messages.txt for reading in an editor, messages.jsonl for scripts, and the SQLite database for queries.

Quick start

  1. Create an app at my.telegram.org → API development tools and note its api_id and api_hash.

  2. Install and run:

    pipx install tg-chat-dump
    tg-chat-dump
    

    uv tool install tg-chat-dump or pip install tg-chat-dump work too. Installed this way, settings and sessions are kept in ~/.tg-chat-dump and dumps go to ~/tg-chat-dump.

    From source, with uv, everything stays inside the checkout (.env, data/, out/):

    git clone https://github.com/renkagod/tg-chat-dump.git
    cd tg-chat-dump
    uv run dump.py
    

The first start asks for api_id and api_hash, saves them to .env and logs you in: scan a QR code in Telegram on your phone (Settings → Devices → Link Desktop Device), or type p to log in with the phone number. On the first dump Telegram asks to allow the fast export mode: the "Telegram" chat gets a data export request, tap Allow there and press Enter (see Extras). After that it works like this:

Accounts: Alice @alice, Bob
Extras: takeout, html   Output: D:\Telegram dumps
Loading your chats… 312 found.

Search chat (name, @username, id or t.me link; Enter: your dumps, /: settings): forum
   1) Forum Club  @forumclub  [forum]  2/2 accounts
   2) Forum News  @forumnews  [channel]  1/2 accounts
Number, [p] search public chats, or type to search again > 1

Forum Club  [forum]  id -1001234567890
~152,310 messages
Dump it with 2 accounts, extras: takeout, html? [Y/n, f = filters]
[████████░░░░░░░░░░░░]  41%  62,104 saved  112,400/min  ETA 48s
  • Matching chats pop up under the cursor as you type; Tab fills in the highlighted one and Enter picks it. A pasted t.me link or an exact @username works too.
  • Enter on an empty search lists the chats you dumped before, the latest first, with how many messages are saved. Pick one to fetch its new messages, several to update them in a row (2 5 7 or 4-6), or u for all of them.
  • If nothing in your chats matches the search, public groups and channels are searched too. Public chats can be dumped without joining.
  • Every account that can see the chat is used. A private chat or a small (non-super) group is the exception: each account has its own copy of it, so you see how many messages each one has and pick one. Enter takes the account that saved the chat before, or the biggest copy.
  • / opens the settings: add (a) or remove (d N) accounts, toggle the extras (x), set the output folder (f). They are saved. By default the output goes to ~/tg-chat-dump, or out/ in a source checkout.
  • Answering f instead of Y asks for filters for this one dump.
  • When a dump is done, o opens it in the browser (with the html extra) and f opens the folder.
  • Ctrl+C stops the dump; the next run resumes it.
  • If Telegram is blocked in your network, set TG_PROXY in .env, for example TG_PROXY=socks5://127.0.0.1:1080.
  • The interactive mode is colored in a terminal; set NO_COLOR=1 to turn colors off.

Extras

takeout and html are on by default, the others are off. Switch them with x in the interactive mode, --with on the command line (it replaces the saved list), or TG_OPTIONS in .env; TG_OPTIONS=none turns all of them off.

Extra Adds Cost
meta reactions ({"👍": 12}), views, forwards, replies none, it is already in every message
markdown text_md: the text as Markdown, with bold, links behind words, mentions none
comments for a channel: the comments under its posts, from the linked discussion group, in comments/, grouped by post a second dump of the discussion group
takeout runs the dump in Telegram's data-export mode, the one Telegram Desktop uses; it skips the usual rate limits, about 10× faster (see Performance) the first time, Telegram asks you to allow the export in the app (the interactive mode waits for it), otherwise it opens after 24 hours; until then the dump runs at normal speed
html index.html in the chat folder: read the dump in a browser, offline, with topics, search, replies and jumps to a date a few seconds on the first run for a chat of several hundred thousand messages, then a fraction of a second

Turning an extra on later does not touch messages that are already saved. A new run adds it to new messages only; --refetch adds it to the saved ones too. Polls and checklists are always saved now; the old polls extra is still accepted and does nothing.

Filters

uv run dump.py @somegroup --since 2026-01-01 --until 2026-03-31   # a date range, inclusive
uv run dump.py @somegroup --since 2026-03 --until 2026-03         # all of March
uv run dump.py @somegroup --since 7d                              # the last 7 days (also 2w, 3m)
uv run dump.py @somegroup --from @alice                           # one author
uv run dump.py @somegroup --type links                            # links, docs, photos, videos, voice, pinned, ...

A filtered dump gets its own database and folder, for example out/1234567890_My_Chat_since-2026-01-01_links/, so it never mixes with the full dump. Filters can be combined. They work with whole-chat dumps, not with --topics.

When the whole chat is already dumped, date and author filters are applied to the saved copy: the whole chat is brought up to date first, then the filtered folder is written from it without downloading the messages again. --type always asks Telegram, since the saved copy does not know which messages hold links.

Command line

With arguments it runs without questions, for scripts and cron. Settings come from .env (see .env.example). The examples use the source checkout; with the installed package, replace uv run dump.py with tg-chat-dump:

uv run dump.py @somegroup                            # whole chat (or only new messages on repeat runs)
uv run dump.py https://t.me/somegroup                # the same; --chat @somegroup works too
uv run dump.py --update-all                          # new messages of every chat dumped before, for cron
uv run dump.py --chat @somegroup --topics 12,37      # only these forum topics
uv run dump.py --chat @somegroup --with meta,markdown   # with extras
uv run dump.py --chat @somegroup --export-only       # rebuild the folders from the database, no network
uv run dump.py --chat @somegroup --refetch           # download the saved messages again, see below
uv run dump.py --login acc2                          # add another account (see below)
uv run dump.py --chat @somegroup --workers 2         # workers per account, default 3
uv run dump.py --chat @friend --account acc2         # only this account: session name, @username or id
uv run dump.py --chat @somegroup --out "D:\Telegram dumps"   # output folder, remembered in .env

More accounts, more speed

Every extra account that is a member of the chat adds throughput. Add one with a in the interactive mode, or:

uv run dump.py --login acc2   # log in once, saved to data/acc2.session

It shows a QR code to scan in Telegram on a phone where that account is logged in (Settings → Devices → Link Desktop Device); type p instead to log in with the phone number and code.

Each data/*.session file is picked up automatically. Accounts that are not logged in or are not members of the chat are skipped with a warning. So is an account that Telegram has frozen: it is read-only and cannot even look up a public chat, and the warning gives the date by which to appeal via @SpamBot before Telegram deletes it. Private chats and small groups are numbered separately in every account, so they are always dumped by one account; on the command line it is the one that saved the chat before, or else the one with the most messages, unless --account names another.

Performance

Measured on a large forum supergroup (several hundred thousand messages):

Accounts Speed Full dump
1 ~6,000–7,000 messages/min ~1h 45m
2 ~11,500 messages/min ~1h
2, with takeout ~115,000 messages/min ~6m
Telegram Desktop export, for comparison ~29,000 messages/min ~25m (extrapolated)

The Telegram Desktop row comes from a separate side-by-side test on one 420,912-message public group, text only: Telegram Desktop exported ~29,000 messages/min and tg-chat-dump with takeout ~110,000. Its full-dump time in the table is extrapolated from that rate.

Telegram's per-account rate limit sets the ceiling: about 6,000 messages/min without takeout and about 60,000 with it. More than 3 workers per account does not help (3, 6 and 12 measured the same), and with many more Telegram adds flood waits. Turning on takeout gives the biggest jump; after that, more speed comes only from more accounts.

Output

With the html extra the chat folder gets index.html: double-click it to read the dump in a browser, with no network and no server. Topics are in a sidebar; the chat opens at the newest messages, replies jump to the quoted message, and there is search (/, Enter for the next match), a jump to a date or a message id, and links like index.html#topic/12/msg/1042. Its data lies in the hidden .reader/ folder next to it, in parts of 10,000 messages; a repeat run rewrites only the newest part of each topic that got new messages, so it takes a fraction of a second. Times are shown in your local timezone, while the text files keep UTC.

Each topic folder contains:

messages.txt: one line per message:

[2026-03-14 09:01:12] #1042 Alice: hi everyone  [👍 3 · 120 views]
[2026-03-14 09:02:40] #1043 Bob (reply to #1042): <MessageMediaPhoto> look at this
[2026-03-14 09:05:00] #1044 Carol: <poll> Lunch? | Pizza (4) | Sushi (2) | 6 votes
[2026-03-14 09:06:10] #1045 Dave [admin] (reply to #1042) (quoting «hi»): <MessageMediaDocument: notes.pdf, 1.2 MB> the notes
  [buttons: Open <https://example.com/notes>]

messages.jsonl: one JSON object per message:

Field Meaning
id message id
date, edit_date ISO 8601, UTC
topic_id forum topic (1 = General, null in non-forum chats)
sender_id, sender author id and display name
text message text
reply_to, reply_top replied-to message and thread root
fwd_from original author of a forwarded message
media media type (MessageMediaPhoto, MessageMediaDocument, ...)
action service message type (MessageActionTopicCreate, ...)
grouped_id album id
extra everything else the app shows, see below
text_md, views, forwards, replies, reactions only with the matching extras

extra holds only what a message has: file (name, size, type, duration, performer and title, sticker emoji), webpage (link preview: site, title, description), poll, todo, geo, venue, contact, dice, game, invoice, story, paid_media, media_info (the fields of any other media), buttons (rows of {text, url}), links (addresses hidden behind words), reply (quote, and peer/chat/from for a reply to another chat), fwd (source id, date, signature), author (signature of a channel post), rank (admin title), via_bot, action (fields of a service message), factcheck, restricted, effect, paid_stars, pinned, channel_post. rich: true marks a rich message: Telegram's block layout of paragraphs, quotes, lists and tables, saved in text as plain text (and as Markdown in text_md with the markdown extra).

Dumps made by versions before 1.3.0 lack some of this: rich messages there have an empty text, and media, buttons and replies have no details. --refetch downloads the saved messages again and fills that in; it takes about as long as the first dump, updates rows in place (messages deleted from Telegram since stay), and rewrites the folders. Ctrl+C stops it, and the next run goes on with it.

The raw data is in data/<chat id>.sqlite, with tables messages, topics, tasks (download progress) and exports (what was last written to each folder, so a repeat run only appends). While a dump runs, .sqlite-wal and .sqlite-shm files sit next to the database; they are part of it and disappear when the run ends, so copy the database only after that.

Limitations

  • Downloads text and metadata only. Media files are recorded by type and details (file name, size, link preview, place...) and not downloaded.
  • The account only sees what Telegram shows it: if the chat hides history from new members, older messages are not available.
  • --topics cannot fetch the General topic on its own; the full-chat mode covers it.

Responsible use

Using your own account through the API falls under Telegram's API Terms of Service. Dumps contain other people's messages, so keep them private and comply with your local data-protection laws. data/*.session files are full logins to your accounts: never share or commit them.

Development

uv sync
uv run pytest
uv run ruff check . && uv run ruff format --check .

The code is in tgdump/: fetch downloads, store turns messages into database rows (with details for what goes into extra and rich for rich messages), export writes the folders, reader the offline page, cli and interactive are the two front ends.

Issues and pull requests are welcome. Please run the tests and linters before opening a PR.

Support

If this project is useful to you, you can support it with crypto: donation addresses.

License

MIT

Metadata

Release files for tg-chat-dump 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tg-chat-dump 1.3.0
File Size Uploaded Provenance Actions
tg_chat_dump-1.3.0.tar.gz 85.9 kB With provenance Details for tg_chat_dump-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tg-chat-dump 1.3.0
File Interpreter ABI Platform Actions
tg_chat_dump-1.3.0-py3-none-any.whl Python 3 none any Details for tg_chat_dump-1.3.0-py3-none-any.whl

Total release size: 162.6 kB

Release files / tg_chat_dump-1.3.0.tar.gz

Download URL tg_chat_dump-1.3.0.tar.gz
Size 85.9 kB
Tags Source
SHA-256 checksum
How to use checksums
54ed8df8644b2569a07159d4dce19fcd600e847bf0efdb409439b965c9eda4eb
BLAKE2b-256 checksum
How to use checksums
a4b74ab0a682c6c534d5c9cc8b815235cf00e2ecdd966562e52eb6d4d1c5bc7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Nov 1, 2026.

Transparency log

Release files / tg_chat_dump-1.3.0-py3-none-any.whl

Download URL tg_chat_dump-1.3.0-py3-none-any.whl
Size 76.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e286c3e9b0c692b482cfa94c2f24ed5431dc0355dfdc57da7a921064c6654b03
BLAKE2b-256 checksum
How to use checksums
416456f59e7370e503a03c5d039539836eb1258b6288cfe9d9f7acc44ecaf35c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Nov 1, 2026.

Transparency log

Security for tg-chat-dump 1.3.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tg_chat_dump-1.3.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 Nov 1, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page