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-voice

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.1.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.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pulse_voice-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 4951615e9870160c517596478efdf6cafdc18db8566b7cbd46d087283fb33cdb
MD5 a30413d60f5286ac4f12a8f597648aa0
BLAKE2b-256 4fc4a1234123a81cdef8f63a8781e57e4262d2e9761b073bc5ff74e6612ebbb0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pulse_voice-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 398336e757f38ffcbb468092a4d6da0d75b29572ef11d81ca71f9734ce0c9f17
MD5 0878944e5d8e90a537e396b57ab170be
BLAKE2b-256 7debf628c6114e84d23e7fd3c1f660b959a3e553783b94746cc4934dae9377d0

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