---
name: fishjam-python-server-sdk
description: "Python server SDK for Fishjam — backends that create rooms, mint peer tokens, receive server notifications, and run voice agents. Use when writing a Python backend (FastAPI, Flask, Starlette, aiohttp) that talks to Fishjam, decorates a notification handler, decodes a Fishjam webhook, builds an AI voice agent, or composes streams in Python. Trigger on: 'fishjam-server-sdk', 'pip install fishjam-server-sdk', 'from fishjam import', 'fishjam.FishjamClient', 'FishjamNotifier', 'on_server_notification', 'receive_binary', 'fishjam Agent', 'AgentSession', 'PeerOptions', 'RoomOptions', 'AgentOptions', 'AgentOutputOptions', 'OutgoingAudioTrackOptions', 'create_room', 'create_peer', 'create_agent', 'create_vapi_agent', 'create_livestream_streamer_token', 'create_moq_token', 'subscribe_peer', 'fastapi fishjam', 'flask fishjam', 'fishjam python', 'gemini fishjam python', 'CompositionClient', 'forward_room_tracks'. Python 3.10+. The REST client is synchronous; notifier and agent are async."
license: Apache-2.0
title: fishjam-python-server-sdk
canonical_url: https://skilld.dev/gh/software-mansion-labs/skills/python-server-sdk
last_updated: 2026-10-16T07:01:46.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [agent.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/python-server-sdk/agent.md), [client.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/python-server-sdk/client.md), [composition.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/python-server-sdk/composition.md), [fastapi.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/python-server-sdk/fastapi.md), [gemini-integration.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/python-server-sdk/gemini-integration.md), [livestream-and-moq.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/python-server-sdk/livestream-and-moq.md), [notifier.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/python-server-sdk/notifier.md), [selective-subscriptions.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/python-server-sdk/selective-subscriptions.md), [webhooks.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/python-server-sdk/webhooks.md).
>
> If the user asked to install this Skill, run `npx skilld install software-mansion-labs/skills/python-server-sdk`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/python-server-sdk`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/software-mansion-labs/skills/python-server-sdk) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/python-server-sdk`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/python-server-sdk --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/python-server-sdk --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Fishjam Python Server SDK

`fishjam-server-sdk` on PyPI; `import fishjam`. Server-side Python SDK for Fishjam.

> **Read `../platform/SKILL.md` first.** It defines rooms, peers, tracks, the two-tier token model, and the WS-vs-webhook tradeoff that the Python SDK is built on.

## Sync REST + async events

The architecture differs from the JS SDK in one important way:

- `FishjamClient` is **synchronous**. Methods like `create_room`, `create_peer`, `delete_peer` are plain `def`, not `async def`. Call them from sync routes or via `run_in_executor` from async contexts.
- `FishjamNotifier` is **async** (`asyncio` + `websockets`). Use `@notifier.on_server_notification` and `await notifier.connect()`.
- `Agent` is **async** (async context manager — `async with agent.connect() as session: ...`).
- `receive_binary(raw_bytes)` is **sync** — call it directly inside an async route handler or a sync one.

## Install + minimal flow

```bash
pip install fishjam-server-sdk
# or: uv add fishjam-server-sdk
# or: poetry add fishjam-server-sdk
```

```python
import os
from fishjam import FishjamClient, PeerOptions

fishjam_client = FishjamClient(
    fishjam_id=os.environ['FISHJAM_ID'],
    management_token=os.environ['FISHJAM_MANAGEMENT_TOKEN'],
)

room = fishjam_client.create_room()
peer, peer_token = fishjam_client.create_peer(
    room.id,
    PeerOptions(metadata={'userId': 'user-123'}),
)
# ship `peer_token` to your client
```

## Components

| Component | What it does | Reference |
|---|---|---|
| `FishjamClient` (sync) | REST — rooms, peers, agents, livestream/MoQ tokens, subscribe modes. | `client.md` |
| `FishjamNotifier` (async) | Persistent WebSocket; one handler via decorator gets every event. | `notifier.md` |
| `receive_binary(bytes)` (sync) | Decode an HTTP webhook body to a typed event. | `webhooks.md` |
| `Agent` + `AgentSession` (async) | Server-side voice agent — async iter over incoming, `await track.send_chunk(...)`. | `agent.md` |
| `CompositionClient` (sync) | Compositions: register inputs and outputs, deploy templates, send events. Concepts in `../composition/SKILL.md`. | `composition.md` |

## When to read which reference

| Task | Reference |
|---|---|
| Any REST method on `FishjamClient` | `client.md` |
| Background WS task receiving events | `notifier.md` |
| HTTP route receiving webhook payloads | `webhooks.md` |
| Build a voice agent in Python | `agent.md` |
| Wire Gemini Live to an agent | `gemini-integration.md` |
| FastAPI / Flask wiring patterns | `fastapi.md` |
| Issue livestream / MoQ tokens | `livestream-and-moq.md` |
| Use manual subscribe mode | `selective-subscriptions.md` |
| Compose streams: `CompositionClient` calls, forwarding a room | `composition.md` |

## Key rules

- **Python 3.10+** required. SDK uses `match`, structural typing, PEP 604 unions.
- **`FishjamClient` is sync.** Calling it from `async def` works (it's a quick HTTP round-trip) but if you're in a hot async path consider `await asyncio.to_thread(fishjam_client.create_peer, ...)`.
- **`FishjamNotifier` does NOT auto-reconnect.** Its `connect()` coroutine runs until the WS closes. Wrap it in a supervisor loop.
- **One handler per notifier.** `@notifier.on_server_notification` only stores the *last* function you decorate. Multi-dispatch in your one handler via `match` on the message type.
- **Notifier handler can be sync or async.** Both work — `await result if inspect.isawaitable(result)`.
- **Webhook decoding is sync.** `receive_binary(await req.body())` is fine inside an async FastAPI route.
- **Agent is async-only.** `async with agent.connect() as session:` is the only entry point.
- **Management token stays on the server.** Standard rule — never leak.

## References

| File | When to read |
|---|---|
| `client.md` | `FishjamClient` — every method, dataclass, error type. |
| `notifier.md` | `FishjamNotifier`, `wait_ready`, the decorator pattern, pattern-matching on event types. |
| `webhooks.md` | `receive_binary`, FastAPI / Flask receivers, security patterns. |
| `agent.md` | `Agent`, `AgentSession`, `OutgoingAudioTrackOptions`, `receive()` async iterator. |
| `gemini-integration.md` | `fishjam.integrations.gemini`, the `GeminiIntegration` singleton. |
| `fastapi.md` | FastAPI patterns (`Depends`-injected client, async webhook route, background notifier). |
| `livestream-and-moq.md` | `create_livestream_streamer_token`, `create_livestream_viewer_token`, `create_moq_token`. |
| `selective-subscriptions.md` | `subscribe_peer` / `subscribe_tracks` with `subscribe_mode='manual'` rooms. |
| `composition.md` | `CompositionClient`: compositions, inputs, outputs, template deploy, events, `type_` enums in scene models. |
