Python wrapper for ferogram, blazing-fast Rust MTProto library for Telegram.
Project description
ferogram-py
Python bindings for ferogram, a Telegram MTProto client written in Rust.
The Rust core handles crypto, transport, session management, and update processing. The Python layer gives you async/await methods and decorator-based event handlers with no boilerplate.
Built with PyO3 and maturin. Works on Linux, macOS, Windows, and Android (Termux).
Install
pip install ferogram
Pre-built wheels are available for:
| Platform | Arch |
|---|---|
| Linux (manylinux) | x86_64, aarch64 |
| macOS | x86_64, arm64 |
| Windows | x86_64 |
| Android / Termux | aarch64, x86_64 |
On Termux, pip install ferogram picks the correct Android wheel automatically.
Force local build
If the pre-built wheel does not work, or you want to compile for your exact machine:
# from PyPI source
pip install ferogram --no-binary ferogram
# from cloned repo
git clone https://github.com/ankit-chaubey/ferogram-py
cd ferogram-py
pip install . --no-binary ferogram
Termux source build prerequisites:
pkg install rust clang python
pip install ferogram --no-binary ferogram
Quick start
from ferogram import Client, filters
app = Client("mybot", bot_token="123:TOKEN")
@app.on_message(filters.command("start"))
async def start(client, message):
await message.reply("Hello!")
app.run()
Handlers
ferogram uses decorator-based handlers. Each handler receives the Client and the update object.
@app.on_message(filters.command("start"))
async def on_start(client, message):
await message.reply("Hello!")
@app.on_message(filters.command("help"))
async def on_help(client, message):
await message.reply("Commands: /start /help")
@app.on_edited_message(filters.text)
async def on_edit(client, message):
await message.reply("you edited a message")
@app.on_callback_query(filters.data("btn_ok"))
async def on_btn(client, query):
await query.answer(text="OK!")
@app.on_inline_query()
async def on_inline(client, query):
pass # handle inline queries
@app.on_user_status()
async def on_status(client, status):
print(status.user_id, status.status)
@app.on_chat_action()
async def on_action(client, action):
pass # user joined, left, pinned, etc.
@app.on_message_deleted()
async def on_delete(client, event):
pass
@app.on_participant_update()
async def on_participant(client, event):
pass
@app.on_message_reaction()
async def on_reaction(client, event):
pass
@app.on_poll_vote()
async def on_vote(client, event):
pass
@app.on_raw_update()
async def on_raw(client, update):
pass # every raw TL update
Filters
Combine filters by passing multiple to the decorator.
filters.all # every update
filters.text # message has text
filters.photo # message has a photo
filters.media # message has any media
filters.private # private chat
filters.group # group or channel
filters.incoming # not sent by you
filters.outgoing # sent by you
filters.mentioned # bot was mentioned
filters.album # grouped media
filters.command("start") # /start
filters.regex(r"hello|hi") # text matches pattern
filters.user(123456) # from a specific user
filters.chat(-100123456) # in a specific chat
filters.data("btn_ok") # callback query data
filters.and_(f1, f2) # both must pass
filters.or_(f1, f2) # either passes
filters.not_(f1) # inverts a filter
Messages
# send
msg = await client.send_message("me", "hello")
await client.send_html("me", "<b>bold</b>")
await client.send_markdown("me", "**bold**")
# on the message object
await message.reply("got it")
await message.forward_to("me")
await message.pin()
await message.edit("updated text")
await message.delete()
Media
await client.send_photo("me", "photo.jpg", caption="look")
await client.send_document("me", "file.pdf", caption="report")
Edit and delete
msg = await client.send_message("me", "draft")
await client.edit_message("me", msg.id, "updated")
await client.delete_message(msg.id)
await client.delete_messages([1, 2, 3])
Dialogs and account
me = await client.get_me()
print(me.first_name, me.username)
dialogs = await client.get_dialogs(limit=20)
for d in dialogs:
print(d.title, d.unread_count)
Userbot
from ferogram import Client, filters
app = Client("session", api_id=123456, api_hash="abc123")
@app.on_message(filters.private, filters.incoming, filters.text)
async def echo(client, message):
await message.reply(message.text)
app.run()
Raw API
Access any Telegram API method directly using the generated TL types.
from ferogram.raw.api.functions import GetHistory
from ferogram.raw.api.types import InputPeerUsername
result = await app.invoke(GetHistory(
peer=InputPeerUsername(username="durov").to_dict(),
offset_id=0,
offset_date=0,
add_offset=0,
limit=10,
max_id=0,
min_id=0,
hash=0,
))
for msg in result.get("messages", []):
print(msg.get("id"), msg.get("message", "")[:80])
758 functions and 1559 types are available under ferogram.raw.api.functions and ferogram.raw.api.types.
The generated/ directory is internal codegen output. Always import from ferogram.raw.api.
Context manager
async with Client("session", api_id=..., api_hash=...) as app:
await app.send_message("me", "hello")
Architecture
Python caller
| asyncio await
v
ferogram-py (PyO3 .so extension)
| FFI, Rust holds GIL only at call boundary
v
ferogram (Rust, tokio async runtime)
| TCP / TLS
v
Telegram MTProto
License
MIT OR Apache-2.0
Developed by Ankit Chaubey
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 Distributions
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 ferogram-0.1.5.tar.gz.
File metadata
- Download URL: ferogram-0.1.5.tar.gz
- Upload date:
- Size: 560.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b193b20f9a6513ef421886a6e174f8a85f63612b7cbb293a28c245e3d094e6f
|
|
| MD5 |
7eb208a8fc4a4bdae5bd12136fd0aebf
|
|
| BLAKE2b-256 |
c864edbdbc81fa75303f5abc09bd8d3f85db732081fe457ef391a546d1e25243
|
File details
Details for the file ferogram-0.1.5-cp313-abi3-win_amd64.whl.
File metadata
- Download URL: ferogram-0.1.5-cp313-abi3-win_amd64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.13+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2e61b21733b1960752c5178167f74cbaba990423445e7231a88b6586d5b91ea
|
|
| MD5 |
ea113a82e36acb0ccdae9dfa35a978bf
|
|
| BLAKE2b-256 |
735130a3315dbb6c5f7997d03bada58d7e61d2d4a3540bdbfe167c6dbb468594
|
File details
Details for the file ferogram-0.1.5-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: ferogram-0.1.5-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: CPython 3.13+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0c55894bac9c62d6fdeeb956d92eced2ceb7a24ff7c13e537eea676f4c4b7e1
|
|
| MD5 |
6710ffeeb34331b9cc6284cc7b8ed0af
|
|
| BLAKE2b-256 |
9254ce933c1df2f71888087ba28407ab811877ce308eef5ca0df1474618600fb
|
File details
Details for the file ferogram-0.1.5-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: ferogram-0.1.5-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.13+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0da34700f4ed179955358c7320af4608ad68ea09f8ded9c5ded4ae44e03fac18
|
|
| MD5 |
27b169ab2133d704e6d753dce1456cf4
|
|
| BLAKE2b-256 |
b35d68f1c39b50c3c2b994589c6fdf7bf943dc126d46554fc69aa540265023f5
|
File details
Details for the file ferogram-0.1.5-cp313-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: ferogram-0.1.5-cp313-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.13+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f64a1c27960b8a89594e1f819245b67f4b9b1673f4ea4337226339a1a5bf9e5d
|
|
| MD5 |
a9d0590edd84a509a7a9462894128662
|
|
| BLAKE2b-256 |
a7a31034c0ac2fe6073f2d432db37a9cb44f3618488a87af377acaeaaf872758
|
File details
Details for the file ferogram-0.1.5-cp313-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: ferogram-0.1.5-cp313-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 4.6 MB
- Tags: CPython 3.13+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79d62a47f509fb40901658aad91115feb6d1ed39182894e048291e47588996a6
|
|
| MD5 |
55f631684383179aa6d4e77474dbecd1
|
|
| BLAKE2b-256 |
4a6c638cc904af6089475cca35291d66e2da2990a7884561243b3f788d071cc1
|
File details
Details for the file ferogram-0.1.5-cp313-abi3-android_24_x86_64.whl.
File metadata
- Download URL: ferogram-0.1.5-cp313-abi3-android_24_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: Android API level 24+ x86-64, CPython 3.13+
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bafda1c9f6ba93b627bc3ff0b6901b6e6a1457b35010af0864b93c22f2b4c6e2
|
|
| MD5 |
c140ffea58761e02f03ba1819b1ae5b9
|
|
| BLAKE2b-256 |
005a631205133b9b6c6ef754720c9f8e396cd440c4d401f4609369ea13c3fa90
|
File details
Details for the file ferogram-0.1.5-cp313-abi3-android_24_x86.whl.
File metadata
- Download URL: ferogram-0.1.5-cp313-abi3-android_24_x86.whl
- Upload date:
- Size: 4.5 MB
- Tags: Android API level 24+ x86, CPython 3.13+
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc7b30c6f58b7e23562fc06e4d4165e1368e715e39c5adacb8788ae62d8218ac
|
|
| MD5 |
a1f542b671f4d335c60a0e566416ad14
|
|
| BLAKE2b-256 |
f6a265d13aa1772398e2535e1deba59be748cfa15451e5e2c60ce723ef7a02b2
|
File details
Details for the file ferogram-0.1.5-cp313-abi3-android_24_armeabi_v7a.whl.
File metadata
- Download URL: ferogram-0.1.5-cp313-abi3-android_24_armeabi_v7a.whl
- Upload date:
- Size: 3.9 MB
- Tags: Android API level 24+ ARM EABI v7a, CPython 3.13+
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
627f537db3ee501b7130f4f9ba62eaec18fa4f62bddee921dbbaac0dad981c5c
|
|
| MD5 |
3c5ef121a320855ffe1bd9635fc0402f
|
|
| BLAKE2b-256 |
8f43c1b38547b6e82c8cfa2da0586bc6438d3b4410d5feebbb7db63d03194475
|
File details
Details for the file ferogram-0.1.5-cp313-abi3-android_24_arm64_v8a.whl.
File metadata
- Download URL: ferogram-0.1.5-cp313-abi3-android_24_arm64_v8a.whl
- Upload date:
- Size: 4.4 MB
- Tags: Android API level 24+ ARM64 v8a, CPython 3.13+
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2510078d3c698b8d234827c4051c3e848b76aeb6f38868170a4c10ed0f41950
|
|
| MD5 |
5f827cc2cc710af44580e54e585c819c
|
|
| BLAKE2b-256 |
875810e230a0e0859f3382e5f5fdcfa4ed664bcfc01e5a083c39d8ed8c390bc9
|