Basic Setup
import moonshine
from moonshine import Stream
# Configure your API token
moonshine.config("your-token")
# Create an index (enable performance for streaming)
moonshine.create("your-index-name", performance=True)
Streaming
Stream Object
Create a streaming object to capture video from your device.
# Create a stream object for your index
ms = Stream("your-index-name")
Available Sources
List all available video sources on your device.
# Get a list of all available sources
ms.sources()
Example output:
2 Sources Detected
==================================================
Device Camera or Screen
--------------------------------------------------
0 FaceTime HD Camera
1 Color LCD (1728 x 1117 @ 120.00Hz)
==================================================
Setting a Source
Select which source to use for streaming.
# Set the stream source to device 1 (screen in this example)
ms.set(1)
Starting a Stream
Start capturing video from the selected source.
# Start streaming indefinitely
ms.start()
# OR start streaming with a timeout (in seconds)
ms.start(30) # Stream for 30 seconds
Best Practices
- Always ensure
performance=True
when creating an index for streaming.
- Use
ms.sources()
to verify available devices before setting a source.
- Set reasonable timeouts for streaming to prevent excessive resource usage.
- Combine streaming and batch uploads for maximum flexibility.