Python client for Smelter — a real-time, low-latency, programmable video and audio composition toolkit.
Project description
smelter-sdk
Python client for Smelter — a real-time, low-latency, programmable video and audio composition toolkit.
The SDK currently exposes Smelter's side channel: a Unix-socket stream of decoded RGBA video frames and PCM audio batches, so Python code can run ML inference (YOLO, Whisper, …) against live media and feed results back into the running pipeline via Smelter's HTTP API.
Status: alpha. The API may change between 0.x releases.
Install
pip install smelter-sdk
Requires Python 3.11+ and NumPy 1.26+. Tested on Linux and macOS. The Smelter server itself is a separate Rust binary — see the Smelter docs for installation.
Quickstart (sync)
The SDK reads its socket directory from the
SMELTER_SIDE_CHANNEL_SOCKET_DIR environment variable (the same one the
server publishes), falling back to the current working directory. With that
exported, the API takes one positional argument — the Smelter input id:
from smelter import subscribe_video_channel
for frame in subscribe_video_channel("cam1"):
# frame.rgba is a writable np.ndarray, shape (H, W, 4), dtype uint8.
# frame.pts_nanos is a presentation timestamp in nanoseconds.
process(frame.rgba, frame.pts_nanos)
Audio:
from smelter import subscribe_audio_channel
for batch in subscribe_audio_channel("cam1"):
# batch.samples is a (sample_count, channels) np.ndarray, dtype float32.
mono = batch.to_mono() # shape (sample_count,)
print(batch.start_pts_seconds, batch.duration_seconds)
If the env var isn't right for your process, pass an explicit
Context:
from smelter import Context, subscribe_video_channel
ctx = Context(socket_dir="/var/run/smelter")
for frame in subscribe_video_channel("cam1", ctx=ctx, timeout=10):
...
Quickstart (asyncio)
import asyncio
from smelter.aio import subscribe_video_channel
async def main():
async for frame in subscribe_video_channel("cam1"):
await process(frame.rgba, frame.pts_nanos)
asyncio.run(main())
The async client uses asyncio.open_unix_connection directly — no thread-pool
wrapper. Heavy synchronous work inside the loop (e.g. ML inference) should
still be wrapped in asyncio.to_thread(...) to avoid blocking other tasks.
Context
A Context bundles SDK-wide configuration. Today it carries one field — the
socket directory — but is the natural extension point for future options
(default timeouts, HTTP API base URL, …).
Context() # env var, then cwd
Context(socket_dir="/var/run/smelter") # explicit
Every public entry point (subscribe_video_channel, subscribe_audio_channel, list_channels,
wait_for_channel, …) accepts an optional ctx= keyword. When omitted, a
fresh default context is constructed per call.
Lower-level API
The top-level smelter module exposes the recommended high-level surface.
Lower-level building blocks live in smelter.sync (and smelter.aio for the
async equivalent) — reach for them only when the one-call
subscribe_*_channel helpers don't fit:
from smelter import SideChannelKind, list_channels
from smelter.sync import connect_video, wait_for_channel
# Enumerate everything currently published.
for info in list_channels():
print(info.kind, info.input_id)
# Wait for a specific channel, then connect.
info = wait_for_channel(kind=SideChannelKind.VIDEO, input_id="cam1", timeout=10)
with connect_video(info, timeout=5.0) as conn:
frame = conn.recv() # raises ConnectionClosed / RecvTimeout
for frame in conn: # iterates until peer closes
...
smelter.sync.connect_audio(info, dtype=np.float64) keeps full f64 precision;
the default is float32 to match Whisper / opus / librosa.
Errors
All exceptions inherit from smelter.SmelterError:
| Exception | Raised when |
|---|---|
ConnectionClosed |
Peer closed the socket — normal end-of-stream. |
RecvTimeout |
recv() exceeded the configured timeout. |
ChannelNotFound |
wait_for_channel timed out before a socket appeared. |
ProtocolError |
A message did not match the expected wire format. |
ChannelNotFound and RecvTimeout also inherit from the built-in TimeoutError.
Stability
The SDK is alpha — any 0.x release may break compatibility. Once 1.0 ships, the following surface will be governed by semver:
- Everything re-exported from the top-level
smelterpackage (seesmelter.__all__) andsmelter.aio(smelter.aio.__all__). - The synchronous building blocks in
smelter.sync(connect_video,connect_audio,wait_for_channel, theVideoConnection/AudioConnectionclasses) and theirsmelter.aioequivalents. - The data types in
smelter.types(VideoFrame,AudioBatch,SideChannelInfo,SideChannelKind) and the exceptions insmelter.errors.
Anything starting with an underscore (smelter._protocol, smelter._discovery)
is internal and may change without notice.
What's not in the SDK (yet)
- A typed client for the Smelter HTTP API. To send scene updates back to
Smelter today, use
requests/httpxagainst the/api/output/.../updateendpoint directly. - A way to push Python-generated frames into Smelter as an input. The side channel is unidirectional (Smelter → Python) at the moment.
Examples
The repository ships a complete demo that wires a video input through YOLO
object detection and Whisper speech-to-text, then renders the boxes and
subtitles back over the stream. See
sdks/python/example/.
License
MIT — see LICENSE.
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 smelter_sdk-0.1.0.tar.gz.
File metadata
- Download URL: smelter_sdk-0.1.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b7eb2355c9f3f1403e40179c3b4a9b4812e52682c2dd539abdcbb1455947589
|
|
| MD5 |
1569f8440a385e9dba099752bde64a56
|
|
| BLAKE2b-256 |
c085dac962c72b4b80b889326c365f237011471f874586e6f0a54f44ee68c084
|
Provenance
The following attestation bundles were made for smelter_sdk-0.1.0.tar.gz:
Publisher:
python_publish.yml on software-mansion/smelter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smelter_sdk-0.1.0.tar.gz -
Subject digest:
5b7eb2355c9f3f1403e40179c3b4a9b4812e52682c2dd539abdcbb1455947589 - Sigstore transparency entry: 1397255106
- Sigstore integration time:
-
Permalink:
software-mansion/smelter@5a533caa36e1205adc19fd5cf6d08be1c2be6b2e -
Branch / Tag:
refs/tags/python-sdk/v0.1.0 - Owner: https://github.com/software-mansion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python_publish.yml@5a533caa36e1205adc19fd5cf6d08be1c2be6b2e -
Trigger Event:
push
-
Statement type:
File details
Details for the file smelter_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: smelter_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
338fac872396e987154660b67613c0f2dc3883a5813e338cca9c7e15421e34a6
|
|
| MD5 |
f0951be5b7755b4c547b5d4a55be6b2e
|
|
| BLAKE2b-256 |
67e406b44a65a9ece71aec7bd276a1f3e922162d324dedeeaea5158a915f845b
|
Provenance
The following attestation bundles were made for smelter_sdk-0.1.0-py3-none-any.whl:
Publisher:
python_publish.yml on software-mansion/smelter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smelter_sdk-0.1.0-py3-none-any.whl -
Subject digest:
338fac872396e987154660b67613c0f2dc3883a5813e338cca9c7e15421e34a6 - Sigstore transparency entry: 1397255118
- Sigstore integration time:
-
Permalink:
software-mansion/smelter@5a533caa36e1205adc19fd5cf6d08be1c2be6b2e -
Branch / Tag:
refs/tags/python-sdk/v0.1.0 - Owner: https://github.com/software-mansion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python_publish.yml@5a533caa36e1205adc19fd5cf6d08be1c2be6b2e -
Trigger Event:
push
-
Statement type: