telegram_grep
Search Telegram messages from the command line.
By default telegram-grep searches private one-to-one human chats only. It skips
groups, channels, and bot dialogs unless you opt in.
Install
python -m pip install .
For development:
python -m pip install -e '.[dev]'
Authentication
This uses Telegram MTProto through Telethon, not the Bot API. A Telegram bot token cannot search your personal private chats.
Required environment:
export TG_API_ID=123456
export TG_API_HASH=0123456789abcdef0123456789abcdef
Session options:
# Recommended for automation: Telethon StringSession token.
export TG_SESSION='...'
# Or a local session file. Default: ./telegram_grep.session
export TG_SESSION_FILE=/path/to/telegram_grep.session
If neither session option exists, Telethon will create/use telegram_grep.session
and may prompt interactively for login. You can also set TG_PHONE for the first
login.
Usage
Search private human chats:
telegram-grep 'wikimedia commons bot'
Include groups:
telegram-grep --groups 'wikimedia commons bot'
Search only groups:
telegram-grep --groups-only 'wikimedia commons bot'
Include bot private dialogs:
telegram-grep --include-bots 'wikimedia commons bot'
Print JSON Lines:
telegram-grep --json 'wikimedia commons bot'
Show neighboring messages:
telegram-grep --context 2 'wikimedia commons bot'
Related Documentation
- Telethon documentation
- Telethon sessions
- Telegram API development tools
- Telegram MTProto API
- PyPI Trusted Publishing
Publishing
CI publishes to PyPI on every push to main after tests pass.
PyPI must have a Trusted Publisher configured for:
- owner/repository:
vitaly-zdanevich/telegram_grep - workflow:
.github/workflows/ci.yml - environment:
pypi
Versions are derived from Git tags/commits through hatch-vcs, because PyPI
does not allow re-uploading the same version.
Metadata
Release files for telegram-grep 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| telegram_grep-0.1.1.tar.gz | 9.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| telegram_grep-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.2 kB
Release files / telegram_grep-0.1.1.tar.gz
| Download URL | telegram_grep-0.1.1.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
107c06c92acbfdd56c66b5cf1125be3a07ad03e9c9a605d342a0145e4702c25a
|
|
BLAKE2b-256 checksum How to use checksums |
be067d9ba2d67e8f2314d74554a4eab8625461e9e2ad02a1e9b3ce50c064d8fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jul 7, 2026.
Transparency logRelease files / telegram_grep-0.1.1-py3-none-any.whl
| Download URL | telegram_grep-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c22503765d57f6f7c3d29791912012ccdc99082eed5efc3a1dbc21ef08c13b35
|
|
BLAKE2b-256 checksum How to use checksums |
1e182c942a2b311e5da1646a8c0979a1aa6c7336c6254a198d5edb76eaf1189b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jul 7, 2026.
Transparency log