Skip to main content

YukiBot

The official Python library for YukiChat bots. If you know telebot, you already know it.

Installation

pip install -U yukibot

Create a bot by sending /newbot MyCoolBot to @YukiFather in YukiChat. You'll get a yk_bot_... token.

Quick start

from yukibot import YukiBot

bot = YukiBot("yk_bot_your_token_here")

@bot.message_handler(commands=["start"])
def start(message):
    bot.reply_to(message, f"Hi @{message.sender.username}!")

@bot.message_handler(content_types=["photo"])
def photo(message):
    bot.reply_to(message, "Nice photo!")

@bot.message_handler(func=lambda m: True)
def echo(message):
    bot.send_message(message.chat.id, message.text_or_caption)

bot.polling()

polling() uses long polling: the server answers the moment something arrives. A bot never receives its own messages or other bots' messages, so echo bots can't loop.

Buttons

kb = {"inline_keyboard": [[
    {"text": "👍 Like", "callback_data": "like"},
    {"text": "Website", "url": "https://yukichat.lol"},
]]}
bot.send_message(chat_id, "Do you like it?", reply_markup=kb)

@bot.callback_query_handler(data="like")
def liked(call):
    bot.answer_callback_query(call.id, "Thanks!")            # toast; show_alert=True for a dialog
    bot.edit_message_text("You liked it ❤️", call.message.message_id)

Files

Every send_* method takes a URL, a file path, bytes or an open file:

bot.send_photo(chat_id, "cat.jpg", caption="Cat")
bot.send_document(chat_id, open("report.pdf", "rb"))
bot.send_voice(chat_id, "note.ogg")          # converted to a playable voice message
bot.send_media_group(chat_id, [{"type": "photo", "media": "a.jpg"}, {"type": "photo", "media": "b.jpg"}])

Other updates

@bot.edited_message_handler()
def edited(message): ...

@bot.chat_member_handler()
def joined_or_left(event):       # event.user, event.chat, event.event == "join" | "leave"
    ...

@bot.my_chat_member_handler()
def added(event): ...            # the bot was added to / removed from a chat (also when someone opens a DM with it)

@bot.poll_answer_handler()
def voted(answer): ...           # for polls sent with is_anonymous=False

@bot.message_reaction_handler()
def reacted(event): ...

@bot.exception_handler
def on_error(exc, update):       # default: logged, the bot keeps running
    ...

Webhooks

bot.set_webhook("https://example.com/yuki", secret_token="long-random-string")

# Flask
@app.post("/yuki")
def hook():
    ok = bot.process_webhook(request.json, "long-random-string", request.headers)
    return ("", 200) if ok else ("", 403)

Updates are delivered in order and retried if your server is down. While a webhook is set, get_updates() returns error 409.

Errors

API errors raise YukiAPIError with .error_code, .description and .retry_after. Network errors, 429 and 5xx answers are retried automatically (YukiBot(token, retries=3, timeout=30)).

Groups

To manage a group, a bot must be an admin with the matching right: ban_chat_member needs ban users, pin_chat_message needs pin messages, delete_message for other people's messages needs delete messages, and so on.

Upgrading from 1.x

1.x code keeps working: the camelCase methods (sendMessage, editMessageText, …) are still there. Changes:

  • sendChatAction(chat_id, action) now needs the chat id.
  • content_type='photo' still works, but prefer content_types=['photo'].
  • Commands match exactly: commands=['start'] no longer fires on /startgame, but does on /start@YourBot.
  • The client-side cache was removed, so admin checks are never stale.

Metadata

Release files for yukibot 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yukibot 2.0.0
File Size Uploaded Provenance
yukibot-2.0.0.tar.gz 12.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for yukibot 2.0.0
File Interpreter ABI Platform
yukibot-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.6 kB

Release files / yukibot-2.0.0.tar.gz

Download URL yukibot-2.0.0.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e119c1e91100142c3c3b620ab8eab4f70b844f7e61f189e6b3da9e8ae90d5085
BLAKE2b-256 checksum
How to use checksums
c0a4a60361b76ef9830c2daf21da16949706084feb98796569534f459587a08b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Release files / yukibot-2.0.0-py3-none-any.whl

Download URL yukibot-2.0.0-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
854c9af5c9e8feab5c014dd93bcbe03ae7543c9774ccd4cdbe259b9c7a76e2d5
BLAKE2b-256 checksum
How to use checksums
261367943cedc5528bab8c0e91fc5b6c42bb30e3e796a894972009d4111f696a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Security for yukibot 2.0.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page