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

Uploaded CPython 3.13+Windows x86-64

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

Uploaded CPython 3.13+macOS 11.0+ ARM64

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

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

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

Uploaded Android API level 24+ x86CPython 3.13+

ferogram-0.4.0-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.0-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.0.tar.gz.

File metadata

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

File hashes

Hashes for ferogram-0.4.0.tar.gz
Algorithm Hash digest
SHA256 db573dab7f76573b53e587f5917b58bed68c4531be97fade0c1f05b888a98d11
MD5 1bb49fd8829717807a8b955f5caf9425
BLAKE2b-256 087f60a26cf892803dfeea9cd00e8783faa639e2671f14cd06899ef2c3355c67

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ferogram-0.4.0-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.0-cp313-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5385cbda2bed472365d560386d78bb0d0331491e28d5907fbe799258b632bede
MD5 5e2a4e6edcd3a088bf0579dd98ca590f
BLAKE2b-256 6100255349ca228c94114ef070fd9f0c3291357be92b621324d0cc5646a6c724

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.0-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9cc85e61eaee13fcb937c86f2ca460f48c94a7f63949496247fa9347ed5019a2
MD5 ca05ba164b891e4ad341441a80a230dd
BLAKE2b-256 8b1f77b7edb466d8e0893ed5fc17df23c4873b6bc4a3d7875223b11016fab10c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.0-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7c6a541bde50434a36982fcc3e2be422b7f898f730d2ad14d9785376d8fe4e8e
MD5 48004987aacb524d34b9a13c469e092a
BLAKE2b-256 c410b405644feb8a14d3d9c3a711224bb627b44e857f8ffbbda1bea55c117883

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.0-cp313-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d92991327f434b87c6608fbf841fe2c66f803b5bcf5c62eace4fb2fa39d93cfa
MD5 c234d290ee7d54f1e7da2649be130219
BLAKE2b-256 d9c77e7cd62a9dd361124992aeb27d2a21dffcf6630f6b5b7785267677f7a1ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.0-cp313-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 37863579f940cf17d25b44888da3328dc6ba238f287545d67ca24b4cc3a161c2
MD5 f60eb5794196678057b93d0d904c6295
BLAKE2b-256 b9a9b554cdd573129f587e978ec86cd56863c211cd7afd490e09d7a97232f551

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.0-cp313-abi3-android_24_x86_64.whl
Algorithm Hash digest
SHA256 07d6088b15b5f3eb80a649bbe92679dba7047c8ff1f6f2d212d5cf120aacf4cb
MD5 8bc00e53d3af473b4f5adfd75bccbbed
BLAKE2b-256 dbf0bfffe67a2affc836c3376b4dcc4c07677f47b080ae80aaf0d706fd9078c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.0-cp313-abi3-android_24_x86.whl
Algorithm Hash digest
SHA256 88ddfbe01404c24d01e7e37cb070a2594c0fe3085f6ce6c8e23b4531632d3c8f
MD5 61486885e19e83aae9096751024f9d91
BLAKE2b-256 cd9b241e68aacb210725227aa1dde0a0d1588dcb6b4a1d7c9c5349ef0ab569a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.0-cp313-abi3-android_24_armeabi_v7a.whl
Algorithm Hash digest
SHA256 1565fd5c5178b6096b2d7311c7a9af646ad71fe325a9d9b09f27760a4cebd5aa
MD5 eaedee6753b0230845679d25c30bc2b1
BLAKE2b-256 9b46730d7dabd55103160d09c84a311ae6f1b51f40477aa92b786b12a8012061

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.4.0-cp313-abi3-android_24_arm64_v8a.whl
Algorithm Hash digest
SHA256 e275e7eb8e5b5d592554578283ebead9ea2af57556e21007a8e4b611c8e1ae25
MD5 309f5aa867669d35de33500bab932850
BLAKE2b-256 27dfae6a9d25383561774ceaa2f7f58b52de115cafd5d0924b4bcc5cd39183ba

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