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
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
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e672f83e30fcb30c38de1d24363eb241080fc3ec1d421e5bbf87acc15adedfb2
|
|
| MD5 |
0ae8c0bd5c06929845a88a58034aa4c9
|
|
| BLAKE2b-256 |
eaee86fbe5f1fc3e7afe21377f92879d7a566ae0146aaacac2664e139582604e
|
Provenance
The following attestation bundles were made for polis_bot-0.2.1.tar.gz:
Publisher:
sdk-release.yml on roman-right/Polis
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polis_bot-0.2.1.tar.gz -
Subject digest:
e672f83e30fcb30c38de1d24363eb241080fc3ec1d421e5bbf87acc15adedfb2 - Sigstore transparency entry: 1008261865
- Sigstore integration time:
-
Permalink:
roman-right/Polis@029ad73d427b945ad9d01b7675b9f8a29c9efcd4 -
Branch / Tag:
refs/tags/sdk-v0.2.1 - Owner: https://github.com/roman-right
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-release.yml@029ad73d427b945ad9d01b7675b9f8a29c9efcd4 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30c5390a4ffc0629293d495f89f6716623a0911b35be3024722fc0cdeb40d63f
|
|
| MD5 |
2c6dd3ca7a333e6a67d65fb3d74915e4
|
|
| BLAKE2b-256 |
332fabb7968bffc098461a97ba8f8c6d177f90c7f3f04943325284d02ddb5417
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polis_bot-0.2.1-py3-none-any.whl -
Subject digest:
30c5390a4ffc0629293d495f89f6716623a0911b35be3024722fc0cdeb40d63f - Sigstore transparency entry: 1008261867
- Sigstore integration time:
-
Permalink:
roman-right/Polis@029ad73d427b945ad9d01b7675b9f8a29c9efcd4 -
Branch / Tag:
refs/tags/sdk-v0.2.1 - Owner: https://github.com/roman-right
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-release.yml@029ad73d427b945ad9d01b7675b9f8a29c9efcd4 -
Trigger Event:
push
-
Statement type: