lib for file management with telegram api
Project description
📡 TDS2 - Telegram Data Storage System
TDS2 (Telegram Data Storage System) is a powerful Python library that leverages Telegram's infrastructure as a cloud storage backend. Upload, download, manage, and track files using Telegram channels with automatic logging and progress tracking.
🌟 Features
- 📤 File Upload: Upload files of any size to Telegram channels with progress bars
- 📥 File Download: Download files using message IDs
- 🗑️ File Management: Delete messages and manage your storage
- 📊 Automatic Logging: Optional JSON-based logging with metadata tracking
- 📈 Storage Analytics: Track total storage size, file counts, and deletion status
- ⚡ Async Support: Built on Telethon for efficient async operations
- 🔒 Private Storage: Use your own Telegram channels as secure cloud storage
📦 Installation
pip install tds2
🚀 Quick Start
from tds2 import tds2client
# Initialize client (without logging)
client = tds2client(
api_id='YOUR_API_ID',
api_hash='YOUR_API_HASH',
group_chat_id='YOUR_CHANNEL_ID'
)
# Upload a file
response = client.upload('/path/to/file.pdf')
print(f"Uploaded! Message ID: {response.id}")
# Download a file
file_path = client.download(response.id)
print(f"Downloaded to: {file_path}")
# Delete a file
client.delete(response.id)
# Get last message ID
last_id = client.get_last()
📝 With Logging Enabled
Enable automatic JSON logging to track all uploads and deletions:
# Initialize client with logging
client = tds2client(
api_id='YOUR_API_ID',
api_hash='YOUR_API_HASH',
group_chat_id='YOUR_CHANNEL_ID',
logfile='my_storage.json'
)
# All operations are now automatically logged
response = client.upload('document.pdf')
# Get storage statistics
summary = client.get_log_summary()
print(f"Total storage used: {summary['total_size_mb']} MB")
print(f"Active files: {summary['active_files']}")
print(f"Deleted files: {summary['deleted_files']}")
🔑 Getting Started
1. Get Telegram API Credentials
- Visit https://my.telegram.org
- Log in with your phone number
- Go to "API Development Tools"
- Create a new application
- Save your
api_idandapi_hash
2. Create a Telegram Channel
- Create a new Telegram channel (private or public)
- Get the channel ID (use a bot like @raw_data_bot or @username_to_id_bot)
- Make sure your account has admin rights in the channel
3. Use TDS2
from tds2 import tds2client
client = tds2client(
api_id='12345678',
api_hash='abcdef1234567890abcdef1234567890',
group_chat_id='-1001234567890',
logfile='storage.json' # Optional
)
📚 Core Functions
upload(file_path)
Upload a file to your Telegram channel. Returns a message object with the upload details.
download(message_id)
Download a file using its Telegram message ID. Returns the path to the downloaded file.
delete(message_id)
Delete a message/file from the Telegram channel.
get_last()
Get the message ID of the last message in the channel.
get_log_summary()
Get statistics about your storage (only available when logging is enabled).
🗂️ JSON Logging Structure
When logging is enabled, TDS2 creates a JSON file with the following structure:
{
"total_size": 1048576000,
"files": {
"123": {
"message_id": 123,
"file_name": "document.pdf",
"size_bytes": 1048576,
"size_mb": 1.0,
"upload_date": "2025-12-24T10:30:00.000000",
"deletion_date": null,
"deleted": false
}
}
}
Log Fields Explained:
total_size: Total bytes of non-deleted filesmessage_id: Telegram message IDfile_name: Original filenamesize_bytes: File size in bytessize_mb: File size in megabytes (rounded)upload_date: ISO 8601 timestamp of uploaddeletion_date: ISO 8601 timestamp of deletion (if deleted)deleted: Boolean indicating deletion status
💡 Use Cases
- Personal Cloud Storage: Use Telegram as unlimited cloud storage
- Backup System: Automated backup of important files
- File Sharing: Share large files through Telegram
- Media Archive: Store photos, videos, and documents
- Data Migration: Transfer files between systems
- Automated Workflows: Integrate with scripts and automation
⚙️ Advanced Configuration
Custom Session Name
The library uses Telethon's session management. By default, it creates a session file named anon.session. This file stores authentication data so you don't need to log in every time.
Progress Tracking
All uploads automatically display a progress bar using tqdm, showing real-time upload speed and ETA.
🔒 Security Considerations
- Keep your
api_idandapi_hashsecure - Use private channels for sensitive data
- Consider encrypting files before upload for additional security
- The session file contains authentication data - keep it secure
- Logging files may contain sensitive filenames - protect them appropriately
📊 Storage Limits
- Telegram allows files up to 2GB per file
- No limit on total storage (as of 2025)
- Upload/download speeds depend on your connection and Telegram's servers
🛠️ Requirements
- Python 3.7+
- telethon
- tqdm
All dependencies are automatically installed with pip.
🤝 Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🔗 Links
- Documentation - Detailed function documentation
- Telethon Documentation - Underlying Telegram library
- Telegram API - Official Telegram API docs
⚠️ Disclaimer
This library is for educational and personal use. Respect Telegram's Terms of Service and API usage limits. The developers are not responsible for any misuse of this library.
📞 Support
For issues, questions, or suggestions, please open an issue on GitHub.
Made with ❤️ by the TDS2 community
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 tds2-0.2.1.tar.gz.
File metadata
- Download URL: tds2-0.2.1.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c30e6ad31b217b7624bbfdca3697baaa9b2454a89ba4564aefb2e5cc56101f26
|
|
| MD5 |
9b8f1eb9f7212e85906a65c442ff1eef
|
|
| BLAKE2b-256 |
27fec9f9cdeb973a3b02494efbe80b7ec397b3839a6d5e87a63041ebd67abaef
|
File details
Details for the file tds2-0.2.1-py3-none-any.whl.
File metadata
- Download URL: tds2-0.2.1-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cdf2655b47c61b8a69f12feeea5817a23a8109eca5d0e31e8b5151e6e29e25d3
|
|
| MD5 |
92bcd1c1cd0aa621f87578d72df873ec
|
|
| BLAKE2b-256 |
94bbe0a1485d3379442a9574c57dd17108e2c2b5a6139156ed7a67191d8cc74b
|