Python SDK
Define GPU functions in Python and serve them as real-time sessions
The uRun Python SDK ships as urun-cli on PyPI — pip install urun-cli gives you both the urun command (deploy, list, scale) and the importable urun library. It is how you write the backend of a uRun app: ordinary Python functions, decorated with the GPU shape they need, deployed to run on uRun's compute fleet.
The product primitive is a real-time session. You decorate a function with @app.function(...), deploy it, and a browser (via the TypeScript SDK) invokes it by name — getting back a live session with bidirectional media stream(name) and a synced control doc(key). The Python side owns the GPU: it holds a model warm, reads inbound media and control, and produces media out.
The same decorator also covers multi-GPU inference (gpus="h100:8", rank-aware via ctx.rank / ctx.world_size), so one mental model spans single-GPU and sharded real-time apps.
The shape of an app
import urun
from urun import App, Context
from urun.core import Dependencies, Credentials
app = App("my-app")
@app.function(gpus="b200:1", deps=Dependencies(python=["torch"]))
def generate(ctx: Context):
# long-lived session owner: holds the model warm, reads inbound
# media + control doc, produces a streamed result out
...Deploy it with the urun CLI, then call it from the browser as app.generate({ prompt: "sunset" }).
Core building blocks
- App & functions —
App, the@app.functiondecorator, and local entrypoints. - Sessions — session lifecycle:
lease, hard caps, idle timeout, scale-to-zero with snapshot wakes, DVR recordings. - Compute — GPU/CPU specs, warm replicas, and session length (
lease/max_session_s). - Streaming pipelines —
ctx.stream,ctx.source | ctx.pipe | ctx.pace | sink, andctx.doccontrol. - Store — content-addressed model/data downloads, versioned artifacts, and
@store.cachefor keeping models hot. - Dependencies & Credentials — the remote environment and its secrets.