Skip to main content

Official Python SDK for Brainbase's REST & WebSocket API

Project description

Brainbase Python SDK

The official Python SDK for interacting with Brainbase's REST & WebSocket API. This SDK provides a simple and intuitive way to establish real-time connections with Brainbase workers and handle streaming messages.

Installation

pip install brainbase

Features

  • WebSocket-based real-time communication
  • Message streaming support
  • Event-driven architecture
  • Function calling capabilities
  • Connection monitoring
  • Error handling

Quick Start

from brainbase import BrainbaseEngine

# Initialize the engine with your API key
engine = BrainbaseEngine("your-api-key")

# Get a worker instance
worker = engine.get_worker("worker-id")

# Define a message handler
def handle_message(data, ws):
    if isinstance(data, dict) and data.get("type") == "stream":
        print(data.get("content"), end="", flush=True)

# Establish connection
connection = worker.run(streaming=True)

# Register message handler
connection.on("message", handle_message)

# Send a message
connection.send("Hello, Brainbase!")

Documentation

For detailed documentation, visit https://docs.brainbase.com/python

API Reference

BrainbaseEngine

The main class for interacting with Brainbase's API.

engine = BrainbaseEngine(
    api_key="your-api-key",
)

Worker

Represents a Brainbase worker that can establish WebSocket connections.

worker = engine.get_worker("worker-id")
connection = worker.run(
    streaming=True,  # Enable message streaming
    monitor=True,    # Enable connection monitoring
    functions=[]     # Optional function definitions
)

Connection

Manages the WebSocket connection to a Brainbase worker.

# Register event handlers
connection.on("message", handle_message)
connection.on("error", handle_error)
connection.on("close", handle_close)

# Send messages
connection.send("Your message")

# Close connection
connection.close()

Development

To set up the development environment:

  1. Clone the repository
  2. Install development dependencies:
pip install -e ".[dev]"

Running Tests

pytest

Code Formatting

black .
isort .

Requirements

  • Python 3.7+
  • websocket-client>=1.0.0
  • requests>=2.25.0

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

For support, email support@usebrainbase.xyz or create an issue on our GitHub repository.


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

brainbase_engine-0.1.1.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

brainbase_engine-0.1.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file brainbase_engine-0.1.1.tar.gz.

File metadata

  • Download URL: brainbase_engine-0.1.1.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for brainbase_engine-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0c34e316b253029bcdedce7ca382fc84f1d697e4fc15e477b0257e49bdd1868b
MD5 3a64dc5237eac641f7cd7aaba5d095f0
BLAKE2b-256 1c440e308a58181eefad14652ea79a584308dce0e455d400a1610a4eceaeda82

See more details on using hashes here.

File details

Details for the file brainbase_engine-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for brainbase_engine-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7988ccb20d525b0d1f56b94a8cd3700f51ccfb4f01e05d109dac03476b16420a
MD5 11de95d0b1ff370268695faaa9f58f8a
BLAKE2b-256 d533929d2a8c5c13bb1ba81070cb0a559833c89a29ec96055f5de0143131bdfa

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