Skip to main content

telegram-tools

A local CLI for operating your own Telegram chats: find the real IDs of your groups, channels, and forum topics, search and export messages, and clear all messages out of forum topics without destroying the topics themselves.

Built on Telethon. Everything runs on your machine with your own Telegram API credentials — no server, no third party, nothing leaves your computer except the Telegram API calls you asked for.

What it does

  • discover — lists your chats, channels, and forum groups with their exact numeric IDs and every forum topic ID. The fastest way to answer "what is this chat's -100… ID and what are its topic IDs?"
  • search — searches messages by text, sender, date range, or topic, and prints a table or exports JSON/CSV.
  • clear-messages — deletes all messages inside selected forum topic(s) while preserving the topics and their IDs. Dry-run by default; deleting requires both --execute and typing DELETE at a prompt.
  • doctor — checks your local setup without printing any secrets.

What it doesn't do (on purpose)

  • No deleting or creating forum topics — topic IDs never change.
  • No media downloads.
  • No sending messages, no bots, no automation loops.
  • No cloud anything — credentials and session files stay in ~/.telegram-tools/.

Install

pipx install telegram-tools
# or
uv tool install telegram-tools

Or from source: pipx install git+https://github.com/banozz0/telegram-tools.git

Requires Python 3.11+.

Setup: your Telegram API credentials

The tool logs in as you (a user account, not a bot), so it needs a Telegram API key. One-time, about two minutes:

  1. Open https://my.telegram.org/apps and log in with your Telegram phone number.
  2. Fill in the short "Create new application" form (any name/short name works; platform "Desktop").
  3. Copy the App api_id (a number) and App api_hash (a hex string).
  4. Store them where the tool can find them:
mkdir -p ~/.telegram-tools
cat > ~/.telegram-tools/.env <<'EOF'
TELEGRAM_API_ID=123456
TELEGRAM_API_HASH=your-api-hash-here
EOF

Shell environment variables and a .env in the current directory also work, and win over ~/.telegram-tools/.env.

Treat the api_hash like a password. The first command you run starts Telethon's interactive login (phone number + code from Telegram); the resulting session file is stored in ~/.telegram-tools/ and reused afterwards. Log out anytime by deleting the session file in that directory (your .env can stay) — the session also shows under Telegram's Settings → Devices.

30 seconds of usage

# What are my chats and their IDs?
telegram-tools discover            # admin/managed chats only
telegram-tools discover --all      # everything

# Search a group
telegram-tools search --chat @mygroup --contains deploy

# Export a topic to JSON
telegram-tools search --chat @mygroup --topic 141 --output topic-141.json

# Clear a topic (dry-run first — this is the default)
telegram-tools clear-messages --chat @mygroup --topic 141
# Actually delete: needs --execute AND typing DELETE at the prompt
telegram-tools clear-messages --chat @mygroup --topic 141 --execute

Running telegram-tools with no arguments opens an interactive menu with the same operations.

discover output looks like:

Forum Groups
============
Example Forum
Chat ID: -1001234567890
Type: Forum Group
Admin: yes

Topics
--------------------------------------------
141   Deploys
217   Support
16    General

Safety model

Command Destructive?
discover, search, doctor No — read-only
clear-messages Yes — but only with --execute and a typed DELETE, only messages, never topics

clear-messages also verifies you actually hold the delete-messages permission in the chat before doing anything, skips topic starter messages, and handles Telegram flood-wait limits automatically.

Status

Stable for its three jobs; used regularly by its author. This is a solo project whose code was written by AI agents under review — issues are welcome, fixes are best-effort, and there is no support promise.

License

MIT. See LICENSE.

Download files

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

Source Distribution

telegram_tools-3.0.0.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

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

telegram_tools-3.0.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file telegram_tools-3.0.0.tar.gz.

File metadata

  • Download URL: telegram_tools-3.0.0.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for telegram_tools-3.0.0.tar.gz
Algorithm Hash digest
SHA256 76f4cc82048ef45d73233c3601eacc90e5eb412990f4bfd115bcba395af72e4a
MD5 5a159144497e37dcecb5856ccc05c87a
BLAKE2b-256 6f437b7e4a596e8f277b45a1e7d617872198c2406d6032c885ad4824e9acfcdd

See more details on using hashes here.

File details

Details for the file telegram_tools-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: telegram_tools-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for telegram_tools-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd476eea7374d82c562cc3b012e3ec4d629fcc250d4c8bd0ba2b9eb90931be87
MD5 9d18363552c7129945a1e2b61e7fb794
BLAKE2b-256 13d9653f3fd80cfba153fdd41887cd721f56f272a19ce80f32656a1070113456

See more details on using hashes here.

Release history Release notifications | RSS feed

3.6.0

2 files

3.4.1

2 files

3.4.0

2 files

3.3.0

2 files

3.2.0

2 files

3.1.0

2 files

This release

3.0.0 This release

2 files

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