Python SDK for Reactor - Real-time AI video streaming
Project description
Reactor Python SDK
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)- Disconnectawait reactor.reconnect()- Reconnect to existing sessionawait reactor.send_command(command: str, data: dict)- Send a commandawait reactor.publish_track(track: MediaStreamTrack)- Send video to modelawait reactor.unpublish_track()- Stop sending videoreactor.get_status()- Get current statusreactor.get_session_id()- Get session IDreactor.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 changednew_message- Message received from modelstream_changed- Video stream changederror- Error occurred
Examples
See the examples/ directory for complete examples:
pygame_app/- Pygame application with dynamic UI controlsrtmp_app/- Stream Reactor video to RTMP servers (Twitch, YouTube, etc.)
License
MIT License - Copyright (c) 2025 Reactor Technologies, Inc.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file reactor_sdk-0.2.2.tar.gz.
File metadata
- Download URL: reactor_sdk-0.2.2.tar.gz
- Upload date:
- Size: 1.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cc2b8d61cce6dadc38d02536b832a02f8099572f29be3a898b9bf9fcaebc71a
|
|
| MD5 |
c4f78839b3264141dbf8309a01b2803f
|
|
| BLAKE2b-256 |
97beb1e1dca14b026f88626e7ef6d50f2f62ec07453b285b2f17492720547407
|
Provenance
The following attestation bundles were made for reactor_sdk-0.2.2.tar.gz:
Publisher:
publish.yml on reactor-team/py-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
reactor_sdk-0.2.2.tar.gz -
Subject digest:
1cc2b8d61cce6dadc38d02536b832a02f8099572f29be3a898b9bf9fcaebc71a - Sigstore transparency entry: 976499141
- Sigstore integration time:
-
Permalink:
reactor-team/py-sdk@2a166c79ed3369ba4ba3dc9d66472a6fda95503c -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/reactor-team
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2a166c79ed3369ba4ba3dc9d66472a6fda95503c -
Trigger Event:
release
-
Statement type:
File details
Details for the file reactor_sdk-0.2.2-py3-none-any.whl.
File metadata
- Download URL: reactor_sdk-0.2.2-py3-none-any.whl
- Upload date:
- Size: 28.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c8f3a44a833b4fe08829018cd0cedaa01d2c1001fb41e6d5af04721fa8da0bc
|
|
| MD5 |
08bf44214745ab4a1ae77847012898d8
|
|
| BLAKE2b-256 |
2953b496767cc0022df8f32451682cdac86b0efcf86cc1f593ff489c0c817531
|
Provenance
The following attestation bundles were made for reactor_sdk-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on reactor-team/py-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
reactor_sdk-0.2.2-py3-none-any.whl -
Subject digest:
4c8f3a44a833b4fe08829018cd0cedaa01d2c1001fb41e6d5af04721fa8da0bc - Sigstore transparency entry: 976499144
- Sigstore integration time:
-
Permalink:
reactor-team/py-sdk@2a166c79ed3369ba4ba3dc9d66472a6fda95503c -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/reactor-team
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2a166c79ed3369ba4ba3dc9d66472a6fda95503c -
Trigger Event:
release
-
Statement type: