Skip to main content

Official Python SDK for KarboAI Bot API

Project description

karbo

Official Python SDK for the KarboAI Bot API.

Installation

pip install karbo

Quick Start

import asyncio
import karbo

BOT_TOKEN = "your-bot-token"

async def main():
    bot = karbo.KarboBot(BOT_TOKEN)
    ws = karbo.KarboBotWS(BOT_TOKEN)

    me = await bot.get_me()
    print(f"Bot: {me.name} ({me.bot_id})")

    @ws.on_message
    async def on_message(message: karbo.Message):
        if message.user_id == me.bot_id:
            return
        await bot.send_message(message.chat_id, f"Echo: {message.content}")

    await ws.run_forever()

asyncio.run(main())

API Reference

KarboBot(token, *, base_url="https://api.karboai.com")

Async HTTP client. Use as a context manager or call .close() when done.

Method Description
get_me() Get bot info (BotInfo)
send_message(chat_id, content, *, reply_to=None, images=None) Send a message with optional images (SentMessage)
upload_image(file_path) Upload a local image, returns its URL (str)
get_message(chat_id, message_id) Get a specific message (Message)
get_chat_members(chat_id, *, limit=100, offset=0) List chat members (list[Member])
get_user(user_id) Get user profile (User)
leave_chat(chat_id) Leave a chat
kick_user(chat_id, user_id) Kick a user (requires helper role)

Sending images

url = await bot.upload_image("photo.jpg")
await bot.send_message(chat_id, "Check this out!", images=[url])

# Send multiple images
urls = [await bot.upload_image(p) for p in ["a.png", "b.png"]]
await bot.send_message(chat_id, "", images=urls)

KarboBotWS(token, *, ws_url="https://api.karboai.com")

WebSocket client for real-time events.

ws = karbo.KarboBotWS(BOT_TOKEN)

@ws.on_message
async def handler(message: karbo.Message):
    ...

@ws.on_connect
async def connected():
    ...

@ws.on_disconnect
async def disconnected():
    ...

await ws.run_forever()

Models

  • BotInfobot_id, name, status
  • Messagemessage_id, chat_id, user_id, content, created_time, type, reply_message_id, author, images
  • SentMessagemessage_id, created_time
  • Useruser_id, nickname, avatar, short_info, role
  • Memberuser_id, nickname, avatar, role
  • Authoruser_id, nickname, avatar

Exceptions

All inherit from karbo.KarboError:

  • AuthenticationError — invalid token (401)
  • ForbiddenError — no permission (403)
  • NotFoundError — resource not found (404)
  • ValidationError — bad request (400)
  • RateLimitError — too many requests (429), has .retry_after
  • APIError — other HTTP errors, has .status and .body

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

karbo-0.1.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

karbo-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file karbo-0.1.0.tar.gz.

File metadata

  • Download URL: karbo-0.1.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.7

File hashes

Hashes for karbo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e7d68f2941700f7f4f4a7e308e1c76da0f1ba034e35125c2da7ecb8a7c4e48f6
MD5 e2eea8dd15c04aa9be56ee92b4bb3147
BLAKE2b-256 1daa3f2396b5dd6afcd6dd8dd1b6b0cc925ebbea4ebb555932442457b2a2491a

See more details on using hashes here.

File details

Details for the file karbo-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: karbo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.7

File hashes

Hashes for karbo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 863eefe45e4d3013b3c9c3eb7ea0b95789ec3297fd75205c784569f86100951c
MD5 ad9a71ffe4341bf9335d69d0821eb987
BLAKE2b-256 1ba30778a0f5527d4999fbd509ba09470270d00d626c4921469bdb19fb3b8a06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page