Ferogram logo
MTProto framework

Ferogram

A native, elegant MTProto framework for building Telegram clients and bots.

Everything you need for Telegram: direct MTProto, bots, user accounts, and voice & video calls in one elegant framework.

Rust
cargo add ferogram
Primary framework
Get started →
Python
pip install ferogram
Powered by the same Rust core
Get started →

Shared architecture

One engine.
Two languages.

Rust and Python run on exactly the same networking, encryption, MTProto implementation, TL parser, transport, update handling, and session management. Python is not a separate reimplementation, it is powered by the same compiled Rust core.

Diagram: user code calls the Python layer (client, filters, types, updates, keyboards, rich text), which crosses an FFI boundary via PyO3 into the compiled Rust extension (_ferogram.so), built from ferogram_mtsender, ferogram_connect, ferogram_crypto, ferogram_session and ferogram_tl_types, which then talks TCP/TLS to Telegram's MTProto servers.

Python calls cross an FFI boundary once, into the same Rust crates that power the native ferogram client.


Choose your language

Same engine, your syntax

Install, write a bot, and read the docs, all in the language you already use.

main.rscargo add ferogram
use ferogram::Client;

const API_ID: i32 = 0;
const API_HASH: &str = "";

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let (client, _) = Client::quick_connect("my.session", API_ID, API_HASH).await?;

    client.send_message("me", "Hello from ferogram!").await?;
    Ok(())
}
main.pypip install ferogram
import asyncio
from ferogram import Client

app = Client("myaccount", api_id=0, api_hash="", phone="+1234567890")

async def main():
    async with app as client:
        await client.send_message("me", "Hello from ferogram!")

asyncio.run(main())

What you get

Built for production

Native performance, full control

An async Rust core talking directly to Telegram's wire protocol, giving you full control over every request and response.

Composable filters

Route updates by combining filters with &, |, and ! instead of nesting if-statements.

Finite-state conversations

ferogram-fsm drives multi-step bot flows with pluggable, swappable state storage.

Pluggable sessions

Binary file, SQLite, LibSQL (Turso), or a portable string backend, or bring your own.

Built-in MTProxy

Classic, DD, and FakeTLS transports, with tg://proxy links parsed and connected automatically.

Gap-safe updates

ferogram-msgbox tracks pts/qts/seq, spots gaps in the update stream, and requests a diff to fix them.

Voice & video calls

TgCalls streams into group and one-on-one calls with a few lines, using FFmpeg under the hood.

One core, two languages

Rust and Python share the exact same protocol implementation, so fixes and speedups land in both at once.

Raw API escape hatch

Reach for client.invoke() and call any TL function directly when the high-level API isn't enough.


Under the hood

Everything a real client needs

MTProxy, rich messaging, CDN downloads, high-speed transfers, and steady performance under load, plus a lot more that doesn't fit in a headline.

MTProxy support
Rich messaging & entities
CDN downloads
High-speed upload & download
High performance under load
Clear crate separation

The goal is to stay out of your way: simple things should be simple, and advanced things should still be possible.

  • Rich messaging: text, media, albums, polls, dice, games, reactions, scheduled messages
  • HTML & Markdown: full parse and generate support for both formats
  • Inline & reply keyboards: buttons, callbacks, inline mode
  • Reactions & stickers: granular reaction API with paid Stars reactions, sticker sets, custom emoji
  • Drafts: save, sync, and clear drafts across devices
  • Proxy support: SOCKS5 with optional auth
  • MTProxy: Classic, DD, and FakeTLS transports, via link or manual config
  • Transport probing: races transports, connects via whichever is fastest
  • Resilient connect: DNS-over-HTTPS and special-config fallback when TCP is blocked
  • CDN: transparent CDN download handling, no extra calls needed
  • Concurrent transfers: parallel uploads/downloads with pause, resume, cancel, and progress tracking
  • Resumable transfers: checkpointed uploads/downloads that survive crashes
  • Router & dispatcher: composable filters (&, |, !) for expressive handlers
  • FSM: type-safe finite state machine for multi-step conversations
  • Middleware: rate limiting, tracing, panic recovery
  • Conversations: ask/wait sequential request-response flows outside the router
  • Flexible login: phone + 2FA (SRP), bot token, or QR code, with exportable session strings
  • Session backends: file, in-memory, string, SQLite, LibSQL
  • Peer resolution: usernames, phone numbers, links, or raw IDs, resolved cache-first
  • Gap-safe updates: pts/qts/seq tracking with automatic diff recovery on reconnect
  • Full admin toolkit: ban, kick, restrict, promote, and transfer ownership
  • Invite links: create, edit, revoke, track joins, approve or decline requests
  • Forum topics: create, edit, and manage topics in forum supergroups
  • Privacy controls: per-key rules with granular allow/disallow lists
  • TgCalls: group calls, P2P calls, conference calls, screen share/presentation, audio and video
  • Payments: invoices, plus shipping and pre-checkout query handling
  • Mini apps: open and manage Telegram mini app sessions
  • Translation & transcription: built-in message translation and voice-to-text
  • Statistics: channel and supergroup growth, views, and activity
  • Raw API: full TL coverage via client.invoke()
  • Python cross-lang: native performance with a clean Python API
14 crates, each doing own job
FGferogram Start here
The main client. Talks to Telegram over MTProto directly, handles auth for bots and user accounts, and gives you a dispatcher, filters, FSM, CDN downloads, middleware, and a raw invoke() escape hatch.
MSferogram-mtsender
Owns the DC connection pool and the retry loop for RPC calls, with pluggable policies like AutoSleep, NoRetries, and CircuitBreaker, plus jittered FLOOD_WAIT handling.
CNferogram-connect
Raw TCP connection and MTProto framing. Abridged, Intermediate, Padded Intermediate, and Full transports, plus Obfuscated2, FakeTLS, and SOCKS5 for MTProxy.
MPferogram-mtproto
The MTProto 2.0 session layer: DH key exchange, encrypted session pack/unpack, msg_key derivation, salts, and message framing.
CRferogram-crypto
AES-IGE, RSA, SHA-1/256, Diffie-Hellman, PQ factorization, and transport obfuscation, written specifically for MTProto rather than borrowed from a general-purpose library.
SSferogram-session
Session persistence: DC address tables, auth keys and salts, update counters, peer access hashes, and pluggable storage backends.
MBferogram-msgbox
Tracks pts/qts/seq for the Updates stream and detects exactly when an update was missed, so a diff can be requested instead of guessing.
TTferogram-tl-types
2,329 auto-generated Rust types covering every Telegram API constructor, function, and enum, with binary TL serialization built in.
TGferogram-tl-gen
Build-time code generator that turns a parsed TL schema into Rust source inside build.rs, keeping the API in step with Telegram's schema.
TPferogram-tl-parser
Reads raw .tl schema files and produces the structured AST that ferogram-tl-gen builds Rust code from.
PRferogram-parsers
Converts Telegram-flavoured Markdown and HTML to and from message entities, for anyone formatting text outside the full client.
FSferogram-fsm
State storage and context for multi-step bot conversations, with a pluggable backend trait and an in-process memory store built in.
DVferogram-derive
Procedural macros for the workspace, currently #[derive(FsmState)] for turning a plain enum into an FSM state type.
TCtgcalls Voice & video
Voice and video calling on top of ferogram, powered by ntgcalls. Join group calls, stream media, and handle P2P calls.

Voice & video

Bring calls into it too

TgCalls extends the same client with voice and video calling, no separate stack to learn.

TgCalls

An elegant Rust client for Telegram voice and video calls.

Bring voice and video calling to your Telegram applications. Join group calls, stream audio or video, and build direct P2P and conference calls with a clean Rust API, built on ferogram and powered by ntgcalls.

call.rscargo add tgcalls
let calls = Calls::new(client);
calls.play(chat_id, "song.mp3").await?;

The simplest way to play audio in a group call, Calls API handles join, voice-chat creation, and media detection for you.

call.rscargo add tgcalls
let calls = Calls::new(client);
calls.play(chat_id, "song.mp3").await?;
simple_calls.rscargo run --example simple_calls
use tgcalls::Calls;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut args = std::env::args().skip(1);
    let chat_id: i64 = args
        .next()
        .expect("usage: simple_calls <chat_id> <file>")
        .parse()?;
    let path = args.next().expect("missing audio file path");

    let api_id: i32 = std::env::var("API_ID")?.parse()?;
    let api_hash = std::env::var("API_HASH")?;
    let (client, shutdown) =
        ferogram::Client::quick_connect("tgcalls.session", api_id, &api_hash).await?;

    let calls = Calls::new(client);
    calls.play(chat_id, path).await?;

    println!("Playing. Press Ctrl+C to stop.");
    tokio::signal::ctrl_c().await?;

    calls.leave(chat_id).await?;
    drop(shutdown);
    Ok(())
}


Source

Repositories

Three repos, one workspace. Star them, fork them, open a PR.

ferogram
ankit-chaubey/ferogram
A native, elegant, and asynchronous MTProto framework in Rust for Telegram clients, bots, and applications.
Rust
mtprotorusttelegramasync
ferogram-py
ankit-chaubey/ferogram-py
A modern, elegant, asynchronous MTProto framework for building Telegram clients and bots in Python, powered by a Rust core.
Python
pythonpyo3telegramasync
tgcalls
ankit-chaubey/tgcalls
An elegant Rust client for Telegram voice and video calls, powered by ntgcalls and ferogram.
Rust
voicevideorustffmpeg

Community

Talk to the project


Ankit Chaubey

College student · Developer · Writer
A curious mind with a quiet interest in how systems, ideas, and people work. Peace, learning through reflection, writing, and building, and staying close to nature and animals, these are the things that make us human.