Skip to main content

Official Python SDK for Brainbase Engine's WebSocket API

Project description

Brainbase Engine Python SDK

The official Python SDK for interacting with Brainbase Engine's 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-engine

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: brainbase_engine-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 386f27d9db7753f341fa0f457488e96f4b582c699d1492a26620743e68ef9255
MD5 2666139fc305158f48b2c82f804a264b
BLAKE2b-256 0203cdec17d4d0c5de2bfddd8ef9b783824342611955ff9a90d372e7b3850623

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for brainbase_engine-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94e28feeb981e666c139d3a374b5704e8302c680831e57561c33ff8ad3983dfa
MD5 ed68f40ba8883d92c21c3f784c66ee99
BLAKE2b-256 96550341a02a06c204a181349f4454509510ee5711a2e3c45e6e32764265d91b

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