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.0.tar.gz (426.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.2.0-cp313-abi3-win_amd64.whl (10.3 MB view details)

Uploaded CPython 3.13+Windows x86-64

ferogram-0.2.0-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.0-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.0-cp313-abi3-macosx_11_0_arm64.whl (7.4 MB view details)

Uploaded CPython 3.13+macOS 11.0+ ARM64

ferogram-0.2.0-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.0-cp313-abi3-android_24_x86_64.whl (8.0 MB view details)

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

ferogram-0.2.0-cp313-abi3-android_24_x86.whl (7.6 MB view details)

Uploaded Android API level 24+ x86CPython 3.13+

ferogram-0.2.0-cp313-abi3-android_24_armeabi_v7a.whl (6.7 MB view details)

Uploaded Android API level 24+ ARM EABI v7aCPython 3.13+

ferogram-0.2.0-cp313-abi3-android_24_arm64_v8a.whl (7.5 MB view details)

Uploaded Android API level 24+ ARM64 v8aCPython 3.13+

File details

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

File metadata

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

File hashes

Hashes for ferogram-0.2.0.tar.gz
Algorithm Hash digest
SHA256 730f2a01ad280200a5abdb1cfdb8acfa3fde348f9a2a5c1f2f5f596bd05de70b
MD5 dda33158141283d212870a33b1f6a274
BLAKE2b-256 319cde4b61dad73c344fdcc53f0b9dd8532e9b8dcac4969c89073de7d7402688

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ferogram-0.2.0-cp313-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7a55e7e8f237b68db23148418e83bf2ed72ff899c01c4f092c624c0d1632ffbf
MD5 f93f4f4102fd2969090a5017f5850499
BLAKE2b-256 692c9939ce43217e4c304e7c87dbbbf15a334f7b1f40acea0ac1da43020cab95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.0-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a308395ece10945ce9c92e3034492303f378d1fc801bee07bc980c4527dc7a88
MD5 8ea27395e2dbcc7fa27d7a73ee9ad301
BLAKE2b-256 57bf2c044d6a63c33eeb033ee2ff088d15016efc254a73084a4b351c3320061a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.0-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5c832b584d0498692088f515fb178ccd980c9a252b7e52f437267a9021b4b925
MD5 34fe4e286eb179592ede133fd328854e
BLAKE2b-256 87e01c45f0d31e617b05ac2e5330c4a2594b339e0fc3285c37fbd23e8f7f97ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.0-cp313-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1c67b9e31c0d78c5cb556b7005508452bad165f4b1a6fb905f07c00ac9925850
MD5 20d68a9c75f15db7ec827285bc5956ef
BLAKE2b-256 6125608881ea5c95fe4a18bfcee0d0c55a52e05d5e9bf1317b4b7fcaca49a857

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.0-cp313-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 243d7cdffd3e2a95cc17a4557f1647f177b88ee125aed2416a011795fb5e96f7
MD5 54ce0934c2a9b856eb8cae2b3de4cfbc
BLAKE2b-256 627d8cb86a00455837bfdb91fb4efd22506bc89b7ba8051b32d4138687b24e09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.0-cp313-abi3-android_24_x86_64.whl
Algorithm Hash digest
SHA256 15516d2340a8f18bb55d6272619fee328c1af22ef095308651afddf10263f1e3
MD5 59a80e4cad80de25c5104ea0e0899c0f
BLAKE2b-256 86cc55653a1b8d6d3b2d31f84cbb47a45db2a617c134ab7b0234dbf902fd829c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.0-cp313-abi3-android_24_x86.whl
Algorithm Hash digest
SHA256 b0b8e1ea8fdec9839acf3f48285ed8c4bfba43228d63370e90038d131bdf875e
MD5 95a3c2ec0a303c3c86dceb4dbe471360
BLAKE2b-256 84d1b26dd174c45a13b91abeb368a97e7a9513e1999e98ad51648eecd973a11a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.0-cp313-abi3-android_24_armeabi_v7a.whl
Algorithm Hash digest
SHA256 09388e5e3c855d6c0544ac8146763410f97fb8a9682a2e44834b550a7ab03f02
MD5 a55917144b21b2ccb1e7b34a335e4316
BLAKE2b-256 e390a76e028aa51b010bc2a38ddce383954ccf9b64964d3ee12e144c9fab336f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.0-cp313-abi3-android_24_arm64_v8a.whl
Algorithm Hash digest
SHA256 f054ad7845d416d9f9d5f3d8eef0c25a110258d63d6cac2751cde5adcdd8edd2
MD5 3c7419f01b04635dbe49ed4c41e0c763
BLAKE2b-256 82c16cac68599fcf6fbf1a4081ce75a09c0105cbcc16dd99abb0ca378e0fbdb8

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