Skip to main content

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.

Built with PyO3 and maturin. Works on Linux, macOS, Windows, and Android (Termux).


What is ferogram-py?

ferogram-py is a Python interface for the ferogram MTProto client.

It uses a Rust core for networking, encryption, session handling, and updates, while exposing a simple async Python API on top.

You can use it to build userbots, bots, or automation tools with access to both high-level methods and raw Telegram APIs.


The Rust core handles crypto, transport, session management, and update processing. The Python layer provides async/await methods and decorator-based event handlers with minimal overhead.

Full API reference: FEATURES.md


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", api_id=0, api_hash="", bot_token="123:TOKEN")

@app.on_message(filters.command("start"))
async def start(client, message):
    await message.reply("Hello!")

app.run()

Credentials can also come from env vars: API_ID, API_HASH, BOT_TOKEN.


Client setup

from ferogram import Client

app = Client(
    session="mybot",       # session file name (no extension)
    api_id=123456,
    api_hash="abc...",
    bot_token="123:TOKEN", # omit for userbot
)

app.run()                          # blocking; starts and loops forever
# or
await app.start()
await app.run_until_disconnected()
# or as context manager
async with app as client:
    ...

Session is created on first run and reused automatically.


Raw API

Use client.raw for convenience. Use class-based calls only when you need full control.

Preferred (namespace proxy, peer strings auto-resolve):

result = await client.raw.messages.GetHistory(peer="@durov", limit=5)
result = await client.raw.messages.SendMessage(peer="@user", message="hi")

Class-based (full control):

from ferogram.raw.generated.functions.messages import GetHistory

result = await client.invoke(GetHistory(
    peer=await client.resolve_peer("@durov"),
    offset_id=0, offset_date=0, add_offset=0,
    limit=5, max_id=0, min_id=0, hash=0,
))
# shorthand
result = await client(GetHistory(...))

Results are low-level TL objects (or dict-like structures) matching the Telegram schema. The generated/ directory is internal codegen output. Direct imports from it are considered advanced usage and may change.

All functions and types are available. See FEATURES.md for all import styles.


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()

Logging

import ferogram.logging as fero_log

fero_log.setup()           # INFO to stderr
fero_log.setup(level=10)   # DEBUG

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

This project is dual-licensed under:

  • MIT License
  • Apache License 2.0

You may choose either license.

You are free to use, modify, and distribute this software (including commercial use), provided that the original license and copyright notice are included.

See LICENSE-MIT and LICENSE-APACHE for full details.

Developed by Ankit Chaubey


⭐ Star this repo if you find it useful

Project details


Download files

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

Source Distribution

ferogram-0.2.2.tar.gz (430.9 kB view details)

Uploaded Source

Built Distributions

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

ferogram-0.2.2-cp313-abi3-win_amd64.whl (10.4 MB view details)

Uploaded CPython 3.13+Windows x86-64

ferogram-0.2.2-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.1 MB view details)

Uploaded CPython 3.13+manylinux: glibc 2.17+ x86-64

ferogram-0.2.2-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.8 MB view details)

Uploaded CPython 3.13+manylinux: glibc 2.17+ ARM64

ferogram-0.2.2-cp313-abi3-macosx_11_0_arm64.whl (7.5 MB view details)

Uploaded CPython 3.13+macOS 11.0+ ARM64

ferogram-0.2.2-cp313-abi3-macosx_10_12_x86_64.whl (8.0 MB view details)

Uploaded CPython 3.13+macOS 10.12+ x86-64

ferogram-0.2.2-cp313-abi3-android_24_x86_64.whl (8.1 MB view details)

Uploaded Android API level 24+ x86-64CPython 3.13+

ferogram-0.2.2-cp313-abi3-android_24_x86.whl (7.7 MB view details)

Uploaded Android API level 24+ x86CPython 3.13+

ferogram-0.2.2-cp313-abi3-android_24_armeabi_v7a.whl (6.8 MB view details)

Uploaded Android API level 24+ ARM EABI v7aCPython 3.13+

ferogram-0.2.2-cp313-abi3-android_24_arm64_v8a.whl (7.6 MB view details)

Uploaded Android API level 24+ ARM64 v8aCPython 3.13+

File details

Details for the file ferogram-0.2.2.tar.gz.

File metadata

  • Download URL: ferogram-0.2.2.tar.gz
  • Upload date:
  • Size: 430.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for ferogram-0.2.2.tar.gz
Algorithm Hash digest
SHA256 dd4a4b21f0931b7e1f0590a9470f41d493cc4090738d0af510e2fa83f81bd2c5
MD5 b3fe84bcfad3a335c73c6f8c0c7f0cc8
BLAKE2b-256 22e2473cf0da686e0536c98db4f00ff73f6f962b3bc53590244eb3d3d80937a8

See more details on using hashes here.

File details

Details for the file ferogram-0.2.2-cp313-abi3-win_amd64.whl.

File metadata

  • Download URL: ferogram-0.2.2-cp313-abi3-win_amd64.whl
  • Upload date:
  • Size: 10.4 MB
  • Tags: CPython 3.13+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for ferogram-0.2.2-cp313-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ffced318e98d8485f6d581664a06b829f98ae6f3dbbaf32e7c1e4367d0796b6f
MD5 ae8963a2963629d6326e24f91122dd55
BLAKE2b-256 aa2bbfe878144819cbdd18a81eb9d0d48e996b1f82089fc1aa858b4262c02045

See more details on using hashes here.

File details

Details for the file ferogram-0.2.2-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ferogram-0.2.2-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 446e9c24645df9a6a8f8fc7bcb733a28b53cf570e506777603cb7812bf5f4edd
MD5 027d4d7a82fff6a3a87f2d55e560e6be
BLAKE2b-256 d8364d916b16a1b87b7fac9dc2433fa9f69288e9dc537e4cf4f56c53918b1049

See more details on using hashes here.

File details

Details for the file ferogram-0.2.2-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ferogram-0.2.2-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e4fdb1b40a8d83c81f240154654c746feb123d9c30c60a8760d04ab0e6b2030b
MD5 023eddf8c637beffdc3bd76a7438bc21
BLAKE2b-256 1fc6471391505c4f6ada965990ee83694ee0224de86d6e794f8d02e1cb857e76

See more details on using hashes here.

File details

Details for the file ferogram-0.2.2-cp313-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ferogram-0.2.2-cp313-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c42bf511ed71d4ea6e8888b8b8f27fcf8e5c62048397747623c3ea56374eb07a
MD5 ed7ddfe34455a582735af29ffc715856
BLAKE2b-256 f4eb45349699dc257cc0e21d3a422c1497aaee2e05245b6d5ddaa318b91f1c60

See more details on using hashes here.

File details

Details for the file ferogram-0.2.2-cp313-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ferogram-0.2.2-cp313-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 63778d7ba115602f65db5b60b2e380c1b477d68f6ed426d6b68be1514f3212d5
MD5 444bba4b6dbe595fb8245d5e9ff77f55
BLAKE2b-256 73b9759b53a5a19278ebc72729ba77d14bbbf43cbd4cb4f128d9a8fff6b55d10

See more details on using hashes here.

File details

Details for the file ferogram-0.2.2-cp313-abi3-android_24_x86_64.whl.

File metadata

File hashes

Hashes for ferogram-0.2.2-cp313-abi3-android_24_x86_64.whl
Algorithm Hash digest
SHA256 f085b258c6aaad334b007d8267d0731af90776e7b9986a5277e2f6bad7887316
MD5 35b07426a9f8975d3c332a37a668acf6
BLAKE2b-256 554f70c3406b97419a7d78952311c7673204fc2104dd6cee32609020dc23999c

See more details on using hashes here.

File details

Details for the file ferogram-0.2.2-cp313-abi3-android_24_x86.whl.

File metadata

File hashes

Hashes for ferogram-0.2.2-cp313-abi3-android_24_x86.whl
Algorithm Hash digest
SHA256 0eaf88e7849c45364a8afdfa102750bf79e8d6c4b369b05393a2d0b5716c31e5
MD5 e6f8998241bda246f54fc83236b5f6fd
BLAKE2b-256 c5a377b67917c2612f9229c76b93dbb01108af666b19701bb5554dd37bd3cc8a

See more details on using hashes here.

File details

Details for the file ferogram-0.2.2-cp313-abi3-android_24_armeabi_v7a.whl.

File metadata

File hashes

Hashes for ferogram-0.2.2-cp313-abi3-android_24_armeabi_v7a.whl
Algorithm Hash digest
SHA256 39d29e7ede273a7068722ffbe3797099d0bba18f7e5b2c5b655a5be3b4467219
MD5 456613c9f666cdb60265e22485c9be0d
BLAKE2b-256 ca818bd33750e677739d40d047e55901976d188b9134660b03c6109dc0577328

See more details on using hashes here.

File details

Details for the file ferogram-0.2.2-cp313-abi3-android_24_arm64_v8a.whl.

File metadata

File hashes

Hashes for ferogram-0.2.2-cp313-abi3-android_24_arm64_v8a.whl
Algorithm Hash digest
SHA256 41e72a273f5dc28a67e1d3d1bba26429053a26ab97a71388c098faccf7234f0d
MD5 bca2a55f6284694b7da6bf9f55e4e94f
BLAKE2b-256 68d971a2ea04f4b91f86d020941393de7181cfaede998671437e3654cbedd3a3

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