Skip to main content

A tool to download Telegram data (users, chats, messages, and media) into a database (and display the saved data).

Project description

telegram-export

Logo

A tool to download Telegram data (users, chats, messages, and media) into a database (and display the saved data).

Database schema:

Schema image

Installation

The simplest way is to run sudo pip3 install --upgrade telegram_export, after which telegram-export should simply be available as a command: telegram-export in the terminal. That’s it!

If you don’t like using sudo pip, you can use pip3 install --user telegram_export, but you’ll have to add something like ~/.local/bin/ to your $PATH to get the command available. If you don’t want to add to PATH, you can also use python3 -m telegram_export anywhere instead of telegram-export. You’ll have a similar issue if you’re using a virtualenv, but if you’re using those you probably know what you’re doing anyway :)

Slow downloads?

You may also want to install cryptg with the same method for a speed boost when downloading media. Telegram requires a lot of encryption and decryption and this can make downloading files especially slow unless using a nice fast library like cryptg. One user reported a speed increase of 1100%.

Usage

First, copy config.ini.example (from GitHub) to ~/.config/telegram-export/config.ini and edit some values. You’ll probably need to create this folder. To write your config whitelist, you may want to refer to the output of telegram-export --list-dialogs to get dialog IDs or telegram-export --search <query> to filter the results.

Then run telegram-export and allow it to dump data.

Full option listing:

usage: __main__.py [-h] [--list-dialogs] [--search-dialogs SEARCH_STRING]
                   [--config-file CONFIG_FILE] [--contexts CONTEXTS]
                   [--format {text,html}] [--download-past-media]

Download Telegram data (users, chats, messages, and media) into a database
(and display the saved data)

optional arguments:
  -h, --help            show this help message and exit
  --list-dialogs        list dialogs and exit
  --search-dialogs SEARCH_STRING
                        like --list-dialogs but searches for a dialog by
                        name/username/phone
  --config-file CONFIG_FILE
                        specify a config file. Default config.ini
  --contexts CONTEXTS   list of contexts to act on eg --contexts=12345,
                        @username (see example config whitelist for full
                        rules). Overrides whitelist/blacklist.
  --format {text,html}  formats the dumped messages with the specified
                        formatter and exits.
  --download-past-media
                        download past media instead of dumping new data (files
                        that were seen before but not downloaded).

telegram-export vs telegram-history-dump

(For brevity we’ll just refer them to as “export” and “dump”)

  • SQLite instead of jsonlines allows for far more powerful queries and better efficiency but loses compatibility with text-manipulating UNIX tools as the data is not stored as text (or even more powerful tools like jq).

  • export’s stored data is less complicated than dump’s json dumps

  • Support for saving the history of a person or other dialog, so you can see e.g. what their name was over time.

  • Using telethon instead of tg-cli allows support for newer Telegram features like pinned messages, admin logs, user bios, first-class support for supergroups and avoids the tg-cli bug which made dumping channels impossible, as well as several other tg-cli annoyances (such as being somewhat harder to install).

  • Newer and less mature than dump

  • No dedicated analysis program yet (dump has telegram-analysis and pisg)

  • Implemented features which dump does not support (incomplete list):

    • Admin logs

    • Dumping Users/Channels/Chats as their own entities, not just as message metadata. This allows things like user bios, channel descriptions and profile pictures.

    • Pinned messages (dump kind of supports this, but only by saving a message replying to the pinned message with text ‘pinned the message’)

    • Participant lists

  • Closer interaction with the Telegram API theoretically allows big speed improvements (Practical comparison of times soon™)

  • export’s database file is bound to a user (like dump), and the program will exit if you login as another person to avoid mixing things up. If you do use export with multiple users, you should specify a different database for each user. You can easily select different config files through --config-file.

Limitations

  • Still being worked on. It dumps things, but the schema may change and we won’t support old schema transitions.

  • Relies on Telethon <https://github.com/LonamiWebs/Telethon>, which is still pre-1.0.

  • Certain information is not dumped for simplicity’s sake. For example, edited messages won’t be re-downloaded and there is currently no support for multiple versions of a message in the db. However, this shouldn’t be much of an issue, since most edits or deletions are legit and often to fix typos.

What does it do? Is it a bot?

It uses the Telegram API (what Telegram apps use), so it has access to everything a Telegram app can do. This is why you need an API ID and API hash to use it, and why one from Telegram Desktop will work. Since normal clients need to download messages, media, users etc to display them in-app, telegram-export can do the same, and save them into a nice database.

So no, it’s not really a bot, but it does use the same technology as userbots in order to work. As far as we know, it won’t get you banned from using Telegram or anything like that.

Installation from source

git clone this repository, then python3 setup.py install. You should also read through the Installation section for related notes.

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-export-1.8.2.tar.gz (37.3 kB view details)

Uploaded Source

Built Distribution

telegram_export-1.8.2-py3-none-any.whl (45.0 kB view details)

Uploaded Python 3

File details

Details for the file telegram-export-1.8.2.tar.gz.

File metadata

  • Download URL: telegram-export-1.8.2.tar.gz
  • Upload date:
  • Size: 37.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2

File hashes

Hashes for telegram-export-1.8.2.tar.gz
Algorithm Hash digest
SHA256 c6f328825dafb867ebede007e1f94dbb8edd68d5029d7d3942d4e71457f17b35
MD5 06986054872bf0992b2adbde351a71a1
BLAKE2b-256 047139b0f5f18132e7a70a98daaab469c8fedd04eb30c3c417c41c0cfcff162a

See more details on using hashes here.

File details

Details for the file telegram_export-1.8.2-py3-none-any.whl.

File metadata

  • Download URL: telegram_export-1.8.2-py3-none-any.whl
  • Upload date:
  • Size: 45.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2

File hashes

Hashes for telegram_export-1.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4a8ad6bb0e0018259e2411e61f6bfc76769c65b434e0294b7970b65ed367fe55
MD5 e9545d8c938ca0ca329c2a384dfc4e30
BLAKE2b-256 20dc229a0de75d8321b51cab830bb0c324f67918d4adef6292d19185aab84073

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page