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.1.tar.gz (427.1 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.1-cp313-abi3-win_amd64.whl (10.4 MB view details)

Uploaded CPython 3.13+Windows x86-64

ferogram-0.2.1-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.1-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.1-cp313-abi3-macosx_11_0_arm64.whl (7.5 MB view details)

Uploaded CPython 3.13+macOS 11.0+ ARM64

ferogram-0.2.1-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.1-cp313-abi3-android_24_x86_64.whl (8.1 MB view details)

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

ferogram-0.2.1-cp313-abi3-android_24_x86.whl (7.7 MB view details)

Uploaded Android API level 24+ x86CPython 3.13+

ferogram-0.2.1-cp313-abi3-android_24_armeabi_v7a.whl (6.8 MB view details)

Uploaded Android API level 24+ ARM EABI v7aCPython 3.13+

ferogram-0.2.1-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.1.tar.gz.

File metadata

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

File hashes

Hashes for ferogram-0.2.1.tar.gz
Algorithm Hash digest
SHA256 570aa514a5918cd09c55e704b3cdb97176c7c9ceb2d3462f55d358d6a4087140
MD5 0b74554518a30a16d8ffacc2234af0ae
BLAKE2b-256 5f1f1ed2ce1b415419409cf1ca40ae21731b2c28bff72736b30be9dc96cb29d8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ferogram-0.2.1-cp313-abi3-win_amd64.whl
  • Upload date:
  • Size: 10.4 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.1-cp313-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 06b693ce89ec806751c75f44b28afb54fc3725a7f7ce03054dbac5762659f0ab
MD5 9f274887dc0e33bdba3318edb39661b3
BLAKE2b-256 f2f0f65c16af2f019918611d46e586b6648950a6766492251d92d63e14bb0607

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.1-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a4ddfcfef0764d2be7cbcfa14dbfad9a23448fa1f97f0ea63594857bc996e27c
MD5 b9ca157b6694ba5d21252be34ef239a1
BLAKE2b-256 2907b8a683667d38a8489b85ec7e599692a5744506db9e602e9a2dd7b89f8993

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.1-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a5056415f7aa6217a9c098dfb1a1c73d0a9512fb7b1d46a87c3774301c665882
MD5 b2a4b5b855250771723bd969e86ac85f
BLAKE2b-256 b32989ca0957e10547492bfc554a8830f3d1e69589c842da84d17d965d05115e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.1-cp313-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 69a78d08f72465753903503962836ba881878ec2026a705294b879ed09b16a0c
MD5 f9951537e5d8d26f0c398b4d6de05cd3
BLAKE2b-256 6b79158ae9c0179b29d78c25f38075584d399bc6dbe7b213255020a95e979e0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.1-cp313-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ae87832b0a4211594dbbcc8a84779ea90f8476fd93f2f22fa2230ba443e55a4f
MD5 844055a84a3928fa200af193b09ac7b8
BLAKE2b-256 63d061f449793a465664ba1f53ebb2263f10136c62b50c07df637bbef5e3905e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.1-cp313-abi3-android_24_x86_64.whl
Algorithm Hash digest
SHA256 467fb9571f6c6a61b5bf0991eb7effc73f0a949958c9fb0493318cd35869a99a
MD5 1a63e2832e7ef6bec685a9e0bb2de3d4
BLAKE2b-256 079ea443568d5a40e8a80e5d9d4797d3fb3fc2356e04cb4187f5b9d7039d09b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.1-cp313-abi3-android_24_x86.whl
Algorithm Hash digest
SHA256 4458e93a73fd0e499f50808cdedf60ab4f4eabed416890b6a287386b0a9f4db3
MD5 2c930f48fd928b24af36a19363ababeb
BLAKE2b-256 234aebb30f514c3effcd2f9cd42bcdfe8af37af92efbf2a9630aee590684bae5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.1-cp313-abi3-android_24_armeabi_v7a.whl
Algorithm Hash digest
SHA256 dc98862365a92526fe68ec0a14563be206ceffec3fbbbda4fb19f0fba7798335
MD5 f56686a1a725b812c03512459399d289
BLAKE2b-256 079ddef81bcef16c2448c6ee9e4630564bc01d8f9e2fc0ab04cc2977c4fd8eac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ferogram-0.2.1-cp313-abi3-android_24_arm64_v8a.whl
Algorithm Hash digest
SHA256 752362bfad4c75faaea1e700e6324a33d2ac618f2bef0d3a1d28d85a4e145a47
MD5 058c7f6c861c5a696ebb0f1b0f7c47c0
BLAKE2b-256 037849c8c3909e0eea435ea4ac1bdaa21886abd5e92f1e8cd0dd737a070e796d

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