Skip to main content

Async Python client for the Polis Bot API

Project description

polis-bot

Async Python client for the Polis Bot API — build bots for the Polis messaging platform.

Installation

pip install -e ./polis-bot-python
# or from the package once published:
# pip install polis-bot

Quick Start

import asyncio
from polis_bot import PolisBot

bot = PolisBot(token="your-bot-api-token")

async def main():
    # Get bot info
    me = await bot.get_me()
    print(f"I am {me.display_name} (@{me.botname})")

    # Register commands
    await bot.set_commands([
        {"command": "start", "description": "Start the bot"},
        {"command": "help", "description": "Show help"},
    ])

    # Poll for updates
    async for update in bot.poll():
        print(f"Update from {update.user.display_name}: {update.type}")

        if update.message and update.message.is_command:
            if update.message.command_name == "start":
                await bot.send_message(
                    user_id=update.user.id,
                    content="Welcome to my bot! 🤖"
                )
            elif update.message.command_name == "help":
                await bot.send_message(
                    user_id=update.user.id,
                    content="**Commands:**\n- /start — Start\n- /help — This message"
                )
        elif update.message and update.message.content:
            # Echo
            await bot.send_message(
                user_id=update.user.id,
                content=f"You said: {update.message.content}"
            )

asyncio.run(main())

Long Polling

The poll() method uses long-polling by default (30s timeout). Customize:

async for update in bot.poll(timeout=10, limit=50):
    ...

File Uploads

await bot.send_file(
    user_id=user_id,
    file_path="image.png",
    content_type="image/png"
)

Acknowledge Updates

Updates are automatically acknowledged after processing in poll(). For manual control:

updates = await bot.get_updates(limit=10)
if updates:
    await bot.acknowledge_updates([u.update_id for u in updates])

API Reference

PolisBot(token, base_url)

Method Description
get_me() Get bot info
send_message(user_id, content, reply_to_id=None) Send text message
send_file(user_id, file_path, content_type) Send a file
get_updates(limit, offset, timeout) Get pending updates
acknowledge_updates(update_ids) Mark updates as delivered
set_commands(commands) Register bot commands
poll(limit, timeout) Async generator for long-polling
close() Close the HTTP client

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

polis_bot-0.2.1.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

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

polis_bot-0.2.1-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file polis_bot-0.2.1.tar.gz.

File metadata

  • Download URL: polis_bot-0.2.1.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for polis_bot-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e672f83e30fcb30c38de1d24363eb241080fc3ec1d421e5bbf87acc15adedfb2
MD5 0ae8c0bd5c06929845a88a58034aa4c9
BLAKE2b-256 eaee86fbe5f1fc3e7afe21377f92879d7a566ae0146aaacac2664e139582604e

See more details on using hashes here.

Provenance

The following attestation bundles were made for polis_bot-0.2.1.tar.gz:

Publisher: sdk-release.yml on roman-right/Polis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polis_bot-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: polis_bot-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for polis_bot-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30c5390a4ffc0629293d495f89f6716623a0911b35be3024722fc0cdeb40d63f
MD5 2c6dd3ca7a333e6a67d65fb3d74915e4
BLAKE2b-256 332fabb7968bffc098461a97ba8f8c6d177f90c7f3f04943325284d02ddb5417

See more details on using hashes here.

Provenance

The following attestation bundles were made for polis_bot-0.2.1-py3-none-any.whl:

Publisher: sdk-release.yml on roman-right/Polis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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