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.3.tar.gz (443.2 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.3-cp313-abi3-win_amd64.whl (10.9 MB view details)

Uploaded CPython 3.13+Windows x86-64

ferogram-0.2.3-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.6 MB view details)

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

ferogram-0.2.3-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.2 MB view details)

Uploaded CPython 3.13+manylinux: glibc 2.17+ ARM64

ferogram-0.2.3-cp313-abi3-macosx_11_0_arm64.whl (7.9 MB view details)

Uploaded CPython 3.13+macOS 11.0+ ARM64

ferogram-0.2.3-cp313-abi3-macosx_10_12_x86_64.whl (8.5 MB view details)

Uploaded CPython 3.13+macOS 10.12+ x86-64

ferogram-0.2.3-cp313-abi3-android_24_x86_64.whl (8.6 MB view details)

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

ferogram-0.2.3-cp313-abi3-android_24_x86.whl (8.1 MB view details)

Uploaded Android API level 24+ x86CPython 3.13+

ferogram-0.2.3-cp313-abi3-android_24_armeabi_v7a.whl (7.2 MB view details)

Uploaded Android API level 24+ ARM EABI v7aCPython 3.13+

ferogram-0.2.3-cp313-abi3-android_24_arm64_v8a.whl (8.0 MB view details)

Uploaded Android API level 24+ ARM64 v8aCPython 3.13+

File details

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

File metadata

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

File hashes

Hashes for ferogram-0.2.3.tar.gz
Algorithm Hash digest
SHA256 e3750af9736ac3dce8b1df241fa7f0023f2aedc4d59043deb4364ff36cb898c3
MD5 89fa4498bfc170dcd1239dc8bdd3f396
BLAKE2b-256 32fb7671eef9de39c98464f822e93959f635355ba8ae3abfa5916fc693637282

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ferogram-0.2.3-cp313-abi3-win_amd64.whl
  • Upload date:
  • Size: 10.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.2.3-cp313-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 52b24a6a9e92b4c5a316ad05bea83cf0541698df76af37f831a95ccc3b485086
MD5 bf49a6f5492550addfdeaf5c7b4a11e3
BLAKE2b-256 fac09d00974d4f9692f3d475570de227027315350590850c5385a1517ec7f4a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.3-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 015c566eb34de1190cf46f723c04797d497e723d36aa23c9bba9cc48ed76dea2
MD5 adc7ef2a803af8e969bfda2c489f20aa
BLAKE2b-256 373851157b396e0946fd1d8732f2d4b5adae3e0ae5fb0b83489641fc8980438c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.3-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 442e2814831535403a750bf1e102898dc7e4da6a1e4191fdc1cbd86ba9c56e91
MD5 e9eff63d0a8809fe5f29adfdb6075184
BLAKE2b-256 35cf6d3951073f9fd5d0ea34b8df9db70b8c66883de9a9681203d748cfbb65e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.3-cp313-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3d3db837b00d3ef3f401cd49161b75030cf366414ae734f303e18b71d4bb7d90
MD5 7c94241cebfa0cb65db9d639fccbaa32
BLAKE2b-256 5798056dd1aec013d189a2bb387fd30b77a414710132295cb50a624c03e03e72

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.3-cp313-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fe12cd33ae9dfff0395448a7e47af7564a0ca328c4ea5b03d316badd6a1231a7
MD5 7f448eed3a3474afdc53c763e5d59b6d
BLAKE2b-256 4894b2040eb561d1499c42ccb1308b3d45513db3ad1765b9fa79e602f4ba8dd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.3-cp313-abi3-android_24_x86_64.whl
Algorithm Hash digest
SHA256 0bc00d081bd121d8990d3c4787e3e9d20d454451a328de55aff453b752e5b40e
MD5 ab85535abf4303af6979d341ececaf60
BLAKE2b-256 850ffb9d14238a8a8ad3428a0a5e035f707dcdbb4b7c4ea90838d5d4494cd33c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.3-cp313-abi3-android_24_x86.whl
Algorithm Hash digest
SHA256 1d36f81dbffc5dcebe8d30b7272444ca321afbcd71b2e4deb53ee91c3751dcb9
MD5 2da50aa2df1213a806bf6556ac970527
BLAKE2b-256 4c25d82ed924cedfce73424bb398132fedbc9dad226135af23e2bd8f50001776

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.3-cp313-abi3-android_24_armeabi_v7a.whl
Algorithm Hash digest
SHA256 6dd6494ba74b984f9115c39aea739a243c1ef16193c77930eff13a661d1e905a
MD5 2a56ddafe46645c7c190129d9694c9e0
BLAKE2b-256 ee1a23c67669aa9036c3bfe2bec1bdcefafcc63035b26577d773e86f91ffad85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.3-cp313-abi3-android_24_arm64_v8a.whl
Algorithm Hash digest
SHA256 c58b1a5aeef78be60043dd2a3abbab2de7a1803f5f72e23c069c06f9fcff3ddf
MD5 6aacd0456f3bedbe4c496d923925e717
BLAKE2b-256 e72c3d580e81327fc7dee3b0f102b12dc062f49bde27485c8974cd086693b788

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