Skip to main content

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_TOKEN so 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

Metadata

Release files for rolespace 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rolespace 0.2.6
File Size Uploaded Provenance Actions
rolespace-0.2.6.tar.gz 16.9 kB Without provenance Details for rolespace-0.2.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rolespace 0.2.6
File Interpreter ABI Platform Actions
rolespace-0.2.6-py3-none-any.whl Python 3 none any Details for rolespace-0.2.6-py3-none-any.whl

Total release size: 34.5 kB

Release files / rolespace-0.2.6.tar.gz

Download URL rolespace-0.2.6.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9257a32418bbf95b7c2d651beb54d3925037f36f9b05a6962877be2ae5acf6f5
BLAKE2b-256 checksum
How to use checksums
4cb0ea94f6d318a1e3aa6139b7f3e52eead402fd80128ef584999a649da87dd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / rolespace-0.2.6-py3-none-any.whl

Download URL rolespace-0.2.6-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
710c7a177de156b8e30ccdaaa8b4656d41f02348506c5c7fb72f0f33236cf0fc
BLAKE2b-256 checksum
How to use checksums
e3f159bc8647d4eb6348c98055a70fb0dcf41af7428de16379bebef95d5f5714
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Security for rolespace 0.2.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page