nicebot
Telegram bot yozing. Kam kod bilan.
Savol-javob, tugmalar, baza va admin panel bitta importda tayyor turadigan Python kutubxonasi.
Siz faqat botingiz nima qilishini yozasiz.
Hujjatlar · Tez start · Imkoniyatlar · Misol
🇺🇿 O'zbekcha · 🇷🇺 Документация · 🇬🇧 Documentation
Bir qarashda
from nicebot import Nicebot
bot = Nicebot(token="123456:ABC...")
@bot.command("start")
async def start(ctx):
name = await ctx.ask("Ismingiz?")
age = await ctx.ask("Yoshingiz?", int)
await ctx.reply(f"Salom, {name}! Siz {age} yoshdasiz.")
bot.start()
Telegram'da foydalanuvchi ko'radigan natija:
👤 /start
🤖 Ismingiz?
👤 Ali
🤖 Yoshingiz?
👤 yigirma
🤖 Butun son kiriting. ← son bo'lmasa, o'zi qayta so'raydi
👤 20
🤖 Salom, Ali! Siz 20 yoshdasiz.
Bu kodda Dispatcher, StatesGroup va FSM yo'q. ctx.ask() savol beradi va javobni shu funksiya ichida kutadi. Foydalanuvchi esa bazaga avtomatik saqlanadi.
aiogram bilan solishtirganda
Ism va yoshni so'raydigan bir xil bot:
| aiogram 3 | nicebot | |
|---|---|---|
| Kod hajmi | 34 qator | 8 qator |
Holatlar klassi (StatesGroup) |
kerak | yo'q |
FSMContext, Dispatcher, Router |
kerak | yo'q |
| Son tekshiruvi va qayta so'rash | o'zingiz yozasiz | int deb yozish kifoya |
| Foydalanuvchini bazaga saqlash | o'zingiz yozasiz | avtomatik |
🚀 Tez start
1. O'rnating — Python 3.10 yoki yangisi kerak:
pip install nicebot
2. Yozing — @BotFather'dan token oling va bot.py yarating:
from nicebot import Nicebot
bot = Nicebot(token="123456:ABC...")
@bot.command("start")
async def start(ctx):
await ctx.reply(f"Salom, {ctx.name}!")
bot.start()
3. Ishga tushiring:
python bot.py
Telegram'da botingizga /start yozing — u ismingiz bilan salomlashadi. 🎉
Tayyor loyiha tuzilmasi kerakmi?
nicebot new mybot && cd mybot && python bot.py—.env,handlers/valocales/bilan loyiha yaratadi.
Boshqa bazalar bilan
| Buyruq | Nima qo'shadi |
|---|---|
pip install nicebot |
SQLite (qo'shimcha o'rnatishsiz) |
pip install "nicebot[postgres]" |
PostgreSQL |
pip install "nicebot[mysql]" |
MySQL / MariaDB |
pip install "nicebot[mongo]" |
MongoDB |
pip install "nicebot[redis]" |
Redis |
pip install "nicebot[all]" |
hammasi |
Kod bir xil qoladi, faqat manzil o'zgaradi: Nicebot(token=..., db="postgresql://...").
📦 Ichida nimalar bor
Hammasi kutubxonaning o'zida — qo'shimcha paket o'rnatmasdan.
| Mavzu | Nima beradi | Qo'llanma |
|---|---|---|
| 💬 Suhbatlar | ask, confirm, choose(multiple=True), form — FSM klasslarisiz savol-javob |
Suhbatlar |
| ✅ Validatorlar | Telefon (+998), email, sana, son, URL, rasm, joylashuv… | Validatorlar |
| 🔘 Tugmalar | Button(on_click=func), "buy:{id:int}" shablonlari, Toggle, ttl, once, only, avto-joylashuv |
Tugmalar |
| 🧭 Menyular | Ko'p darajali Menu ("Orqaga" o'zi qo'shiladi), ctx.paginate() |
Menyular |
| 🗄 Baza (ORM) | SQLite, PostgreSQL, MySQL va MongoDB uchun bitta API, avto-migratsiya | Baza |
| 👥 Foydalanuvchilar | Avtomatik saqlash, o'z maydonlaringiz, referal tizimi | Foydalanuvchilar |
| 🌍 Ko'p tillilik | ctx.t(), JSON tarjimalar, uz / ru / en tayyor matnlar |
i18n |
| 📊 Admin panel | /stats, /broadcast, /maintenance, /backup, xatolar haqida hisobot |
Admin |
| 📣 Broadcast | Tezlik chegarasi, bloklanganlarni belgilash, to'xtagan joydan davom ettirish | Broadcast |
| ⭐ To'lovlar | Telegram Stars: ctx.invoice() va @bot.paid |
To'lovlar |
| 🛡 Guruhlar | ban, mute, warn, captcha, majburiy obuna, support rejimi |
Guruhlar |
| 📱 Mini App | @bot.api endpointlari, initData HMAC tekshiruvi, tayyor nicebot.js |
Mini App |
| 🧩 Arxitektura | DI (type hint orqali), middleware, Router, from_env(), scheduler, fon vazifalari, kesh |
Middleware |
| 🔁 Ishonchlilik | Flood-wait, retry, file_id keshi, to'g'ri to'xtash — restartda update yo'qolmaydi | Deploy |
| 🧪 Testlar | bot.test() — botni Telegram'siz, haqiqiy foydalanuvchidek sinash |
Testlash |
| 🤖 Bot API 10.3 | 185 ta metod va 403 ta tur rasmiy spetsifikatsiyadan generatsiya qilingan (msgspec) | Bot API |
Barcha 50 ta imkoniyat bitta sahifada: Imkoniyatlar ro'yxati →
🛒 To'laroq misol
Mahsulot tanlash, telefon so'rash, tasdiqlash, bazaga yozish va adminga xabar — barchasi bitta faylda:
from nicebot import Nicebot, Button, Model, fields, Phone
bot = Nicebot(token="...", db="sqlite:///shop.db", admins=[123456789])
class Order(Model):
user_id = fields.BigInt(index=True)
product = fields.Str(100)
phone = fields.Str(20)
async def buy(ctx, product: str):
phone = await ctx.ask("Telefon raqamingiz?", Phone)
if await ctx.confirm(f"{product} buyurtma qilinsinmi?"):
await Order.create(user_id=ctx.user_id, product=product, phone=phone)
await ctx.reply("✅ Qabul qilindi!")
await ctx.notify_admins(f"🛒 Yangi buyurtma: {product}, {phone}")
@bot.command("shop", description="Do'kon")
async def shop(ctx):
await ctx.reply("Mahsulotni tanlang:", buttons=[
Button("📚 Kitob", on_click=buy, product="Kitob"),
Button("🎧 Quloqchin", on_click=buy, product="Quloqchin"),
])
bot.start(reload=True)
Nima bo'layapti:
Button(..., on_click=buy, product="Kitob")— tugma bosilgandabuy(ctx, product="Kitob")chaqiriladictx.ask(..., Phone)— raqamni istalgan ko'rinishda qabul qiladi va+998901234567ga keltiradictx.confirm()— "✅ Ha / ❌ Yo'q" tugmalari bilan so'raydi,TrueyokiFalseqaytaradiOrderjadvali bot ishga tushganda o'zi yaratiladiadmins=[...]berilgani uchun/stats,/broadcast,/maintenanceva/backupham ishlaydireload=True— faylni saqlaganingizda bot o'zi qayta ishga tushadi
Telegram'siz test
async def test_shop():
async with bot.test() as t:
user = t.user(first_name="Ali")
await user.send("/shop")
await user.click("Kitob")
await user.send("90 123 45 67")
await user.click("Ha")
assert t.last_in(user.chat_id).text == "✅ Qabul qilindi!"
pytest va pytest-asyncio bilan ishlaydi.
📚 Hujjatlar
To'liq qo'llanma o'zbek, rus va ingliz tillarida: https://ozodmeofficial.github.io/nicebot/
| Bo'lim | Ichida |
|---|---|
| Boshlash | Kirish, o'rnatish, birinchi bot, asosiy tushunchalar |
| Asoslar | Handlerlar, ctx, matn formatlash |
| Tugmalar va suhbat | Tugmalar, klaviatura, suhbatlar, validatorlar, holat, menyular |
| Ma'lumotlar | Baza (ORM), foydalanuvchilar, ko'p tillilik |
| Biznes vositalari | Admin panel, broadcast, to'lovlar, guruhlar |
| Ilg'or | Middleware, Mini App, rejalashtirish, deploy, testlash |
🛠 Ishlab chiqish
pip install -e ".[dev]"
pytest # testlar
python docs/src/build.py # hujjatlar sayti → docs/index.html
Litsenziya
MIT © Ozodbek Sobirjonovich
Metadata
Release files for nicebot 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nicebot-0.1.1.tar.gz | 138.0 kB | With provenance | Details for nicebot-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nicebot-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for nicebot-0.1.1-py3-none-any.whl |
Total release size: 280.6 kB
Release files / nicebot-0.1.1.tar.gz
| Download URL | nicebot-0.1.1.tar.gz |
|---|---|
| Size | 138.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a39ae8a12c619db6025557ea5185a497c0a1b21ab54cbd46a7fdf2de3c20dbee
|
|
BLAKE2b-256 checksum How to use checksums |
9a6ecbee2ae7aa7e2405db0112f1ff673089b20d9ddd2fe5f056d88ca82253a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logRelease files / nicebot-0.1.1-py3-none-any.whl
| Download URL | nicebot-0.1.1-py3-none-any.whl |
|---|---|
| Size | 142.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1553f9391abaa989717808e413cae4c7f60fefbc800861ed389491bafab2c326
|
|
BLAKE2b-256 checksum How to use checksums |
764f8b28ad13b1c378f950a3a3baa63ff5043fcb47bce51cccff447237e8cdf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logSecurity for nicebot 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for nicebot-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.