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.
- π€ 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
pip install tds2from 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()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']}")- 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
- 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
from tds2 import tds2client
client = tds2client(
api_id='12345678',
api_hash='abcdef1234567890abcdef1234567890',
group_chat_id='-1001234567890',
logfile='storage.json' # Optional
)Upload a file to your Telegram channel. Returns a message object with the upload details.
Download a file using its Telegram message ID. Returns the path to the downloaded file.
Delete a message/file from the Telegram channel.
Get the message ID of the last message in the channel.
Get statistics about your storage (only available when logging is enabled).
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
}
}
}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
- 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
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.
All uploads automatically display a progress bar using tqdm, showing real-time upload speed and ETA.
- 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
- 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
- Python 3.7+
- telethon
- tqdm
All dependencies are automatically installed with pip.
Contributions are welcome! Please feel free to submit issues and pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation - Detailed function documentation
- Telethon Documentation - Underlying Telegram library
- Telegram API - Official Telegram API docs
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.
For issues, questions, or suggestions, please open an issue on GitHub.
Made with β€οΈ by the TDS2 community