Skip to main content

Python SDK for Commandless relay API

Project description

commandless-relay (Python)

Official Python SDK for the Commandless relay API.

This package gives Python bots a simple client and a ready-to-use discord.py adapter.

Install

Core client:

pip install commandless-relay

With discord.py adapter support:

pip install "commandless-relay[discord]"

AI-only setup (no code)

Install and run from terminal, similar to the Node SDK flow:

pip install "commandless-relay[discord]"
commandless-discord

Set these environment variables first:

  • BOT_TOKEN - your Discord bot token
  • COMMANDLESS_API_KEY - API key created in Commandless dashboard
  • COMMANDLESS_SERVICE_URL (or SERVICE_URL) - optional, defaults to Commandless backend
  • BOT_ID - optional bot ID from dashboard (recommended)
  • COMMANDLESS_HMAC_SECRET - optional HMAC secret
  • COMMANDLESS_MENTION_REQUIRED - optional (true by default)

Quickstart (discord.py in code)

import os
import discord
from commandless_relay import RelayClient, use_discord_adapter

TOKEN = os.getenv("BOT_TOKEN")
API_KEY = os.getenv("COMMANDLESS_API_KEY")
BASE_URL = os.getenv("COMMANDLESS_SERVICE_URL") or os.getenv("SERVICE_URL")  # optional

intents = discord.Intents.default()
intents.message_content = True
intents.messages = True
intents.guilds = True

client = discord.Client(intents=intents)
relay = RelayClient(api_key=API_KEY, base_url=BASE_URL)  # base_url optional

use_discord_adapter(client, relay, mention_required=True)

@client.event
async def on_ready():
    print(f"Logged in as {client.user}")

client.run(TOKEN)

Environment variables

  • BOT_TOKEN - your Discord bot token
  • COMMANDLESS_API_KEY - API key created in Commandless dashboard
  • COMMANDLESS_SERVICE_URL (or SERVICE_URL) - optional, defaults to Commandless backend
  • BOT_ID - optional fixed bot id to lock config/persona
  • COMMANDLESS_HMAC_SECRET - optional HMAC secret
  • COMMANDLESS_MENTION_REQUIRED - optional (true by default)
  • COMMANDLESS_DISABLE_CONFIG_CACHE - optional (false by default)
  • COMMANDLESS_DEBUG - optional verbose logs (false by default)

Included components

  • RelayClient
    • send_event(event) -> Decision dict or None
    • register_bot(...) -> botId (optional flow)
    • heartbeat() (optional flow)
  • ConfigCache
    • fetches /v1/relay/config
    • local filtering for channel/user/role/premium/rate limits
    • polls every 30 seconds
  • use_discord_adapter(client, relay, mention_required=True, execute=None)
    • binds an on_message listener
    • sends events to relay
    • executes reply actions by default
    • applies local config filtering by default (disable via COMMANDLESS_DISABLE_CONFIG_CACHE=true)
    • sends a clear message on billing rejection (402 / no subscription or credits)

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

commandless_relay-0.1.9.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

commandless_relay-0.1.9-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file commandless_relay-0.1.9.tar.gz.

File metadata

  • Download URL: commandless_relay-0.1.9.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for commandless_relay-0.1.9.tar.gz
Algorithm Hash digest
SHA256 d4ecdd4c38b5e0fdee4390cc281dd9b0c95919c0600652461b2c5efd00e82d8c
MD5 f5cba8080652cb54dcb75b0a18de284e
BLAKE2b-256 865461247caca5da512f7b4d4d39dfa7ce53837f8aa27a3ac2689afe3004f249

See more details on using hashes here.

File details

Details for the file commandless_relay-0.1.9-py3-none-any.whl.

File metadata

File hashes

Hashes for commandless_relay-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 58c7c5426c813bce965cfa77c07a9c0d4b0e31a36097cc182c319314cc767d22
MD5 043e6c7687c41aee87262d5b7eafed88
BLAKE2b-256 41d7ad35970fb6eedf8dcf1da16836d04bd5523df3a501b85b22dc7449d9a91c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page