Dump Telegram channel messages to a local SQLite database for searching and archival
Project description
Telememo
Telememo is a Python CLI tool to dump Telegram channel messages to a local SQLite database for easy searching and archival.
Features
- Dump all messages from Telegram channels to SQLite
- Search messages by text content
- Incremental sync to fetch only new messages
- Built with modern Python async/await
- Lightweight and easy to use
Requirements
- Python 3.10 or higher
- Telegram API credentials (API ID and API hash from https://my.telegram.org)
- Your Telegram account (phone number) for authentication
Installation
Install from PyPI:
pip install telememo
Or as an isolated CLI tool with uv:
uv tool install telememo
From source (development)
- Clone the repository:
git clone https://github.com/reorx/telememo
cd telememo
- Install in editable mode:
pip install -e .
For development with testing tools:
pip install -e ".[dev]"
Configuration
Create a configuration file at ~/.config/telememo/config.py:
mkdir -p ~/.config/telememo
cp config.example.py ~/.config/telememo/config.py
Edit ~/.config/telememo/config.py with your credentials:
# Telegram API credentials (get from https://my.telegram.org)
TELEGRAM_API_ID = 12345678
TELEGRAM_API_HASH = "your_api_hash_here"
# Your phone number (optional, will be prompted if not set)
PHONE = "+1234567890"
# Default channel to use when -c/--channel-name is not specified
DEFAULT_CHANNEL = "example_channel"
# Optional: Configure multiple channels
CHANNELS = {
"tech_news": {
"id": "@technews",
"description": "Technology news channel"
},
}
Getting Telegram API Credentials
- Visit https://my.telegram.org
- Log in with your phone number
- Go to "API development tools"
- Create a new application
- Copy your
api_idandapi_hash
Authentication
Important: Telememo uses user authentication, not bot authentication, because Telegram bots cannot access historical channel messages.
When you run the CLI for the first time, you'll be prompted to:
- Enter your phone number (in international format, e.g., +1234567890)
- Enter the verification code sent to your Telegram app
- Optionally enter your 2FA password if enabled
Your session will be saved locally in ~/.local/share/telememo/telethon.session so you won't need to authenticate again. This session file is shared across all channels.
Usage
Dump channel messages
Dump all messages from a channel:
telememo -c @channelname dump-messages
Or use the default channel from config:
telememo dump-messages
Dump with a limit:
telememo -c @channelname dump-messages --limit 100
Sync new messages
Fetch only new messages since last sync:
telememo -c @channelname sync
Show channel information
telememo -c @channelname info
Search messages
Search within a specific channel:
telememo -c @channelname search "search term" --limit 20
Project Structure
telememo/
├── telememo/
│ ├── __init__.py
│ ├── types.py # Pydantic data models
│ ├── db.py # Database operations (Peewee ORM)
│ ├── telegram.py # Telegram client wrapper (Telethon)
│ ├── core.py # Business logic & scraper
│ └── cli.py # CLI commands (Click)
├── tests/
│ ├── conftest.py
│ └── test_integration.py
├── pyproject.toml
├── claude.md
└── README.md
Development
Running Tests
Run integration tests:
pytest tests/
Run with verbose output:
pytest -v tests/
Run specific test:
pytest tests/test_integration.py::test_get_channel_info_and_messages -v
Development Guidelines
See claude.md for detailed development guidelines and architecture principles.
Tech Stack
- Telethon: Telegram MTProto API client
- Peewee: Lightweight SQLite ORM
- Click: CLI framework
- Pydantic: Data validation
- pytest: Testing framework
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
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 telememo-0.1.0.tar.gz.
File metadata
- Download URL: telememo-0.1.0.tar.gz
- Upload date:
- Size: 47.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba2bf1bbbb3f4bfa5313dc824e08c4083993237334b8a9d5fe4882448c17da0a
|
|
| MD5 |
0114d4a12d705bca60261dede86c537e
|
|
| BLAKE2b-256 |
be2d8d011e8ae57885186282ab876d6b964a3d7d4f9996a7a9c04e80d674efec
|
File details
Details for the file telememo-0.1.0-py3-none-any.whl.
File metadata
- Download URL: telememo-0.1.0-py3-none-any.whl
- Upload date:
- Size: 44.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5451938cabb9a7598be3e919f9bc3a8c9bbf66ccbaf25c378f139185e09f8e6f
|
|
| MD5 |
f0391022e05c5af00af4ab83beeaa7dd
|
|
| BLAKE2b-256 |
318db7f8573d50a3fe010a15010d2a31dc44ef1e5ea2e0b0ff913362c1b95e5b
|