Skip to main content

sent

PyPI version Python versions License: MIT CI

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 / MsgContainer handling
  • 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

License

MIT — see LICENSE.

Metadata

Release files for sent 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sent 1.0.0
File Size Uploaded
sent-1.0.0.tar.gz 365.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sent 1.0.0
File Interpreter ABI Platform
sent-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 775.6 kB

Release files / sent-1.0.0.tar.gz

Download URL sent-1.0.0.tar.gz
Size 365.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b1a61ccc7fc4c8daf9ba40415f5ebf1ed5faeebc9cfa077dcb7605ef14d0396f
BLAKE2b-256 checksum
How to use checksums
965277c1106aa7a8c35b54502efde1ea62348283aff47ffa890ed3e7b2294964
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 5, 2026.

Transparency log

Release files / sent-1.0.0-py3-none-any.whl

Download URL sent-1.0.0-py3-none-any.whl
Size 409.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
614872f1c94c8f63ab42a84e3217d52e52758a06e47dd27bdd9b2436296a1319
BLAKE2b-256 checksum
How to use checksums
b720b54ec206b05bbc9493a9ccc3b63810d33c8f24d73450de8c8a5744152ea8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page