Skip to content

oscoderuz/pygrammy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

🐍 PyGrammY

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.


🚀 Xususiyatlar

  • ⚡ To‘liq asinxron (async/await)
  • 🌐 httpx asosida 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

📦 O‘rnatish

PyPI orqali (kelajakda)

pip install pygrammy

Lokal o‘rnatish

pip install httpx aiohttp
project/
├── pygrammy/
│   ├── bot.py
│   ├── context.py
│   ├── keyboard.py
│   ├── session.py
│   ├── filters.py
│   ├── composer.py
│   ├── types.py
│   └── __init__.py
└── main.py

🧑‍💻 Minimal misol

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

🧩 Middleware

@bot.use
async def logger(ctx, next):
    print(ctx.update.update_id)
    await next()

💾 Session

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']}")

⌨️ Inline Keyboard

from pygrammy import InlineKeyboard

kb = InlineKeyboard()
kb.text("👍 Like", "like").row().url("Google", "https://google.com")

await ctx.reply("Tanlang:", reply_markup=kb)

🎯 Filters

@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")

🪝 Callback Query

@bot.callback_query("like")
async def like(ctx):
    await ctx.answer_callback_query("👍")

🌐 Webhook

await bot.start(webhook={
    "domain": "https://example.com",
    "path": "/webhook",
    "port": 8443
})

🆚 GrammyJS bilan taqqoslash

Xususiyat GrammyJS PyGrammY
Til JS / TS Python
Async Promise async/await
HTTP fetch httpx
Typing TypeScript type hints

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages