Skip to main content

Official Python library for the Pulse API - Build bots and integrations

Project description

Pulse.py

Official Python library for the Pulse API. Build bots and integrations for the Pulse platform.

Installation

pip install pulse.py

Quick Start

import asyncio
from pulse import Client

client = Client(debug=True)

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

@client.event
async def on_message(data):
    message = data["message"]
    author = data["author"]

    if message["content"] == "!ping":
        await client.rest.send_message(message["roomId"], "Pong!")

    if message["content"] == "!hello":
        await client.rest.send_message(
            message["roomId"],
            f"Hello {author['displayName']}!"
        )

asyncio.run(client.run("YOUR_BOT_TOKEN"))

Features

  • Async/Await - Fully asynchronous with asyncio
  • REST API Client - Full access to the Pulse API
  • WebSocket Events - Real-time message and presence updates
  • Type Hints - Full type annotations included
  • Easy to Use - Simple and Pythonic API

Documentation

Client

The main client for interacting with Pulse.

from pulse import Client

client = Client(
    api_url="https://pulse.shadowforge.fr/api",  # Optional
    ws_url="wss://pulse.shadowforge.fr",         # Optional
    debug=False,                                  # Optional
)

Events

Use the @client.event decorator or @client.on("event_name"):

@client.event
async def on_ready():
    print("Bot is ready!")

@client.event
async def on_message(data):
    print(f"Message: {data['message']['content']}")

@client.on("member_join")
async def handle_join(data):
    print(f"New member joined!")
Event Description
ready Fired when the client is connected and ready
message Fired when a message is received
message_update Fired when a message is edited
message_delete Fired when a message is deleted
typing_start Fired when someone starts typing
typing_stop Fired when someone stops typing
presence_update Fired when a user's presence changes
member_join Fired when a member joins a hub
member_leave Fired when a member leaves a hub
error Fired when an error occurs
disconnect Fired when disconnected from WebSocket

REST API

Access the REST API through client.rest:

# Get current user
user = await client.rest.get_current_user()

# Send a message
await client.rest.send_message(room_id, "Hello!")

# Get hub members
members = await client.rest.get_hub_members(hub_id)

# Create a room
room = await client.rest.create_room(
    hub_id,
    name="general",
    type="text"
)

WebSocket

Direct WebSocket access through client.ws:

# Join a room for updates
await client.ws.join_room(room_id)

# Leave a room
await client.ws.leave_room(room_id)

# Send typing indicator
await client.ws.start_typing(room_id)
await client.ws.stop_typing(room_id)

Example Bot

import asyncio
import os
from pulse import Client

client = Client(debug=True)
PREFIX = "!"

@client.event
async def on_ready():
    print(f"Bot is ready! Logged in as {client.user.username}")
    print(f"Serving {len(client.hubs)} hubs")

@client.event
async def on_message(data):
    message = data["message"]
    author = data["author"]

    # Ignore self
    if author["id"] == client.user.id:
        return

    content = message["content"]
    room_id = message["roomId"]

    if not content.startswith(PREFIX):
        return

    args = content[len(PREFIX):].strip().split()
    command = args.pop(0).lower() if args else ""

    if command == "ping":
        await client.rest.send_message(room_id, "Pong!")

    elif command == "userinfo":
        info = f"**User Info**\n"
        info += f"Username: {author['username']}\n"
        info += f"ID: {author['id']}\n"
        info += f"Created: {author['createdAt']}"
        await client.rest.send_message(room_id, info)

    elif command == "servercount":
        await client.rest.send_message(
            room_id,
            f"I'm in {len(client.hubs)} hubs!"
        )

    elif command == "echo":
        text = " ".join(args) if args else "Nothing to echo!"
        await client.rest.send_message(room_id, text)

@client.event
async def on_member_join(data):
    print(f"New member joined: {data}")

@client.event
async def on_error(error):
    print(f"Error: {error}")

if __name__ == "__main__":
    token = os.getenv("BOT_TOKEN")
    if not token:
        print("Please set BOT_TOKEN environment variable")
        exit(1)

    asyncio.run(client.run(token))

Links

License

MIT License - Shadow Forge

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

pulse_voice-1.0.0.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

pulse_voice-1.0.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file pulse_voice-1.0.0.tar.gz.

File metadata

  • Download URL: pulse_voice-1.0.0.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pulse_voice-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1bb187ee4e15b848878de4fe144ba83a7659545d4393a00bf8882ea2af581ba3
MD5 8492c4a2043a1d30012cba7dd470eeaa
BLAKE2b-256 d543005cf08873afbdc4b4a15959cf0010bb3fffb221483f6dde119edea0113d

See more details on using hashes here.

File details

Details for the file pulse_voice-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pulse_voice-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pulse_voice-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed136df1b57164a6259607ddc72cbca2716c2d976f142a5ba9e2b6c96485eeca
MD5 27213601abcacd0e0b3a9aaab4032381
BLAKE2b-256 b81c9506b4a121010d5a36a49adc274dec622cc242c45c2e193820cb0742a355

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