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()

Больше примеров в репозитории.


Лицензия

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.2.tar.gz (20.8 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.2-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gramix-0.1.2.tar.gz
  • Upload date:
  • Size: 20.8 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.2.tar.gz
Algorithm Hash digest
SHA256 100c42edc7cfc94f03e222a6ce28a5c5db173ca96e8b7c3cbab11246ebf419d4
MD5 b89e2bcbb07e2433f36863ef24766487
BLAKE2b-256 0c9ec63c432c4147e8a6331bf72717125f345043f1818b9b5fda324ed77e92e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gramix-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 48c202aa6645db72063459bfd94d809e692d7a677251c8bcb82c29b9918fc7fc
MD5 97a8d89ac4be067161d98dc562ff3870
BLAKE2b-256 ad5d3036c2b2987e5a535bd5a136576770d8cbd260fc24bd8856cc0d6f1582dd

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