Skip to main content

A user-friendly library based on Telethon, with additional features and easier usage.

Project description

🚀 Teloxi: Based on Telethon, with additional features and easier usage

PyPI - Version Python Versions License Downloads

🛠️ Version: 1.0.2

🌟 Introduction

Teloxi is a lightweight, easy-to-use library based on Telethon, with additional features and easier usage.

✨ Features

Teloxi is a user-friendly Python library built on top of Telethon, offering enhanced Telegram automation capabilities. Key features include:

  • 🖥️ Multi-session management: Easily store, retrieve, update, and delete multiple Telegram accounts.
  • 🔑 Login code handling: Automatically fetch Telegram login codes via BotFather interaction.
  • 🗄️ Database integration: Store sessions in SQLite or other supported storage backends.
  • 📊 Query filtering & sorting: Retrieve sessions using advanced filtering, ordering, and limit options.
  • Asynchronous support: Fully async functions for high-performance Telegram operations.
  • 📱 Multi-platform Device support: Compatible with Telegram Device for Android, Windows, Linux, macOS, and iOS.
  • 🛠️ Extensible & open-source: Easy to customize and contribute additional features.

Designed to simplify Telegram automation and make multi-account management effortless.


📚 Requirements


🔧 Installation

Install teloxi via pip:

pip install teloxi

Or install from source:

git clone https://github.com/abbas-bachari/teloxi.git
cd teloxi
pip install .

💡 Quick Start

import asyncio
from dbflux import Sqlite
from proxa import ProxyManager
from teloxi import TeloxiClient,Device,Storage


proxa=ProxyManager(['http://127.0.0.1:10808','socks5://127.0.0.1:1080'])
DB=Storage(Sqlite('sessions.ses'))


proxy=proxa.get_working_proxy()

async def main():
    session_id='+19223338123'

    
    client=TeloxiClient(
                        session_id=session_id, 
                        database=DB,
                        device=Device.TelegramAndroid.Generate(),
                        proxy=proxy.for_telethon
                        )
    

    await client.connect()
   
    is_auth=await client.is_user_authorized()
    if not is_auth:
        await client.start(phone=p)
  
    
    await client.PrintSessions()
    

    me=await client.get_full_me()

    print(f"Phone    : {me.phone}")
    print(f"User ID  : {me.id}")
    print(f"Username : {me.username or ''}")
    print(f"Full Name: {me.first_name} {me.last_name or ''}")
    print(f"About    : {me.about}")
    
   

    chat_info,error,is_joined= await client.join_chat('https://t.me/+2Rllq4qAlvk4MjM0')
    if is_joined:
       
       print(f"Success join to {chat_info.__class__.__name__}: {chat_info.title } ")
    else:
        print(f"{ error.__class__.__name__}: {error}")
        
    
    await client.disconnect()

    
if __name__=="__main__":
    asyncio.run(main())

💻 Output:

|---------+---------------------+----------+------------+--------+--------------------------+--------------|
|         |       Device        | Platform |   System   | API_ID |         App name         | Official App |
|---------+---------------------+----------+------------+--------+--------------------------+--------------|
| Current | Samsung Galaxy S25  | Android  |  13 (33)   |   6    | Telegram Android 11.14.1 |      ✔       |
|---------+---------------------+----------+------------+--------+--------------------------+--------------|
|    1    | Redmi Redmi Note 9S | Android  |  12 (31)   |   6    | Telegram Android 11.14.1 |      ✔       |
|    2    |  Samsung Galaxy S3  | Android  | 8.0 O (26) |   6    | Telegram Android 11.13.2 |      ✔       |
|---------+---------------------+----------+------------+--------+--------------------------+--------------|
Phone    : +19223338123
User ID  : 46567598
Username : usernam_2
Full Name: user-2 telegram
About    : None
Success join to Channel: Test Channel 

🗄️ Connect to Saved Sessions

import asyncio
from dbflux import Sqlite
from proxa import ProxyManager
from teloxi import TeloxiClient,Device,Storage,Account


proxa=ProxyManager(['http://127.0.0.1:10808','socks5://127.0.0.1:1080'])
DB=Storage(Sqlite('sessions.ses'))

async def main():
    proxy=proxa.get_working_proxy()
    accounts: list[Account]=DB.get(limit=5,conditions=[Account.status=='ACTIVE'])
    for account in accounts:
        
        client=TeloxiClient(session_id=account.session_id,database=DB,proxy=proxy.for_telethon) 
        await client.connect()
        
        
        
        me=await client.get_me()
        
        if me:
            print(f"Phone    : {me.phone}")
            print(f"User ID  : {me.id}")
            print(f"Username : {me.username or ''}")
            print(f"Full Name: {me.first_name} {me.last_name or ''}")
            print("="*30)
            

        await client.disconnect()
        await asyncio.sleep(5)

if __name__=="__main__":
    asyncio.run(main())

💻 Output:

Phone    : 9812356488
User ID  : 46567598
Username : username_1
Full Name: user-1
==============================
Phone    : +19223338123
User ID  : 5865442887
Username : usernam_2
Full Name: user-2 telegram
==============================
Phone    : 1923155554
User ID  : 8320041566
Username : usernam_2
Full Name: user-3
==============================

🔑 Get Login Code

async def code_callback(message, code):
    if code:
        print(f"Received login code: {code}")
    else:
        print(message)


async def main():
    proxy = proxa.get_working_proxy()
    session_id = '+1987654321'

    client = TeloxiClient(
        session_id=session_id, 
        database=DB,
        proxy=proxy.for_telethon
    )

    await client.connect()
   
    is_auth = await client.is_user_authorized()
    if is_auth:
        code = await client.get_login_code(callback=code_callback)
        if code:
            print(f"Login code successfully retrieved: {code}")
        else:
            print("Failed to get login code.")


if __name__ == "__main__":
    asyncio.run(main())

💻 Example Output

Login to +1987654321 now to grab your code!
Received login code: 86305
Login code successfully retrieved: 86305

🗄️ Manage Saved Sessions

# Initialize sessions manager
DB = Storage(base_db=Sqlite('sessions.ses'))
session_id = '+1987654321'

# ------------------------------
# Get a single session by session_id
accounts: list[Account] = DB.get(conditions=[Account.session_id == session_id])
if accounts:
    account = accounts[0]
    print(f"Name: {account.first_name:<15} | Is bot: {'YES' if account.is_bot else 'NO':<3} | status: {account.status}")

# ------------------------------
# Get all sessions
accounts: list[Account] = DB.get()
for account in accounts:
    print(f"Name: {account.first_name:<15} | Is bot: {'YES' if account.is_bot else 'NO':<3} | status: {account.status}")

# ------------------------------
# Get active sessions
active_sessions: list[Account] = DB.get(conditions=[Account.status == "ACTIVE"])

# Get inactive sessions
inactive_sessions: list[Account] = DB.get(conditions=[Account.status == "INACTIVE"])

# Get bot sessions
bot_sessions: list[Account] = DB.get(conditions=[Account.is_bot == True])

# ------------------------------
# Get first 5 active non-bot sessions
first_5_sessions: list[Account] = DB.get(limit=5, conditions=[Account.status == "ACTIVE", Account.is_bot == False])

# ------------------------------
# Get random sessions (example: 3 active non-bot)
random_sessions: list[Account] = DB.get(limit=3, conditions=[Account.status=="ACTIVE", Account.is_bot==False], random=True)

# ------------------------------
# Delete all bot sessions
deleted_bots = DB.delete(conditions=[Account.is_bot == True])
print(f'Deleted {deleted_bots} bot sessions!')

# Delete all sessions
deleted_all = DB.delete(conditions='ALL')
print(f'Deleted {deleted_all} sessions!')

# Delete inactive sessions
deleted_inactive = DB.delete(conditions=[Account.status == "INACTIVE"])
print(f'Deleted {deleted_inactive} inactive sessions!')

# ------------------------------
# Update bot sessions to inactive
updated_bots = DB.update(conditions=[Account.is_bot == True], data={'status':'INACTIVE'})
print(f'Updated {updated_bots} bot sessions!')

# Update a specific session by phone
updated_one = DB.update(conditions=[Account.phone == '+9811111'], data={'status':'INACTIVE'})
print(f'Updated {updated_one} session!')

💻 Example Output

Name: user-1         | Is bot: NO  | status: ACTIVE
Name: user-2         | Is bot: YES | status: INACTIVE
Name: user-3         | Is bot: NO  | status: ACTIVE
...
Deleted 2 bot sessions!
Deleted 10 sessions!
Updated 3 bot sessions!
Updated 1 session!

👤 About the Author

Abbas Bachari / عباس بچاری – Developer & Maintainer of Teloxi

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

teloxi-1.0.2-py3-none-any.whl (65.5 kB view details)

Uploaded Python 3

File details

Details for the file teloxi-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: teloxi-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 65.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for teloxi-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 77d2619f1fce35fcbb67f41af11db602e1f1fb2eb27249567ab3623ef78236af
MD5 fe424f9abf60b36016c05f530315007f
BLAKE2b-256 49f91deb462244f1e50193b6bc8a2fa71bdbd1ac348c744262556cdb0daf9b49

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page