Skip to main content


GoyGram logo

GoyGram

A Telegram framework where Bot API and MTProto run side by side, with the crypto in Rust.
Read the docs »

Documentation · Wiki · PyPI · Report bug · Request feature

Python 3.13+ Rust core PyPI version PyPI downloads License: AGPL v3 Strict CI Publish Telegram MTProto OpSec Docs Wiki Last commit Stars Forks Issues

Table of contents
  1. GoyGram
  2. Key features
  3. Benchmarks
  4. Getting started
  5. Usage
  6. Documentation
  7. Contributing
  8. License
  9. Contact

GoyGram

Bot API and MTProto in one process, with the crypto in Rust

GoyGram is a Telegram framework for Python. Bot API and MTProto run in the same process and share one event loop and one set of handlers, so a bot and a userbot can live in the same app instead of two. Nothing on the hot path is Python: AES for every packet and the TL codec are Rust, compiled straight into the package.

import asyncio
from goygram import GoyGram, filters

app = GoyGram(bot_token="123456:ABC_TOKEN")

@app.on_msg(filt=filters.text)
async def echo(msg):
    await msg.reply("Hello from GoyGram")

asyncio.run(app.run())

Key features

  • Ready: pip install goygram. Python 3.13 and newer, with wheels for Linux, Windows and macOS.
  • Two transports: Bot API and MTProto in one app. Switch per call with via="api" or via="mtproto", and a reply goes back the way the original message arrived.
  • Fast to start: 77 ms to import, about 11 MB of memory. Telethon takes 342 ms and 48 MB for the same job.
  • Rust core: AES-256-IGE for MTProto packets, AES-256-GCM for vaults, with AES-NI used when the CPU has it.
  • No generated wrappers: any Bot API method works right away, in snake_case or camelCase. MTProto methods go through the mt_ prefix. A method Telegram adds tomorrow works without a new release of GoyGram.
  • One event object: MsgObj, CbObj, PollObj, MemberObj and InlineObj are aliases of a single dynamic Obj. Fields are read on demand, so you only pay for the ones you touch.
  • Sessions in one place: a Session is your in-memory state, the .vault file and a portable encrypted string at once. No separate MemorySession, StringSession and SQLiteSession classes to keep in sync.
  • OpSec: the vault key comes out of PBKDF2-SHA256 at 600,000 rounds over your machine id. Memory is zeroized on shutdown, and a wrong key raises instead of quietly falling back to plaintext.
  • Light: aiohttp, rich and qrcode. That is the whole dependency list.
  • Bots over MTProto: pass bot_token together with api_id and api_hash, and the bot speaks raw MTProto instead of HTTP.

(back to top)

Benchmarks

Cold import, memory footprint and MTProto crypto, measured against telethon, pyrogram, aiogram and python-telegram-bot.

goygram telethon pyrogram aiogram python-telegram-bot
cold import (ms) 77.2 342.0 461.5 3016.3 142.8
RSS delta (MB) 10.8 48.4 35.6 152.2 18.8
AES-256-IGE (MB/s, 64 KiB) 1062.5 10.8 202.4 — —
loads message (ops/s) 577,821 — — — —
loads updateNewMessage (ops/s) 225,347 — — — —

There is no C extension to install separately, the crypto is already in the package. For scale, tgcrypto reaches 204.3 MB/s on the same hardware. Parsing a realistic updateNewMessage costs 3.8 µs at p50 and 8.9 µs at p99. How the numbers were taken is written up in benchmarks/.

(back to top)

Getting started

Prerequisites

Python 3.13 or newer. The prebuilt wheels pull nothing else in, and Rust is only needed when you build from source.

A bot needs a token from @BotFather. A user account needs an api_id and an api_hash from my.telegram.org.

Installation

pip install goygram

The wheels are built against the stable ABI and carry the cp38-abi3 tag, so one native build loads on CPython 3.13 and everything newer, on Linux, Windows and macOS. To build from source when your platform has no wheel, Rust has to be on the machine:

git clone https://github.com/GoyGram/GoyGram
cd GoyGram
python -m pip install --no-build-isolation .

(back to top)

Usage

A user account talks MTProto, so it needs an api_id and an api_hash:

import asyncio
from goygram import GoyGram

app = GoyGram(api_id=123456, api_hash="0123456789abcdef0123456789abcdef")

@app.on_cmd("ping")
async def ping(msg):
    await msg.reply("pong")

asyncio.run(app.run())

The first run opens a login screen in the terminal. Pick a QR code or a phone number, and give the 2FA password if the account has one. The session lands in default.vault, encrypted with AES-256-GCM.

# several accounts out of one process
app = GoyGram(api_id=..., api_hash=..., session_name="farm_worker_1")

# one message through Bot API, the next through MTProto
await app.send_msg("123456789", "via Bot API", via="api")
await app.send_msg("123456789", "via MTProto", via="mtproto")

(back to top)

Documentation

The rest of the library has its own pages:

(back to top)

Contributing

Bug reports and pull requests are welcome.

CI is strict about two things: the type check has to pass, and commits have to be signed (git commit -S).

(back to top)

License

GoyGram is released under the GNU Affero General Public License v3.0. The full text is in LICENSE.

(back to top)

Contact

Questions and bug reports go to GitHub issues.

(back to top)

Metadata

Release files for goygram 0.8.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for goygram 0.8.20
File Size Uploaded
goygram-0.8.20.tar.gz 128.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for goygram 0.8.20
File Interpreter ABI Platform
goygram-0.8.20-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
goygram-0.8.20-cp38-abi3-manylinux_2_34_x86_64.whl CPython 3.8 abi3 Linux glibc 2.34+ x86-64 Details
goygram-0.8.20-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details

Total release size: 1.3 MB

Release files / goygram-0.8.20.tar.gz

Download URL goygram-0.8.20.tar.gz
Size 128.9 kB
Tags Source
SHA-256 checksum
How to use checksums
904e96bd9440e8c2bec5a4dd86252286f7584d2f8d96fed46aa8cc9048f5691c
BLAKE2b-256 checksum
How to use checksums
50e38f7791748a0c6433c8f6613e22268d6163eda94494e5c9ce6924b6310a65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / goygram-0.8.20-cp38-abi3-win_amd64.whl

Download URL goygram-0.8.20-cp38-abi3-win_amd64.whl
Size 354.3 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
5684d3855649735eb0fe455cc605647432d7a6db65fa15f2497e6681857056b1
BLAKE2b-256 checksum
How to use checksums
51a3b23c14982453461e4a161d237154c17935e18f97fee14101df1dba418c97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / goygram-0.8.20-cp38-abi3-manylinux_2_34_x86_64.whl

Download URL goygram-0.8.20-cp38-abi3-manylinux_2_34_x86_64.whl
Size 435.2 kB
Tags CPython 3.8 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
d12fb193f427e5e0f923ad11b02bdfe769300d1727fc3edb592a4dbbf3c594d1
BLAKE2b-256 checksum
How to use checksums
f644d9d3df367a3554f5cee4bee4cba933db4238808c5b4a6c476c0e3a2a0dad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / goygram-0.8.20-cp38-abi3-macosx_11_0_arm64.whl

Download URL goygram-0.8.20-cp38-abi3-macosx_11_0_arm64.whl
Size 408.8 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
532f157007767b0dba13ac16c4b3df7ca7553c3fb31c747219ff65baaee1640e
BLAKE2b-256 checksum
How to use checksums
d9ff5a145aaf2a4dc321818d677bea91fbd8403248651f75534ef1df4eec4ec2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release history Release notifications | RSS feed

This release

0.8.20 This release

4 release files

0.8.14

4 release files

0.8.13

4 release files

0.8.12

4 release files

0.8.11

4 release files

0.8.10

4 release files

0.8.9

4 release files

0.8.8

4 release files

0.8.7

4 release files

0.8.6

4 release files

0.8.5

4 release files

0.8.4

4 release files

0.8.3

4 release files

0.8.2

4 release files

0.8.1

4 release files

0.8.0

4 release files

0.7.99

4 release files

0.7.98

4 release files

0.7.97

4 release files

0.7.96

4 release files

0.7.95

4 release files

0.7.94

4 release files

0.7.93

4 release files

0.7.92

4 release files

0.7.91

4 release files

0.7.90

4 release files

0.7.89

4 release files

0.7.88

4 release files

0.7.87

4 release files

0.7.86

4 release files

0.7.85

4 release files

0.7.84

4 release files

0.7.82

4 release files

0.7.81

4 release files

0.7.80

4 release files

0.7.79

4 release files

0.7.78

4 release files

0.7.77

4 release files

0.7.76

4 release files

0.7.75

4 release files

0.7.63

4 release files

0.7.62

4 release files

0.7.61

4 release files

0.7.60

4 release files

0.7.59

4 release files

0.7.58

4 release files

0.7.57

4 release files

0.7.56

4 release files

0.7.55

4 release files

0.7.54

4 release files

0.7.53

4 release files

0.7.52

4 release files

0.7.51

4 release files

0.7.50

4 release files

0.7.49

4 release files

0.7.48

4 release files

0.7.47

4 release files

0.7.46

4 release files

0.7.45

4 release files

0.7.35

4 release files

0.7.34

4 release files

0.7.33

4 release files

0.7.32

4 release files

0.7.31

4 release files

0.7.30

4 release files

0.7.29

4 release files

0.7.28

4 release files

0.7.27

4 release files

0.7.26

4 release files

0.7.25

4 release files

0.7.24

4 release files

0.7.23

4 release files

0.7.22

4 release files

0.7.21

4 release files

0.7.20

4 release files

0.7.19

4 release files

0.7.18

4 release files

0.7.17

4 release files

0.7.16

4 release files

0.7.15

4 release files

0.7.14

4 release files

0.7.13

4 release files

0.7.9

4 release files

0.7.8

4 release files

0.7.7

4 release files

0.7.6

4 release files

0.7.5

4 release files

0.7.4

4 release files

0.7.3

4 release files

0.7.2

4 release files

0.7.1

4 release files

0.7.0

4 release files

0.6.9

4 release files

0.6.8

4 release files

0.6.7

4 release files

0.6.6

4 release files

0.6.5

4 release files

0.6.4

4 release files

0.6.3

4 release files

0.6.2

4 release files

0.6.1

4 release files

0.6.0

4 release files

0.5.7

4 release files

0.5.6

4 release files

0.5.5

4 release files

0.5.3

4 release files

0.5.1

4 release files

0.5.0

4 release files

0.4.9

4 release files

0.4.8

4 release files

0.4.7

4 release files

0.4.2

4 release files

0.4.1

4 release files

0.4.0

4 release files

0.3.9

4 release files

0.3.8

4 release files

0.3.7

4 release files

0.3.6

4 release files

0.3.5

4 release files

0.3.4

4 release files

0.3.2

4 release files

0.3.0

4 release files

0.1.0

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page