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.1.9.tar.gz (425.6 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.1.9-cp313-abi3-win_amd64.whl (10.1 MB view details)

Uploaded CPython 3.13+Windows x86-64

ferogram-0.1.9-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.8 MB view details)

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

ferogram-0.1.9-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.5 MB view details)

Uploaded CPython 3.13+manylinux: glibc 2.17+ ARM64

ferogram-0.1.9-cp313-abi3-macosx_11_0_arm64.whl (7.2 MB view details)

Uploaded CPython 3.13+macOS 11.0+ ARM64

ferogram-0.1.9-cp313-abi3-macosx_10_12_x86_64.whl (7.8 MB view details)

Uploaded CPython 3.13+macOS 10.12+ x86-64

ferogram-0.1.9-cp313-abi3-android_24_x86_64.whl (7.8 MB view details)

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

ferogram-0.1.9-cp313-abi3-android_24_x86.whl (7.5 MB view details)

Uploaded Android API level 24+ x86CPython 3.13+

ferogram-0.1.9-cp313-abi3-android_24_armeabi_v7a.whl (6.6 MB view details)

Uploaded Android API level 24+ ARM EABI v7aCPython 3.13+

ferogram-0.1.9-cp313-abi3-android_24_arm64_v8a.whl (7.3 MB view details)

Uploaded Android API level 24+ ARM64 v8aCPython 3.13+

File details

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

File metadata

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

File hashes

Hashes for ferogram-0.1.9.tar.gz
Algorithm Hash digest
SHA256 50e6f0d02999b8b95e546dd978409771e487f885d8a2d7838429eb8d8a898ced
MD5 0081914407c078d7ea664bb946ae432a
BLAKE2b-256 f3534c9bdf4d5864b47e04f49dc6fe8e82159c4f52f866d39b1fa65dde7ccd44

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ferogram-0.1.9-cp313-abi3-win_amd64.whl
  • Upload date:
  • Size: 10.1 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.1.9-cp313-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6f69ba5ded40eed8c90cfd1b6eb1105dc86daed1879bd6163aea8b3e5a61eb69
MD5 d91bdd768f769d49435ebe0a24adb6d0
BLAKE2b-256 8000f2cf87d1a961f30d0f8d127304be254721874f92a2e48527193e80aa4f30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.9-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9ab65a3f6351c37cc22621b519f5ba9da6e7b077a37a362f0103c35476771f80
MD5 4e68cc91f2d1abbafab989482611e603
BLAKE2b-256 c5e7b0cf0e410233bf19167c2ce353920ef0ef35d6fb4106179ca5ec4fcf8dba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.9-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d91735453d917155e84b6186dc2db340055da7fbd21dcb5015cc6c6a6406d34f
MD5 0d063100463da5a410b562c8d2f638aa
BLAKE2b-256 d8ebdbe68cf68c34b97f6bfb609bd1a854c62f97db760b8256f6354f0671048e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.9-cp313-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 041891b10579d848e9cd62a0a78a56e951fa43e5b02a687409c3988bd517c8be
MD5 809eb5ad5860cdfc629b413fcd3245e9
BLAKE2b-256 f75408a5108fa475168e9656ea5a1725a27b16afce1f62747ddf90a25ba402cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.9-cp313-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3af481892c8e1dd739013ca54067f3c165c6942571170424865e8b867fa7b9b8
MD5 609a69e4d96a1df640e3c3abfb886b3b
BLAKE2b-256 68ac18c0ded6902622487e305358a73cb41a0667c3ad06ba77de4687ed107603

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.9-cp313-abi3-android_24_x86_64.whl
Algorithm Hash digest
SHA256 122d6b238021a2ef0a20802ba8030bf32396711e12b34f2bcb06191c8bc047c7
MD5 d196b025bcd119364ef3f42688d2c3ec
BLAKE2b-256 a2dbcfefc68f8276716b450e12b5e0731d3ff8bc7a41b49b93465e9ce9fa72c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.9-cp313-abi3-android_24_x86.whl
Algorithm Hash digest
SHA256 f2f9f0c3b1f83609a227467a9cb7aff2a8993eab920cfd2907a9ca6e5f6be3c3
MD5 0ca143bca694ead7020303a3721d299b
BLAKE2b-256 cc8902fe0f67871fb1051a602af716155813df89ef36fda2966c40b8652fcc90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.9-cp313-abi3-android_24_armeabi_v7a.whl
Algorithm Hash digest
SHA256 29d2c3c36d094f8bb8e07360a62d6d512bc38b04446ffe7c2033d06d365584eb
MD5 f5faf3acb7846558e2be901a93d90fd2
BLAKE2b-256 b316dd458b721646be71a11246993a92ee6674a74b47b1de1e1eb139adc37495

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.9-cp313-abi3-android_24_arm64_v8a.whl
Algorithm Hash digest
SHA256 f1b01df9e79230150ab37124f4dba745d0373578820bbef891775a99e61842fb
MD5 2b6ea05b517102dd815d958ae8c3e30f
BLAKE2b-256 d4dd4743eda9452dca7d434d5ef8e991c3c10568ee9ddc207f9a60a321609a99

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