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.4.1.tar.gz (460.0 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.4.1-cp313-abi3-win_amd64.whl (13.9 MB view details)

Uploaded CPython 3.13+Windows x86-64

ferogram-0.4.1-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.3 MB view details)

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

ferogram-0.4.1-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (10.7 MB view details)

Uploaded CPython 3.13+manylinux: glibc 2.17+ ARM64

ferogram-0.4.1-cp313-abi3-macosx_11_0_arm64.whl (10.5 MB view details)

Uploaded CPython 3.13+macOS 11.0+ ARM64

ferogram-0.4.1-cp313-abi3-macosx_10_12_x86_64.whl (11.2 MB view details)

Uploaded CPython 3.13+macOS 10.12+ x86-64

ferogram-0.4.1-cp313-abi3-android_24_x86_64.whl (11.4 MB view details)

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

ferogram-0.4.1-cp313-abi3-android_24_x86.whl (11.0 MB view details)

Uploaded Android API level 24+ x86CPython 3.13+

ferogram-0.4.1-cp313-abi3-android_24_armeabi_v7a.whl (9.7 MB view details)

Uploaded Android API level 24+ ARM EABI v7aCPython 3.13+

ferogram-0.4.1-cp313-abi3-android_24_arm64_v8a.whl (10.7 MB view details)

Uploaded Android API level 24+ ARM64 v8aCPython 3.13+

File details

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

File metadata

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

File hashes

Hashes for ferogram-0.4.1.tar.gz
Algorithm Hash digest
SHA256 8a1ae79167c25777880e16ba2b741f94640b3f9b85203922f3d572cfdf53dc66
MD5 d0b63d4e941030993ab5ac4f55e9c62b
BLAKE2b-256 d7951938e485bf6c8f24ebc45e41c34360ddf814e2fe979ea44d15e300060037

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ferogram-0.4.1-cp313-abi3-win_amd64.whl
  • Upload date:
  • Size: 13.9 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.4.1-cp313-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b91b7e2734f96cac9f285f65207733be828ea2a54796bf1285e9a76c8ad56d35
MD5 4dce8379eef907ef9f18c2638177be25
BLAKE2b-256 850a9026eb7b4e16c2718b6938bb2816abd379c581f440ada03cad63ea30c916

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.1-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d3a1daaec9bcf987db1b97642760fd896752ed2ad355a27dad901bb8fb35e385
MD5 2affe0b97ef6cbc82bfeed4470390bdd
BLAKE2b-256 a379998bd6961be2d9898d49980e5dec5f83c2c4c693cd01ca1d0b889a422247

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.1-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e10baad8eeddbcb3c3e800c71c673a8578ca1eb0c00b20626fea76ec4752ec61
MD5 c87f327ffcb463cc13ff6ac53cb98304
BLAKE2b-256 20c075c5f1451ccca2cf1e044a90f529590bebd65e5171bd4379495bed3678aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.1-cp313-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6cfe6d5959a52981e2e2a39c8509493f54a61f59b0fd48399facdd2a422d7ac3
MD5 d3ef29976d9a08892a568a9047d1c839
BLAKE2b-256 ba09e9a33be0c311f8dc9013a730d73be1c9cda709ec6017f4df5fe7f459cff9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.1-cp313-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1251a49dc3bb5455e27cb7f07e6033cd0910125db64a027940b0c157ac08cced
MD5 0c5ea952c961a468694fe71807ac5f01
BLAKE2b-256 4855fe9466832c7f2914a2f017db2b674d9789fbdc290ebc9cd68f00b7d03c2d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.1-cp313-abi3-android_24_x86_64.whl
Algorithm Hash digest
SHA256 d8fb8adfa6232e1787a2a5d865d4ca68e134ede6f71c3c7f5730de462d5e87e9
MD5 4d8730bdb61f8f2f4b0e94f3973ef39d
BLAKE2b-256 e17f2bd5094117547129c4df97570b6ab811ae8ac7388d604a9e992d715f5214

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.1-cp313-abi3-android_24_x86.whl
Algorithm Hash digest
SHA256 8db8dcc4568e44e2fe7cbef300dad91be37b5b5e52e3972e9a065fe779aa3bb2
MD5 d8c6db90f6151c766380eb19b2ff0316
BLAKE2b-256 174060e101a14d8ba2128e2fb813db6edf31d9fdb4a8aa5123325def81e43fa8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.1-cp313-abi3-android_24_armeabi_v7a.whl
Algorithm Hash digest
SHA256 a8c35396063feec80a1674f96f9ca88c9a2b282f17f049b98fbb09c293e6c4d3
MD5 b75c8c049277103130fd0b1181620225
BLAKE2b-256 529794ff5739e31b5abc733f84c58101670a6e3504d4de0b365f7518f75bc578

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.1-cp313-abi3-android_24_arm64_v8a.whl
Algorithm Hash digest
SHA256 97f0e272f1a6b0740319b43a3edfaa7e6e29f7aa305ca2b8821b39e231f52a19
MD5 a680608668acd7085d3e282152031490
BLAKE2b-256 3f67ac974feff21d59f129a534b0eda910cbed711c9dce34253d236cce81f616

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