A Telegram-native embedded database for Telegram bots
Project description
🧠 What is pyteledb?
pyteledb is a Telegram-native persistence abstraction that uses Telegram itself as the storage layer. No external databases required — just your bot and a Telegram channel or group.
Key Concepts
- Telegram channel/group = your database
- Pinned message = root index
- Messages = records
- Bot API only — no MTProto, no user accounts
✨ Features
- 🔌 Zero external dependencies for storage — Telegram IS the database
- 🚀 Async-first design with
httpx - 💾 Optional local caching (memory or SQLite) for performance
- 🔒 Soft locking for write coordination
- 📦 Versioned records with optimistic concurrency
- 🔧 Crash-resilient with repair tools
- 📊 Built-in metrics and observability
📦 Installation
pip install pyteledb
# With SQLite cache support
pip install pyteledb[sqlite]
🚀 Quick Start
import asyncio
from pyteledb import TelegramDatabase, DatabaseConfig
async def main():
config = DatabaseConfig(
bot_token="YOUR_BOT_TOKEN",
chat_id=-100123456789, # Your channel/group ID
db_name="my_database",
)
async with TelegramDatabase(config) as db:
# Initialize (creates root index if not exists)
await db.initialize()
# Insert a record
record = await db.insert({
"user_id": 12345,
"name": "Alice",
"score": 100,
})
print(f"Created record: {record.id}")
# Update
await db.update(record.id, {
"user_id": 12345,
"name": "Alice",
"score": 150, # New high score!
})
# Get database info
info = await db.info()
print(f"Total records: {info['record_count']}")
asyncio.run(main())
📁 Project Structure
pyteledb/
├── core/ # Database logic (TelegramDatabase, Record, RootIndex)
├── telegram/ # Bot API client (messages, files, pins)
├── storage/ # Serialization, checksums, versioning
├── cache/ # Memory and SQLite caching
├── ops/ # Rate limiting, write queue, metrics
└── utils/ # Logging, time, ID generation
⚡ Performance Model
pyteledb is designed for small to medium Telegram bots with predictable workloads:
- Never scans full chat history — fetches only required message IDs
- Uses local cache for frequently accessed records
- Rate-limit aware with automatic throttling
- Prefers
editMessageoversendMessagefor updates
🛡️ Consistency & Safety
Telegram provides no transactions, so pyteledb implements:
- Record versioning for optimistic concurrency
- Soft locks for write coordination
- Idempotent, retry-safe writes
- Repair tools for crash recovery
🎯 Target Use Cases
- ✅ Small to medium Telegram bots
- ✅ Developer tooling
- ✅ Predictable workloads
- ✅ Human-inspectable data
🚫 Not Designed For
- ❌ High-throughput applications
- ❌ Complex queries (SQL/NoSQL parity)
- ❌ Multi-service orchestration
📚 Documentation
📄 License
This project is licensed under the GPL-3.0 License — see the LICENSE file for details.
🤝 Contributing
Contributions are welcome! Please read our Contributing Guide first.
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 pyteledb-0.1.0.tar.gz.
File metadata
- Download URL: pyteledb-0.1.0.tar.gz
- Upload date:
- Size: 59.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c09052c320d66740958842aeb4dd9366a9501592d4922fe19428498fe0bc900
|
|
| MD5 |
6cd87e019537feacecc21893ee41f213
|
|
| BLAKE2b-256 |
fc65747750c92eaa59f2233a8d45a4212ba62944f3dee6a460cb78f4d0d7f7af
|
File details
Details for the file pyteledb-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyteledb-0.1.0-py3-none-any.whl
- Upload date:
- Size: 62.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee87ef43ed17b3edbf7d9598bac9b955f3cb8837a5f6c990a58cdacaa7f87861
|
|
| MD5 |
8db53a4bb7046ca5e2786c8dd6980b41
|
|
| BLAKE2b-256 |
c867253fb447a00bb6fb05ecd8a7f1fc1e8fdd74a88e6ab8b129ccd6d9037a49
|