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.1.0.tar.gz
(21.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
polis_bot-0.1.0-py3-none-any.whl
(13.7 kB
view details)
File details
Details for the file polis_bot-0.1.0.tar.gz.
File metadata
- Download URL: polis_bot-0.1.0.tar.gz
- Upload date:
- Size: 21.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3e971feb7bddcc4bfb01ef74dad35a939b296f7600c0bca51bb67afca55c23f
|
|
| MD5 |
a65b261d9d61ede11e97f4966327fdd5
|
|
| BLAKE2b-256 |
13967a831702174c881abf9a5c3369e28dcc5c772f5cfdca834ccd4277f803a5
|
File details
Details for the file polis_bot-0.1.0-py3-none-any.whl.
File metadata
- Download URL: polis_bot-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8abcb57f61a69fbfcd8effe192638fb5ef9cef79c96503dc2a0a8b747b3e0886
|
|
| MD5 |
a4be671a2c4e62f7e32f2081e21e7c0f
|
|
| BLAKE2b-256 |
a3b9314cebd4308a785bc4ac0bf876fcb87d7a1f35a3e9ebf607e7134ef50fbe
|