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

Uploaded CPython 3.13+Windows x86-64

ferogram-0.1.8-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.8-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.8-cp313-abi3-macosx_11_0_arm64.whl (7.2 MB view details)

Uploaded CPython 3.13+macOS 11.0+ ARM64

ferogram-0.1.8-cp313-abi3-macosx_10_12_x86_64.whl (7.7 MB view details)

Uploaded CPython 3.13+macOS 10.12+ x86-64

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

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

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

Uploaded Android API level 24+ x86CPython 3.13+

ferogram-0.1.8-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.8-cp313-abi3-android_24_arm64_v8a.whl (7.2 MB view details)

Uploaded Android API level 24+ ARM64 v8aCPython 3.13+

File details

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

File metadata

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

File hashes

Hashes for ferogram-0.1.8.tar.gz
Algorithm Hash digest
SHA256 3d77cdefafb3d55f70c75dbed622bb65c3d25db381796e69459e7c9ef2487c1e
MD5 e583bafa787824d0197f00b197ba472f
BLAKE2b-256 f64e46a74eae4a1ef2c8735c36326bb6a3bdddf2519787b57550722bed217fd7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ferogram-0.1.8-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.8-cp313-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 676245ec9e727bb81a7028c10af91103d14dbce71bd5ca0f87b19a819f1e6e81
MD5 a47d57ad91ab3c144bdb45659a419418
BLAKE2b-256 aebdd4a5af71b0863c14ea6e919864baffdca2c8ecfafdf77c894dbec93f2ba1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.8-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eefcd2e2e9c1acfa185e3254d0e5043b258fbe7abfad87bbbd662864a43cee01
MD5 926dbc417d8476d6ec7eba1ce393b17b
BLAKE2b-256 c8cff6c92089e085fee5fff54d0c63f7a805637d85414741d197356b9e92bbfd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.8-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 41d10746ce33a8874a0c0de77b66d3d20c0409b818a2434c4f6452e085071cd5
MD5 f4e6b7ba4151683040f61d648630c248
BLAKE2b-256 4caae4c89f353972480491703129e0ccc850b78796e6382029f2a68e0036677b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.8-cp313-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2dccdf128ca26734f4a92478b37adf83acc474b9826e027665041b0b8cc4edf3
MD5 f1ed93d5bb25c2946e5a2565c2e995ee
BLAKE2b-256 b8fc48dfedec0b220f6709e2f81e810741e68ede327a999ab2758b92db296940

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.8-cp313-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5ff83a3da843a46c18299b59cec483acad4f0fdcdc307e313d9380f3f0ac8094
MD5 1536b150d0653051cb701d18cd69fd26
BLAKE2b-256 2856feac4633d74b44d8d7f90ca89380f063df5a14b61ad4e05aa95f79b9f1d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.8-cp313-abi3-android_24_x86_64.whl
Algorithm Hash digest
SHA256 4d89ccc540f79e112999df590035f7622ae5241846d8bed1a1395a115d8fd556
MD5 b16627871d156ef84fea760bb7f0858d
BLAKE2b-256 6c85998bb3542eabf60b8d49dd45f619a05b2c592680e9c55ca74b86ad711166

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.8-cp313-abi3-android_24_x86.whl
Algorithm Hash digest
SHA256 8ebedb1a1561ea48724f038890d91d10c601b095c27e3bb03c0d558ea423e581
MD5 02c0fc64d964a33848539fe97e52e0c8
BLAKE2b-256 6cf8e901220396875bba8d0f32d97378de200d662a86a97d4b17decaa93d0f6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.8-cp313-abi3-android_24_armeabi_v7a.whl
Algorithm Hash digest
SHA256 b6e6436a8db58b0852436dd9389650fad93fce627ccf4e3a0a26582160100680
MD5 85c9e271987ee2c145c887a05f7f69f3
BLAKE2b-256 edf792e5e0450dd266a544d99fadbe8ad39575b3ea698d30a8ad4c826756004d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.1.8-cp313-abi3-android_24_arm64_v8a.whl
Algorithm Hash digest
SHA256 557b964aa3ae01482516ff30d5fce4a64b8ac569d6ed63bcd2a43b41203c41b3
MD5 6e916626ecb5e01fc8374f75a10f0389
BLAKE2b-256 5496b90fc08aaecbc76bae2800d3c0afbbe71fddef7f6ad4ae5d32303f7db51d

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