Async Python SDK for building bots on the Luffa messaging platform
Project description
Luffa Bot Python SDK
Async, OpenAI-style SDK for building bots for the Luffa messaging platform.
Features
- Fully async (based on
httpxandasyncio) - OpenAI-style interface (
luffa_bot.robot_key = "...") - Simple APIs:
receive(),send_to_user(),send_to_group(), andrun() - Advanced group messages with buttons, confirms, and @mentions
- Built-in deduplication, concurrency control, and middleware support
- CLI for quick bot setup
Installation
pip install luffa-bot-python-sdk
Requires Python 3.9+.
Quickstart
import asyncio
import luffa_bot
# Set the robot secret key (or use LUFFA_ROBOT_SECRET env var)
luffa_bot.robot_key = "YOUR_ROBOT_SECRET"
async def main():
# Poll once for messages
envelopes = await luffa_bot.receive()
for env in envelopes:
for msg in env.messages:
if env.type == 0:
await luffa_bot.send_to_user(env.uid, f"You said: {msg.text}")
else:
await luffa_bot.send_to_group(env.uid, f"[group] {msg.text}")
asyncio.run(main())
Running a Bot Loop
Use the built-in run() method to continuously poll and handle messages.
import asyncio
import luffa_bot
luffa_bot.robot_key = "YOUR_ROBOT_SECRET"
async def handler(msg, env, client):
if "help" in msg.text.lower():
await client.send_to_user(env.uid, "How can I help?")
else:
await client.send_to_user(env.uid, f"Echo: {msg.text}")
asyncio.run(luffa_bot.run(handler, interval=1.0, concurrency=5))
Features of run()
- Automatic deduplication by
msgId(FIFO-capped memory) - Configurable polling interval
- Concurrency limit (process multiple messages at once)
- Middleware and error hook support
Sending Group Messages with Buttons
from luffa_bot.models import GroupMessagePayload, SimpleButton
payload = GroupMessagePayload(
text="Pick an option:",
button=[SimpleButton(name="OK", selector="ok")]
)
await luffa_bot.send_to_group("GROUP_ID", payload, message_type=2)
message_type=1→ Text onlymessage_type=2→ Buttons/advanced messages
Environment Variables
LUFFA_ROBOT_SECRET: Default robot key if not set vialuffa_bot.robot_key.
CLI
A CLI is included for quick bot testing:
export LUFFA_ROBOT_SECRET="..."
# Run an echo bot
luffa-bot run --interval 1.0
# Send DM to a user
luffa-bot send --uid <USER_ID> --text "Hello"
# Send message to a group with buttons
luffa-bot send-group --uid <GROUP_ID> --text "Hi group" --with-buttons
Development
pip install -e ".[dev]"
- Tests:
pytest - Lint:
ruff check . - Type-check:
mypy .
Changelog
0.1.2 (2026-03-10)
- Fix:
_ensure_client()was recreating thehttpx.AsyncClient(and leaking the old connection pool) on every API call. Connection pooling now works correctly across calls. - Fix: Dedupe eviction used
set.pop()(arbitrary removal). Now uses FIFO eviction viadequeso oldest IDs are dropped first. - Fix: CLI
sendandsend-groupcommands now properly close the HTTP client on exit. - Fix: GitHub Actions workflow directory renamed from
workflow/toworkflows/— CI/CD was silently not running. - Security: Removed unused dependencies
anyioandpydanticfrominstall_requires(unnecessary install footprint). - Compat: Replaced deprecated
asyncio.get_event_loop()withasyncio.get_running_loop()in example bot. - Added
__version__export (luffa_bot.__version__).
0.1.1
- Minor fixes and improvements.
0.1.0 (initial release)
- Initial async SDK with
receive(),send_to_user(),send_to_group(), andrun(). - Middleware pipeline, deduplication, concurrency control.
- CLI entry point (
luffa-bot).
Author
Niraj Kulkarni (Sabma Labs, University of Surrey)
License
Apache License 2.0
Project details
Release history Release notifications | RSS feed
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 luffa_bot_python_sdk-0.1.2.tar.gz.
File metadata
- Download URL: luffa_bot_python_sdk-0.1.2.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
772f749c1a49b1101bc9cc276beae9ded0550a2d5e358b8ae1b40d81e6adc2d7
|
|
| MD5 |
73a88cd9edb32685790ad01843264ba4
|
|
| BLAKE2b-256 |
96213255b7348e88d85766e93b69f2afb31d739540843837f532d40e9156dad9
|
Provenance
The following attestation bundles were made for luffa_bot_python_sdk-0.1.2.tar.gz:
Publisher:
publish.yaml on sabma-labs/luffa-bot-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
luffa_bot_python_sdk-0.1.2.tar.gz -
Subject digest:
772f749c1a49b1101bc9cc276beae9ded0550a2d5e358b8ae1b40d81e6adc2d7 - Sigstore transparency entry: 1074653876
- Sigstore integration time:
-
Permalink:
sabma-labs/luffa-bot-python-sdk@b75d2c8d84de6ea1fc62c364d44b1990353c5f37 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/sabma-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@b75d2c8d84de6ea1fc62c364d44b1990353c5f37 -
Trigger Event:
push
-
Statement type:
File details
Details for the file luffa_bot_python_sdk-0.1.2-py3-none-any.whl.
File metadata
- Download URL: luffa_bot_python_sdk-0.1.2-py3-none-any.whl
- Upload date:
- Size: 15.6 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 |
455d9b8eba2e77047bef3263d5a55db573e2c6b1761339349b4c44aeee59397c
|
|
| MD5 |
4f136203965718fafe71685f8202bce5
|
|
| BLAKE2b-256 |
6cd815be5e73de38272c95d912b6c9574bfeabb3a625767963d2f41ab100bfdd
|
Provenance
The following attestation bundles were made for luffa_bot_python_sdk-0.1.2-py3-none-any.whl:
Publisher:
publish.yaml on sabma-labs/luffa-bot-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
luffa_bot_python_sdk-0.1.2-py3-none-any.whl -
Subject digest:
455d9b8eba2e77047bef3263d5a55db573e2c6b1761339349b4c44aeee59397c - Sigstore transparency entry: 1074653899
- Sigstore integration time:
-
Permalink:
sabma-labs/luffa-bot-python-sdk@b75d2c8d84de6ea1fc62c364d44b1990353c5f37 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/sabma-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@b75d2c8d84de6ea1fc62c364d44b1990353c5f37 -
Trigger Event:
push
-
Statement type: