Python quickstart
This walks you from nothing to a bot that posts a message, answers !ping with pong, and plays an audio file in a voice room. It uses the async Python SDK in sdk/python (yuva_bot), built on httpx, livekit and aiortc. Python 3.10 or newer.
1. Create the bot#
In Yuva, open Ayarlar → Geliştirici and use Bot oluştur (a name, and optionally what it does).
Copy the token (
yb_…) right away: it is shown once. If you lose it, Anahtarı yenile gives a new one and the old one stops working. Keep it out of your code and out of git; the examples read it fromYUVA_BOT_TOKEN.Copy the bot id (
bot_…) with Kimliği kopyala.
See authentication for how the token is sent and what to do when it is revoked.
2. Get it into a lodge#
A bot only sees the lodges it was added to. Someone with the manageBots staff right in the lodge (the owner, or a role that has it) opens the lodge settings, Botlar, pastes the bot id and picks what the bot may do: read, write, speak, mention, and so on. They can change or take away those rights at any time. To post you need write, to join voice speak. Permissions lists every right.
3. Install the SDK#
From the Yuva repository root (a virtualenv is a good idea):
sh
python -m venv .venv && . .venv/bin/activate # Windows: .venv\Scripts\activatepip install ./sdk/pythonThis also installs livekit (LiveKit's Python SDK, wheels for Windows, macOS and Linux), aiortc and PyAV. PyAV's wheels bundle the FFmpeg libraries, so you need no separate FFmpeg to decode MP3, OGG, WAV or other audio files. Lodges whose voice runs on LiveKit refuse SDKs older than 0.2.0, so update the SDK when you pull a newer Yuva.
4. Post a message#
python
import asyncio, osfrom yuva_bot import Clientasync def main(): async with Client(os.environ["YUVA_BOT_TOKEN"], "https://yuva.chat") as bot: me = await bot.me() print("I am", me["displayName"], me["userId"]) for lodge in await bot.lodges(): view = await bot.lodge(lodge["id"]) room = next(c for c in view["channels"] if c["kind"] == "text" and c["perms"]["write"]) await bot.send_message(room["id"], "Merhaba! 👋")asyncio.run(main())The second argument is your Yuva site; the SDK talks to <site>/api/bot/v1. Every method maps to one endpoint of the API reference and returns its JSON as plain dicts (typed as TypedDicts in yuva_bot.types). A failed call raises yuva_bot.ApiError with .status and .message (the server's Turkish message, fine to show to people).
Files: f = await bot.upload_file(channel_id, "rapor.pdf"), then await bot.send_message(channel_id, "Rapor", file_id=f["id"]). Attachments need a trusted account, see the reference.
5. Answer messages#
python
import asyncio, osfrom yuva_bot import Clientasync def main(): async with Client(os.environ["YUVA_BOT_TOKEN"], "https://yuva.chat") as bot: @bot.on("message.create") async def ping(event): message = event["message"] if message["body"].strip() == "!ping": await bot.send_message(event["channelId"], "pong") await bot.react(message["id"], "heart") # or one Unicode emoji: "🔥", "👍🏽", "🇹🇷" await bot.run()asyncio.run(main())run() polls GET /events every 1.5 seconds across every text room the bot can read, keeps the cursor, polls again at once after a full page, and backs off on 429/5xx. It skips the bot's own messages (pass include_own=True to get them) and raises ApiError on 401, since a revoked token never comes back. Handlers can be plain functions or coroutines; each event runs as its own task, so a slow handler doesn't hold up the rest. Also available: message.update (edits, reactions, pins) and message.delete (event["messageId"]). bot.stop() ends run().
Stay within the rate limits: the events loop and a voice connection use a fraction of them.
6. Play audio in a voice room#
python
import asyncio, osfrom yuva_bot import Client, SeatLostasync def main(): async with Client(os.environ["YUVA_BOT_TOKEN"], "https://yuva.chat") as bot: lodge_id = (await bot.lodges())[0]["id"] view = await bot.lodge(lodge_id) room = next(c for c in view["channels"] if c["kind"] == "voice" and c["perms"]["speak"]) voice = await bot.join_voice(lodge_id, room["id"], on_lost=lambda reason: print("seat lost:", reason)) try: await voice.play("song.mp3") # returns when the file ends except SeatLost as lost: print("kicked out:", lost.reason) finally: await voice.leave()asyncio.run(main())join_voice takes the seat and keeps it alive with a beat every 5 seconds. In a lodge whose voice runs on LiveKit (most of them) it asks the server for a media ticket and joins the room's LiveKit room, where it publishes one microphone track while a file plays; in an older mesh lodge it dials everyone in the room over WebRTC instead. voice.transport tells which ("sfu" or "mesh"); your code is the same either way. People who join later get the bot's audio too, including the rest of a file that is already playing. While nothing plays (or after voice.set_muted(True)) the bot sends nothing and shows as muted; it never listens to the room and shows as deafened. voice.stop() ends the current file early, and voice.peers is the peer list from the latest beat.
If a moderator moves the bot, it follows to the new room. If a moderator disconnects it, speak is taken away, or it is removed from the lodge, or another process takes the seat over, the connection closes: on_lost(reason) runs and a pending play() raises SeatLost. Leaving the async with block leaves any seat still open. The voice guide describes the protocol underneath if you want to know what the SDK does.
Next#
API reference: every endpoint, object and error.
Voice guide: the LiveKit and mesh flows behind
join_voice.Permissions and rate limits.