Skip to main content

Goygram: unified Telegram runtime on Python and Rust

Project description

GoyGram

License: AGPLv3 Python Rust Build Status

GoyGram is a Telegram framework with one clean entrypoint for user code and split low-level lanes under the hood: Bot API on aiohttp, MT transport on raw sockets, Rust for frame and crypto primitives.

Build

python -m venv .venv
source .venv/bin/activate
pip install -U pip maturin aiohttp pydantic
maturin develop

Quick Start

import asyncio

from goygram import GoyGram, InlineKbd, LinkOpts


app = GoyGram(
    bot_token="123456:BOT_TOKEN",
)

kbd = InlineKbd().add_btn("Ping", data="ping")
links = LinkOpts(above=True, large=True)


@app.on_msg
async def echo(msg):
    if not msg.text:
        return
    if msg.text == "/start":
        await app.send_msg(msg.chat_id, "hello https://example.com", kbd=kbd, link_options=links, via=msg.src)
        return
    await msg.reply(f"rx: {msg.text}")


asyncio.run(app.run())

Commands And Callbacks

@app.on_cmd("start", "help")
async def boot(msg):
    await msg.reply("ready")


@app.on_cb
async def taps(cb):
    if cb.data == "ping":
        await cb.answer("pong")
        await cb.edit("updated")

Public API

from goygram import GoyGram, InlineKbd, ReplyKbd, Btn

GoyGram(...) accepts flat config:

  • bot_token
  • mt_host
  • mt_port
  • mt_key
  • mt_iv

Main calls:

  • @app.on_msg
  • @app.on_cmd("start")
  • @app.on_cb
  • @app.on_poll
  • @app.on_member
  • await app.send_msg(chat_id, text, kbd=..., via=...)
  • await app.send_msg(chat_id, text, link_options=...)
  • await app.send_photo(chat_id, photo, caption=...)
  • await app.send_doc(chat_id, document, caption=...)
  • await app.send_media_group(chat_id, media)
  • await app.answer_cb(cb_id, text=...)
  • await app.edit_text(chat_id, msg_id, text)
  • await app.set_webhook(url)
  • await app.delete_webhook()
  • await app.get_webhook_info()
  • await msg.reply(text, kbd=...)
  • await msg.delete()
  • await app.run()

Extra UI helpers:

  • InlineKbd
  • ReplyKbd
  • ForceReply
  • ReplyGone

Package Layout

.
├── ext_rust
│   ├── Cargo.toml
│   └── src/lib.rs
├── goygram
│   ├── __init__.py
│   ├── client.py
│   ├── api
│   ├── core
│   ├── tl
│   ├── types
│   └── vendor
├── tools
│   ├── gen_botapi.py
│   └── gen_mtproto.py
└── tests

Codegen

python tools/gen_botapi.py
python tools/gen_mtproto.py

Generated targets:

  • goygram/api/types.py
  • goygram/api/methods.py
  • goygram/tl/schema.py

Tests

python -m unittest tests.test_matrix -v

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

goygram-0.3.2.tar.gz (19.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

goygram-0.3.2-cp311-abi3-win_amd64.whl (155.4 kB view details)

Uploaded CPython 3.11+Windows x86-64

goygram-0.3.2-cp311-abi3-manylinux_2_34_x86_64.whl (239.7 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.34+ x86-64

goygram-0.3.2-cp311-abi3-macosx_11_0_arm64.whl (222.1 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

Details for the file goygram-0.3.2.tar.gz.

File metadata

  • Download URL: goygram-0.3.2.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for goygram-0.3.2.tar.gz
Algorithm Hash digest
SHA256 b6d819eb633b41a053b4c14bc3e346749ead5a9adcbc1f27543fd6537881441a
MD5 91813010c973deb79e0f2182bc021ab9
BLAKE2b-256 6f9976030b48f12ed2c668329ba7b2b1b1eb6cb99fbb7d55bdc48e59948828fd

See more details on using hashes here.

File details

Details for the file goygram-0.3.2-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: goygram-0.3.2-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 155.4 kB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for goygram-0.3.2-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f6c7cf68a00c7cd6e249d6755319be373e0a12082320ee040890ad766c991d43
MD5 ef4e333099a3d75b8b0277f4bd2f5f5c
BLAKE2b-256 1c1c1c8862688e6657c1fd03748d04a105218e47721a9f5c3c9ac565303a5456

See more details on using hashes here.

File details

Details for the file goygram-0.3.2-cp311-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for goygram-0.3.2-cp311-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5797e98ed7ed27d1134c9ee0b6394ce238ecfb7e32c26cb82a6910c8b0eb66cf
MD5 0b8008dec019056112bccff3f9ceaa8e
BLAKE2b-256 f489e63498312cfc68780adc3200d00a91c5db225a87d45ed730326a5bbc624b

See more details on using hashes here.

File details

Details for the file goygram-0.3.2-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for goygram-0.3.2-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f4be61324df8c93e0ad57d5ed29fc731d5aae9dff4ec203af7d65716257979fd
MD5 b78281ebb6c868d018d6da01cd0b043c
BLAKE2b-256 38be1b5dcc0e838434035fb46cfaccefa1d8830807c7f8f354ec7076e8c8e959

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