PyGrammY — bu Python uchun to‘liq asinxron, grammy.js’dan ilhomlangan, zamonaviy Telegram Bot Framework.
U async/await, httpx, middleware, session, filters va modular arxitekturani qo‘llab-quvvatlaydi.
- ⚡ To‘liq asinxron (
async/await) - 🌐
httpxasosida Telegram Bot API - 🧠 Context (ctx) — barcha ma’lumotlar bitta joyda
- 🔌 Middleware chain (GrammyJS uslubida)
- 💾 Session (memory & file storage)
- 🧩 Composer — modular bot arxitekturasi
- 🎯 Kuchli filters
- ⌨️ Inline & Reply Keyboards
- 🪝 Polling va Webhook qo‘llab-quvvatlanadi
- 🛡 Global error handling
pip install pygrammypip install httpx aiohttpproject/
├── pygrammy/
│ ├── bot.py
│ ├── context.py
│ ├── keyboard.py
│ ├── session.py
│ ├── filters.py
│ ├── composer.py
│ ├── types.py
│ └── __init__.py
└── main.py
import asyncio
from pygrammy import Bot
bot = Bot("YOUR_BOT_TOKEN")
@bot.command("start")
async def start(ctx):
await ctx.reply("👋 Salom, PyGrammY ishlayapti!")
async def main():
async with bot:
await bot.start()
asyncio.run(main())@bot.use
async def logger(ctx, next):
print(ctx.update.update_id)
await next()from pygrammy import session
bot.use(session(initial=lambda: {"count": 0}))
@bot.on("message:text")
async def counter(ctx):
ctx.session["count"] += 1
await ctx.reply(f"Count: {ctx.session['count']}")from pygrammy import InlineKeyboard
kb = InlineKeyboard()
kb.text("👍 Like", "like").row().url("Google", "https://google.com")
await ctx.reply("Tanlang:", reply_markup=kb)@bot.on("message:photo")
async def photo_handler(ctx):
await ctx.reply("📸 Rasm qabul qilindi")Custom filter:
@bot.filter(lambda ctx: ctx.chat.type == "private")
async def private_only(ctx):
await ctx.reply("Private chat")@bot.callback_query("like")
async def like(ctx):
await ctx.answer_callback_query("👍")await bot.start(webhook={
"domain": "https://example.com",
"path": "/webhook",
"port": 8443
})| Xususiyat | GrammyJS | PyGrammY |
|---|---|---|
| Til | JS / TS | Python |
| Async | Promise | async/await |
| HTTP | fetch | httpx |
| Typing | TypeScript | type hints |