Async MTProto client library for Telegram user accounts and bots
Project description
sent
sent is an async MTProto client library for Telegram. It speaks the raw Telegram protocol and supports both user accounts and bots with an event-driven, developer-friendly API.
Features
- Async MTProto 2.0 — encryption, sessions, RPC with
RpcResult/MsgContainerhandling - User accounts and bots — phone + code login, SRP 2FA, bot token, QR login
- Event system —
NewMessage,MessageDeleted,MessageRead,CallbackQuery,ChatAction,UserUpdate,Album - Friendly API —
send_message,send_file,get_dialogs,iter_messages,conversation() - TL layer 225 — auto-generated from the latest Telegram schema
- Session storage — SQLite (with entity cache), StringSession, or in-memory
- Transport — TCP abridged / intermediate / full, SOCKS5 proxy support
Installation
pip install sent
Optional extras for faster cryptography:
pip install sent[fast] # cryptg (recommended for production)
pip install sent[crypto] # pycryptodome fallback
For local development:
git clone https://github.com/kalanakt/sent.git
cd sent
uv sync --all-extras
Quick start
Get your api_id and api_hash from my.telegram.org.
Bot
import asyncio
import os
from sent import TelegramClient, events
API_ID = int(os.environ["TELEGRAM_API_ID"])
API_HASH = os.environ["TELEGRAM_API_HASH"]
BOT_TOKEN = os.environ["TELEGRAM_BOT_TOKEN"]
async def main():
client = TelegramClient("echo_bot", API_ID, API_HASH)
@client.on(events.NewMessage)
async def handler(event):
await event.reply(event.text)
await client.start(bot_token=BOT_TOKEN)
await client.run_until_disconnected()
asyncio.run(main())
See examples/echo_bot.py for a complete echo bot.
User account
import asyncio
import os
from sent import TelegramClient, events
API_ID = int(os.environ["TELEGRAM_API_ID"])
API_HASH = os.environ["TELEGRAM_API_HASH"]
async def main():
client = TelegramClient("my_account", API_ID, API_HASH)
@client.on(events.NewMessage(incoming=True))
async def handler(event):
await event.reply("Hello!")
await client.start() # prompts for phone, code, and 2FA when needed
me = await client.get_me()
print(f"Logged in as {me.first_name}")
await client.run_until_disconnected()
asyncio.run(main())
See examples/user_bot.py for a fuller user-account example.
Conversation helper
async with client.conversation("username") as conv:
await conv.send_message("What's your name?")
response = await conv.get_response()
print(response.text)
Development
uv sync --group test
uv run pytest test/ -v
Run benchmarks:
uv run python bench/run.py
Regenerate TL types after updating the schema:
python -m sent._codegen.generate
See CONTRIBUTING.md for full contributor and release guidelines.
Project links
- Source: https://github.com/kalanakt/sent
- Issues: https://github.com/kalanakt/sent/issues
- PyPI: https://pypi.org/project/sent/
License
MIT — see LICENSE.
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 sent-1.0.0.tar.gz.
File metadata
- Download URL: sent-1.0.0.tar.gz
- Upload date:
- Size: 365.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1a61ccc7fc4c8daf9ba40415f5ebf1ed5faeebc9cfa077dcb7605ef14d0396f
|
|
| MD5 |
d33eb82d9db67350750627d00da06032
|
|
| BLAKE2b-256 |
965277c1106aa7a8c35b54502efde1ea62348283aff47ffa890ed3e7b2294964
|
Provenance
The following attestation bundles were made for sent-1.0.0.tar.gz:
Publisher:
publish.yml on kalanakt/sent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sent-1.0.0.tar.gz -
Subject digest:
b1a61ccc7fc4c8daf9ba40415f5ebf1ed5faeebc9cfa077dcb7605ef14d0396f - Sigstore transparency entry: 1732127484
- Sigstore integration time:
-
Permalink:
kalanakt/sent@321508bc03885ec88714ad4904a2e31bdc07db0d -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/kalanakt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@321508bc03885ec88714ad4904a2e31bdc07db0d -
Trigger Event:
release
-
Statement type:
File details
Details for the file sent-1.0.0-py3-none-any.whl.
File metadata
- Download URL: sent-1.0.0-py3-none-any.whl
- Upload date:
- Size: 409.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
614872f1c94c8f63ab42a84e3217d52e52758a06e47dd27bdd9b2436296a1319
|
|
| MD5 |
04189ff393c94fd49a464ae6e1d8fda5
|
|
| BLAKE2b-256 |
b720b54ec206b05bbc9493a9ccc3b63810d33c8f24d73450de8c8a5744152ea8
|
Provenance
The following attestation bundles were made for sent-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on kalanakt/sent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sent-1.0.0-py3-none-any.whl -
Subject digest:
614872f1c94c8f63ab42a84e3217d52e52758a06e47dd27bdd9b2436296a1319 - Sigstore transparency entry: 1732127540
- Sigstore integration time:
-
Permalink:
kalanakt/sent@321508bc03885ec88714ad4904a2e31bdc07db0d -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/kalanakt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@321508bc03885ec88714ad4904a2e31bdc07db0d -
Trigger Event:
release
-
Statement type: