A Python library for Telegram automation and group management
Project description
archbyte
A Python library for Telegram automation and group management.
Author: Cyrus Arch
Installation
pip install archbyte
Features
- Session-based authentication with persistent login
- Bulk leave operations with rate limiting
- Whitelist protection for important chats
- Keyword-based spam detection and auto-leave
- Activity logging and tracking
- Async/await support with context managers
Quick Start
import asyncio
from archbyte import Telecemper
async def main():
client = Telecemper(
api_id='YOUR_API_ID',
api_hash='YOUR_API_HASH',
phone_number='+1234567890'
)
# First time authentication
await client.request_code()
code = input("Enter code: ")
message, session = await client.authenticate(code)
# Save session for future use
print(f"Session: {session}")
await client.disconnect()
asyncio.run(main())
Configuration
Get your API credentials from https://my.telegram.org
Required:
api_id- Telegram API IDapi_hash- Telegram API hashphone_number- Phone number with country code
Usage Examples
Using saved session
client = Telecemper(
api_id='YOUR_API_ID',
api_hash='YOUR_API_HASH',
phone_number='+1234567890',
session_string='YOUR_SAVED_SESSION'
)
await client.login_with_session()
Whitelist management
# Add chats to whitelist (by ID, username, or title)
client.add_to_whitelist(123456789, "family_group", "Work Team")
# Load from file
client.load_whitelist_from_file("whitelist.txt")
# Save to file
client.save_whitelist_to_file("whitelist.txt")
# View protected chats
protected = client.get_whitelist()
Bulk operations
# Leave all chats except whitelisted
summary = await client.leave_all_chats(
delay_range=(1, 5),
respect_whitelist=True
)
print(f"Left: {summary['left_count']}")
print(f"Protected: {summary['skipped_count']}")
Spam detection
# Enable auto-leave on spam keywords
keywords = ['free giveaway', 'get rich quick', 'limited offer']
await client.enable_spam_detection(keywords)
# Disable spam detection
client.disable_spam_detection()
List all chats
chats = await client.list_all_chats()
for chat in chats:
status = "Protected" if chat['protected'] else "Unprotected"
print(f"{chat['title']}: {status}")
View logs
logs = client.get_logs()
print(logs['leave_log'])
print(logs['join_log'])
print(logs['activity_log'])
Whitelist File Format
Create a whitelist.txt file with one identifier per line:
# Comments start with #
123456789
family_chat
Work Team
987654321
API Reference
Authentication Methods
request_code()- Request verification codeauthenticate(code)- Authenticate with code, returns session stringlogin_with_session()- Login with saved session
Whitelist Methods
add_to_whitelist(*identifiers)- Add chats to whitelistremove_from_whitelist(*identifiers)- Remove from whitelistclear_whitelist()- Clear all whitelist itemsget_whitelist()- Get list of whitelisted itemsload_whitelist_from_file(filepath)- Load from filesave_whitelist_to_file(filepath)- Save to file
Operation Methods
leave_all_chats(delay_range, respect_whitelist)- Leave all groups/channelslist_all_chats(include_protected)- List all chats with statusenable_spam_detection(keywords)- Enable auto-leave on spamdisable_spam_detection()- Disable spam detectionget_logs()- Retrieve activity logs
Utility Methods
start()- Start the clientdisconnect()- Disconnect the client
Context Manager
async with Telecemper(api_id, api_hash, phone, session) as client:
await client.leave_all_chats()
# Automatically disconnects on exit
Logging
Configure Python logging to see detailed activity:
import logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
Best Practices
- Store session strings securely, never commit to version control
- Use delays between operations to respect rate limits
- Always whitelist important chats before bulk operations
- Monitor logs for unexpected behavior
- Use context managers for automatic cleanup
License
MIT License,
Project details
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 archbyte-0.2.1.tar.gz.
File metadata
- Download URL: archbyte-0.2.1.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baf6e3b663dd51e04f0ed7ed0365f8cd4768ac935a35e372c01da1d633cdd3ff
|
|
| MD5 |
6d2351f9c686add902fb4bcc22617835
|
|
| BLAKE2b-256 |
e9b2a6df4ae1c9dcc6144ab523bb1332e6229f8c61986f268c41a191e5ea8e25
|
File details
Details for the file archbyte-0.2.1-py3-none-any.whl.
File metadata
- Download URL: archbyte-0.2.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4f5c40707f4dd023663db6aa52ec8a8bcfef7098b6bd07ddda8bfc69530e97c
|
|
| MD5 |
bbee934b613b815a17beba8b51c6f08c
|
|
| BLAKE2b-256 |
4971ce51a75d065e14ddc7b84a53bff9c833c8538f48650fe338c05cc16ef900
|