Official Rolespace bot SDK for Python
Project description
Rolespace Python SDK
Minimal client for the Rolespace bot API. Requires Python 3.8+ and requests.
Install
Drop rolespace.py into your project, or:
pip install rolespace
Quick start
from rolespace import Rolespace
# Reads ROLESPACE_BOT_TOKEN from your environment.
rs = Rolespace.from_env()
me = rs.me()
print(f"Logged in as {me['bot']['username']} (#{me['bot']['id']})")
# Send a message:
rs.send_message(server_id, channel_id, "Hello from my bot!")
# Listen for interactions (button clicks, modal submits, etc.):
for ix in rs.interactions():
if ix["customId"] == "book":
rs.respond(ix["id"], {"type": "message", "content": "Booked!", "ephemeral": True})
Webhook signature verification
from flask import Flask, request, abort
from rolespace import Rolespace
import os, json
app = Flask(__name__)
SECRET = os.environ["WEBHOOK_SECRET"]
@app.post("/webhook")
def webhook():
raw = request.get_data() # raw bytes — NOT request.json
sig = request.headers.get("X-Rolespace-Signature", "")
if not Rolespace.verify_webhook(raw, sig, SECRET):
abort(401)
event = json.loads(raw)
# ...handle event...
return ("", 204)
Important: use request.get_data() — request.json re-serializes the body
and the signature check will fail.
What this SDK does for you
- Loads the token from
ROLESPACE_BOT_TOKENso you don't hardcode it - Retries 429s with exponential backoff (honors
Retry-After) - Hides the bot token from
repr(client) - Verifies webhook signatures with
hmac.compare_digest(constant-time) - Generator over
/interactions— no manual polling loop or cursor bookkeeping
API
| Method | What it does |
|---|---|
rs.me() |
Bot account + owner + scopes |
rs.servers() |
All servers the bot is in |
rs.server(id) |
One server with its channels |
rs.server_channels(id) / server_members(id) |
Lists |
rs.send_message(server_id, channel_id, "text" or {...}) |
Post a message |
rs.send_dm(recipient_id, "text" or {...}) |
Send a DM |
for ix in rs.interactions(): |
Stream of interactions |
rs.respond(id, reply) |
Reply to an interaction |
rs.get/post/patch/put/delete(path, json=None) |
Raw HTTP for endpoints not covered above |
Rolespace.verify_webhook(raw_body, sig_header, secret) |
Static; constant-time check |
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
rolespace-0.2.1.tar.gz
(10.0 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
rolespace-0.2.1-py3-none-any.whl
(10.7 kB
view details)
File details
Details for the file rolespace-0.2.1.tar.gz.
File metadata
- Download URL: rolespace-0.2.1.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2df8b6d4bf9e0e868ca401dbfaefd33c7e48fe8af5cf2a97bc30fbb70db85faa
|
|
| MD5 |
9eb4989b3e9f908fc3f9ebb58465da18
|
|
| BLAKE2b-256 |
15c757f3f5b9ae4c5e4e06899442bb0129c47351d334bc196129292f32721e44
|
File details
Details for the file rolespace-0.2.1-py3-none-any.whl.
File metadata
- Download URL: rolespace-0.2.1-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac5658d34a2329689b8a774c94245b80077aa9937b5623679d74a97e530f0207
|
|
| MD5 |
42bfb74494a71275b07f1bb8fe83370a
|
|
| BLAKE2b-256 |
091b52e55c035b1c21d020c773d325d293cf03b34bbca394db182b1dc528bda3
|