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.4.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.4-cp311-abi3-win_amd64.whl (155.4 kB view details)

Uploaded CPython 3.11+Windows x86-64

goygram-0.3.4-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.4-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.4.tar.gz.

File metadata

  • Download URL: goygram-0.3.4.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.4.tar.gz
Algorithm Hash digest
SHA256 68d790b466bf4ab8878f8f9deeb3885c991cfc0e3a847a24b83ae7da80d18900
MD5 b464be036368d34ac106c230b44e306a
BLAKE2b-256 49dd2bf6323c922ff5b40b0a3acbcf31d2c56e5cfac9d68b5933bc6a373c4af3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: goygram-0.3.4-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.4-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f03e7c887654eb8e84db3275aab58a6c6ad5cb69faae88d8c6088eafae763fec
MD5 cad8f950c493e92a97ed8c92964c381f
BLAKE2b-256 748611da0957bc6db53cc6085e91eac7f04d42f949806bf481e5ae9153ec9038

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for goygram-0.3.4-cp311-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0f3a59e665220ebf8626d58958c49695c1506b720f329a3c5ae467aa121ddb21
MD5 27480fc710527efe5feeee593a830cce
BLAKE2b-256 06ce38932f2eb11ddceec93a266f8a1a224296ab3f9a510ef647770013b7df74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for goygram-0.3.4-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 07f6fee2c6dbb214057f9abb1076ec06f8a26a70ebec1ab7781dbfca13ac91e5
MD5 9599f33588e55c98e27cf75a14effcdb
BLAKE2b-256 6f30186b3aab90fb7824fda7c2d861ae1efc3316aee97006dbc9e46e7b8bf02a

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