Skip to main content

Python SDK for Reactor - Real-time AI video streaming

Project description

Reactor Python SDK

PyPI version PyPI downloads build license

Python SDK for Reactor - Real-time AI video streaming platform.

Installation

pip install reactor-sdk

Quick Start

import asyncio
from reactor_sdk import Reactor, ReactorStatus

async def main():
    # Create a Reactor instance with your API key
    reactor = Reactor(
        model_name="my-model",
        api_key="REACTOR_API_KEY",  # SDK automatically fetches JWT token
    )
    
    # Use decorators for clean event handling
    @reactor.on_frame
    def handle_frame(frame):
        print(f"Received frame: {frame.shape}")
    
    @reactor.on_message
    def handle_message(msg):
        print(f"Message: {msg}")
    
    @reactor.on_status(ReactorStatus.READY)
    def handle_ready(status):
        print("Connected and ready!")
    
    @reactor.on_error
    def handle_error(error):
        print(f"Error: {error}")
    
    # Connect to the model (JWT token is fetched automatically)
    await reactor.connect()
    
    # Send commands
    await reactor.send_command("setParameter", {"value": 0.5})
    
    # Keep running
    try:
        while reactor.get_status() == ReactorStatus.READY:
            await asyncio.sleep(0.1)
    finally:
        await reactor.disconnect()

if __name__ == "__main__":
    asyncio.run(main())

Features

  • WebRTC video streaming via aiortc
  • Event-driven API matching the JavaScript SDK
  • Frame callbacks for single-frame access
  • Video input support for sending video to models
  • Local development mode for testing
  • Full type hints for IDE support

API Reference

Reactor

The main class for connecting to Reactor models.

from reactor_sdk import Reactor

# Production usage with API key
reactor = Reactor(
    model_name="my-model",
    api_key="REACTOR_API_KEY",  # SDK fetches JWT automatically
)

# Local development (no API key needed)
reactor = Reactor(
    model_name="my-model",
    local=True,
)

The Reactor type can also be used for type annotations:

from reactor_sdk import Reactor

def process_reactor(reactor: Reactor) -> None:
    # reactor has full type hints for all methods
    pass

Methods

  • await reactor.connect() - Connect to the model (fetches JWT automatically if API key provided)
  • await reactor.disconnect(recoverable: bool = False) - Disconnect
  • await reactor.reconnect() - Reconnect to existing session
  • await reactor.send_command(command: str, data: dict) - Send a command
  • await reactor.publish_track(track: MediaStreamTrack) - Send video to model
  • await reactor.unpublish_track() - Stop sending video
  • reactor.get_status() - Get current status
  • reactor.get_session_id() - Get session ID
  • reactor.set_frame_callback(callback) - Set frame callback

Decorators

Use decorators for clean event handling:

@reactor.on_frame
def handle_frame(frame):
    """Called for each video frame (numpy array H,W,3)."""
    pass

@reactor.on_message
def handle_message(message):
    """Called for each message from the model."""
    pass

@reactor.on_status
def handle_any_status(status):
    """Called for all status changes."""
    pass

@reactor.on_status(ReactorStatus.READY)
def handle_ready(status):
    """Called only when status becomes READY."""
    pass

@reactor.on_status([ReactorStatus.READY, ReactorStatus.CONNECTING])
def handle_active(status):
    """Called when status is READY or CONNECTING."""
    pass

@reactor.on_error
def handle_error(error):
    """Called when an error occurs."""
    pass

@reactor.on_stream
def handle_stream(track):
    """Called when video stream/track changes."""
    pass

Events (alternative to decorators)

  • status_changed - Status changed (disconnected, connecting, ready)
  • session_id_changed - Session ID changed
  • new_message - Message received from model
  • stream_changed - Video stream changed
  • error - Error occurred

Examples

See the examples/ directory for complete examples:

  • pygame_app/ - Pygame application with dynamic UI controls
  • rtmp_app/ - Stream Reactor video to RTMP servers (Twitch, YouTube, etc.)

License

MIT License - Copyright (c) 2025 Reactor Technologies, Inc.

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

reactor_sdk-0.1.0.tar.gz (33.3 kB view details)

Uploaded Source

Built Distribution

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

reactor_sdk-0.1.0-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: reactor_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 33.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for reactor_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 af5d5f4cb54abaa9dde32ae72535f6f435cacb787d13acf473013421a321b006
MD5 e8044360ef09c5863d56c8b91a6a9475
BLAKE2b-256 050861113c101d54a081bb63c920900afbb3023277418b0decfcc60a08874ac5

See more details on using hashes here.

Provenance

The following attestation bundles were made for reactor_sdk-0.1.0.tar.gz:

Publisher: publish.yml on reactor-team/py-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: reactor_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for reactor_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 17bb26bd4c53ce702f66b0dd71839cf1a33f428e89948be583899595c147f3ff
MD5 c42098fac9df49e1de9516776dc9fefb
BLAKE2b-256 dd36520043d4eb52780f618d70ad40c3afeb4690dd4623156582d27b48835299

See more details on using hashes here.

Provenance

The following attestation bundles were made for reactor_sdk-0.1.0-py3-none-any.whl:

Publisher: publish.yml on reactor-team/py-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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