yukibot Library Reference

Welcome to the official yukibot Python library documentation. This framework provides a simple, synchronous, Telebot-like wrapper around the YukiChat Bot API, fully optimized for Cloudflare D1 integration.

Quick Start

Install the library via PIP and initialize your bot in just a few lines of code.

pip install yukibot
from yukibot import YukiBot

bot = YukiBot("yk_bot_YOUR_TOKEN_HERE")

@bot.message_handler(commands=['start'])
def send_welcome(message):
    bot.reply_to(message, "Hello! I am a YukiChat Bot built with Python.")

if __name__ == '__main__':
    bot.polling()

Below is the complete reference for all **37 API methods** mapped directly to Python functions inside the YukiBot class, along with library-exclusive helper decorators.

Architecture & Data Flow

YukiChat is built entirely on Cloudflare's Edge network. The yukibot Python library is designed to seamlessly interface with this infrastructure, offering smart D1 caching to save database read quotas automatically.

📱 YukiChat Client App
⚡ Cloudflare Edge Worker (REST API)
🗄️ Cloudflare D1 (SQLite)

Stores Messages, Users,
& Chat Settings

📡 Webhook / Polling Dispatcher
🐍 Your Python Script
bot.polling()

How it works with Python

1. Receiving Updates: When using bot.polling(), your script constantly asks the Cloudflare Edge Worker if there are new messages. The Worker reads the D1 database efficiently using indexed cursors and returns updates.

2. Routing via Decorators: The yukibot library intercepts these raw JSON updates, transforms them into object-oriented Message and Update structures (via DotDict), and routes them to your @bot.message_handler() functions.

3. Smart D1 Caching: Calling methods like bot.getChat() or bot.getStickerSet() triggers database reads. To save your Cloudflare D1 quotas, yukibot automatically caches read-only queries in memory (TTL 60-120s). Repeated calls for the same chat info won't cost network overhead!

Usage & FAQ

Everything you need to know about building bots in Python using the yukibot library.

How do I create a bot token?

Open YukiChat, search for @YukiFather, and send the /start command. Then, send /newbot <your_bot_name>. Note that your bot's username must end in "bot" (e.g., WeatherBot). YukiFather will reply with your token which you pass into YukiBot("TOKEN").

How do message handlers work?

The library provides a @bot.message_handler decorator. You can filter by commands, functions, or content types. Example: @bot.message_handler(commands=['help'], content_type='text') will only trigger if the user sends "/help" as a text message.

What is DotDict in the library?

Unlike raw dictionaries where you have to type message['chat']['id'], yukibot converts JSON into DotDict objects. This allows you to write beautiful, object-oriented code like message.chat.id and message.sender.username.

Polling vs. Webhooks

The library natively supports bot.polling() which is great for development or running on standard VPS containers. If you wish to use serverless environments (like AWS Lambda or Vercel), you can use bot.setWebhook("url") and pass incoming JSON directly to bot.process_new_updates([update_json]).

How do Inline Keyboards work?

You can pass a dictionary to the reply_markup parameter of any sending method. It should contain an inline_keyboard array. Example:
markup = {"inline_keyboard": [[{"text": "Click Me", "callback_data": "btn1"}]]}
bot.sendMessage(chat_id, "Choose:", reply_markup=markup)