Skip to main content

Мощный фреймворк для создания Telegram ботов.

Project description

gramix

PyPI Python License

Мощный фреймворк для создания Telegram ботов на Python.

pip install gramix

Примеры

Простой бот

from gramix import Bot, Dispatcher, Router
from gramix.env import load_env

load_env()

bot = Bot()
rt  = Router()
dp  = Dispatcher(bot)

@rt.message("/start")
def on_start(msg):
    msg.reply(f"Привет, {msg.from_user.first_name}!")

@rt.message()
def echo(msg):
    msg.reply(msg.text)

dp.include(rt)
dp.run()

Inline клавиатура

from gramix import Inline

@rt.message("/menu")
def on_menu(msg):
    kb = Inline()
    kb.button("Да", callback="yes")
    kb.button("Нет", callback="no")
    msg.reply("Выбери:", keyboard=kb)

@rt.callback("yes")
def on_yes(call):
    call.answer("Отлично!")
    call.message.edit("✅ Выбрано: Да")

FSM

from gramix import State, Step

class Form(State):
    name = Step()
    age  = Step()

@rt.message("/start")
def on_start(msg):
    state = rt.fsm.get(msg.from_user.id)
    state.set(Form.name)
    msg.reply("Как тебя зовут?")

@rt.state(Form.name)
def get_name(msg, state):
    state.data["name"] = msg.text
    state.next()
    msg.reply("Сколько лет?")

@rt.state(Form.age)
def get_age(msg, state):
    name = state.data["name"]
    state.finish()
    msg.reply(f"{name}, {msg.text} лет — записал.")

Async

@rt.message("/start")
async def on_start(msg):
    await msg.answer("Привет!")

dp.run_async()

Больше примеров в папке examples/.


Лицензия

MIT © riokzy

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

gramix-0.1.1.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

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

gramix-0.1.1-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

Details for the file gramix-0.1.1.tar.gz.

File metadata

  • Download URL: gramix-0.1.1.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/34.0 requests/2.32.5 requests-toolbelt/1.0.0 urllib3/2.6.3 tqdm/4.67.3 importlib-metadata/8.7.1 keyring/25.7.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.13.12

File hashes

Hashes for gramix-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cc7d294f944d96c4253235f479c5344292d44fb24a7d7e38d45eeae9d26f01bb
MD5 2c98bbb9bb37b9dbd998c6f441834fe2
BLAKE2b-256 f41edaaa4dba40eb0aab394405a29e1105edf88c14196a98d014f6a16a570011

See more details on using hashes here.

File details

Details for the file gramix-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: gramix-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 25.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/34.0 requests/2.32.5 requests-toolbelt/1.0.0 urllib3/2.6.3 tqdm/4.67.3 importlib-metadata/8.7.1 keyring/25.7.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.13.12

File hashes

Hashes for gramix-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1ef7c11c858dcd9fe475c55f5191ab083ab20351fecc8b98e75d6ae1a9187b9e
MD5 2828976314988b05fc13357a3102d7ba
BLAKE2b-256 696050ef463a9f6cd31f90d4229301c2751fa447ded3872815cb4c2f22d811a3

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