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.1.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.1.0-cp311-cp311-win_amd64.whl (125.0 kB view details)

Uploaded CPython 3.11Windows x86-64

goygram-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl (262.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

goygram-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (223.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: goygram-0.1.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.1.0.tar.gz
Algorithm Hash digest
SHA256 578924f481ca6f3ec95dbddf456b8171ef548f5ecdcf98d3db72316c8b1b4563
MD5 e37ee5c2d13c685943ad5db7d1dfe2d5
BLAKE2b-256 707cf9a9d0143e5954dd5e8785a8533f415e31a600bb155a65dd1153d94a8876

See more details on using hashes here.

File details

Details for the file goygram-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: goygram-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 125.0 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.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ecc0c58fcc05c4be48fa072cb9aedd364bc96cfaaa5684649283e5da05e457f4
MD5 e0e0c11b2b9c003b78f351eacf9d09f9
BLAKE2b-256 e8ccc3aaf37aca3164a07f694da7d06652fc44b37d9e782789aed7e701b37fde

See more details on using hashes here.

File details

Details for the file goygram-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for goygram-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 48b9ac64d7a490a0f93d79e105d47a9bc698cde338796c78281431833d0f2ee0
MD5 15b8c8bbc097c8eb94cd6ab1df93184b
BLAKE2b-256 be377c604ae90a88912634a12913a8c292adf0a3e841b701deb5e50bbc36c477

See more details on using hashes here.

File details

Details for the file goygram-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for goygram-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 81771daea6e6555aed0053851b51ac0c3849e90740b8ef30e080c3d802f801ba
MD5 79230d6b7cf9f1ed824b60325d4d6134
BLAKE2b-256 586c290cde712e994fc6b7dd3e0e2f6f3207e2f2d9bc266f32d354ed1b51dc45

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