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.0.tar.gz (5.7 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.0-cp311-abi3-win_amd64.whl (125.1 kB view details)

Uploaded CPython 3.11+Windows x86-64

goygram-0.3.0-cp311-abi3-manylinux_2_34_x86_64.whl (209.7 kB view details)

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

goygram-0.3.0-cp311-abi3-macosx_11_0_arm64.whl (192.2 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for goygram-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4fae9fbe37cedae6e41edecc18d2b6983be812dc18e400b07d4668f87c78c6ab
MD5 af542c2d2ef98c7c8c07f02fb9b99731
BLAKE2b-256 bdbf4046865527402374d88e30a37eee79a21612f2f316bd24aa192bbf980b2f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: goygram-0.3.0-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 125.1 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.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 884b7f712060eb14c4a6dacbd1bedd942c1ca7d1f3137abf99f0233311269e19
MD5 c577a18d2c4c0216d1cd8d662da1e744
BLAKE2b-256 6d42a7bc469bc53d983425613d2dce3bc4dbfbc9538e14aad5d662c8fc11a7ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for goygram-0.3.0-cp311-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 aa810cd6af67b81d074334bcd7083a9ebcbd8c478a33db923f3b95d60051bcfb
MD5 72904bfe3bab2a25de695b6fd8765744
BLAKE2b-256 b417a566ee57688f8113830fce9e84ffd96afc20ab79ac60716ff9ec250c2145

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for goygram-0.3.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4dbeae50de9d105f2e7156d8fbc4b5ebd6ac9e07f2ddb92679f071ba5d1f574a
MD5 70082f3d9dc9dcb9239928ab4d7e8172
BLAKE2b-256 5bb33d109bf4d4c790299246cb5c5116487d382fedf4a15f918f64b97a8b1cf4

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