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

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.1
File Size Uploaded Provenance
yukibot-2.0.1.tar.gz 12.5 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 23.9 kB

Release files / yukibot-2.0.1.tar.gz

Download URL yukibot-2.0.1.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d632f5b05167fd67cffd855f51c9baa42a8b392ca3af81ad036454aa6a77afb7
BLAKE2b-256 checksum
How to use checksums
d079d6abba7b2a1bfc1c33ee468016a54cf344cfcae34d75c2db6d0edddc0255
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.1-py3-none-any.whl

Download URL yukibot-2.0.1-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
10fbbe01e70f5f9717e8121b4480c7991b767f358f2dcdc4de2f3f3d60c11f46
BLAKE2b-256 checksum
How to use checksums
5e8c3785b0873a1f13674bef42bc2f8d80fba02243907e807ed7430d9eb36fd8
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.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.

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