A Python Telegram API Library , with official Telegram APIs.
Project description
Grampo
A Python Telegram API Library , with official Telegram APIs.
Installation
pip install Grampo
Quick start
import asyncio
from Grampo import (
TelegramApp,
Sessions,
CreateNewSession,
UseCurrentSession,
GrampoOptions
)
async def main():
telegram=TelegramApp(None,['http','127.0.0.1',10809],options=GrampoOptions())
# If there is a session, it will start it, otherwise,
# a new session will be created and saved.
await telegram.start_telegram('+9811122233')
me=await telegram.get_me()
print(me.first_name)
await telegram.disconnect()
if __name__=="__main__":
asyncio.run(main())
Connect to a saved session:
async def main():
telegram=TelegramApp('+9811122233',['http','127.0.0.1',10809])
await telegram.connect_telegram()
me=await telegram.get_me()
print(me.first_name)
await telegram.disconnect()
if __name__=="__main__":
asyncio.run(main())
Convert telethon session to tdata (desktop session):
async def main():
telegram=TelegramApp('+9811122233',['http','127.0.0.1',10809])
await telegram.start_telegram()
me=await telegram.get_me()
print(me.first_name)
# Use the current session
tdesk=await telegram.convert_to_tdata('E:/Telegram/TD-DATAS')
# # Create a new desktop session
# tdesk=await telegram.convert_to_tdata(
# output_dir='E:/Telegram/TD-DATAS',
# new_session=True,
# password='password')
# Use the current session
tdesk=await telegram.convert_to_tdata(output_dir='E:/Telegram/TD-DATAS',new_session=False)
await telegram.disconnect()
client:TelegramApp=await tdesk.ToTelethon(None,flag=UseCurrentSession,api=tdesk.api,proxy=['http','127.0.0.1',10809])
await client.connect()
await client.PrintSessions()
if __name__=="__main__":
asyncio.run(main())
Get login code:
import asyncio
from Grampo import TelegramApp
async def main():
telegram=TelegramApp('+9811122233',['http','127.0.0.1',10809])
await telegram.connect_telegram()
me=await telegram.get_me()
print(me.first_name)
print('Now apply for login in the TelegramApp app:')
code=await telegram.get_login_code()
print('Login Code: ', code)
await telegram.disconnect()
if __name__=="__main__":
asyncio.run(main())
Manage saved sessions:
SESSIONS=Sessions('sessions.ses')
session=SESSIONS.get_one(phone='+9811122233')
print(f"Name: {session.first_name:<15} | Is bot: {'YES' if session.is_bot else 'NO':<3} | status: {session.status}")
all_sessions=SESSIONS.get_many()
for session in all_sessions:
print(f"Name: {session.first_name:<15} | Is bot: {'YES' if session.is_bot else 'NO':<3} | status: {session.status}")
active_sessions=SESSIONS.get_many(status='ACTIVE')
inactive_sessions=SESSIONS.get_many(status='INACTIVE')
bot_sessions=SESSIONS.get_many(is_bot=True)
random_session=SESSIONS.get_one(random=True, status='ACTIVE',is_bot=False)
first_5_sessions=SESSIONS.get_many(limit=5, status='ACTIVE',is_bot=False)
delete_session=SESSIONS.delete(is_bot=True)
print(f'Deleted {delete_session} session !')
delete_all_session=SESSIONS.delete(delete_all=True)
print(f'Deleted {delete_all_session} session !')
delete_inactive_session=SESSIONS.delete(status='INACTIVE')
print(f'Deleted {delete_inactive_session} session !')
update_session=SESSIONS.update({'status':'INACTIVE'},is_bot=True)
print(f'Update {update_session} session !')
update_session=SESSIONS.update({'status':'INACTIVE'},phone='+9811111')
print(f'Update {update_session} session !')
Powered by Abbas Bachari.
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
grampo-1.0.0.tar.gz
(79.9 kB
view details)
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
grampo-1.0.0-py3-none-any.whl
(87.8 kB
view details)
File details
Details for the file grampo-1.0.0.tar.gz.
File metadata
- Download URL: grampo-1.0.0.tar.gz
- Upload date:
- Size: 79.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a62ed44e58aa12906b769b6293150e935a628be84b7cfa151f426e64212a4937
|
|
| MD5 |
539a8e11642abe435761fb4819df2058
|
|
| BLAKE2b-256 |
ba7ca8fb57f223bf87974107bd5be52e72678086952f2e2f6bc0160331195ac1
|
File details
Details for the file grampo-1.0.0-py3-none-any.whl.
File metadata
- Download URL: grampo-1.0.0-py3-none-any.whl
- Upload date:
- Size: 87.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd0842f241a2957c9f75080a2f23b2b9bf3eda0a431d2258c71ce8bc3d3d1780
|
|
| MD5 |
06d641f28687ee33a157d8682833cea3
|
|
| BLAKE2b-256 |
c41cf23f86e8b3a4411ab7a22c04c1b43ac0a6e9a5735ffed1747f9dd6fbce76
|