Index of every page on this site: llms.txt
All skills
software-mansion-labs avatar

/python-server-sdk

@43cde80
Run it yourself

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.

  • 10 files
  • 55.7 KB
  • Apache-2
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/software-mansion-labs/skills/python-server-sdk

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

client.md

≈1.6k tokens on demand. Your agent reads this file only when SKILL.md points to it.

FishjamClient (Python)

The REST client. Synchronous — no await. Source: fishjam/api/_fishjam_client.py in fishjam-server-sdk.

Constructor

from fishjam import FishjamClient

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

Use one instance per process. The constructor accepts both positional and keyword args; pin yourself to keyword for clarity.

Rooms

from fishjam import FishjamClient, RoomOptions

room = fishjam_client.create_room()  # defaults: conference room_type, no webhook, server-default video codec
room = fishjam_client.create_room(RoomOptions(
    room_type='audio_only',
))
room = fishjam_client.create_room(RoomOptions(
    room_type='livestream',
    public=True,
))
room = fishjam_client.create_room(RoomOptions(
    webhook_url='https://api.example.com/webhooks/fishjam/<secret>',
    video_codec='vp8',
    max_peers=20,
))

room = fishjam_client.get_room(room_id)
rooms = fishjam_client.get_all_rooms()
fishjam_client.delete_room(room_id)

RoomOptions dataclass fields:

  • max_peers: int | None — cap concurrent peers
  • video_codec: Literal['h264', 'vp8'] | None — default None (server picks)
  • webhook_url: str | None
  • room_type: Literal['conference', 'audio_only', 'livestream', 'audio_only_livestream', 'full_feature'] — default 'conference'
  • public: bool — livestream only

Returns Room(id, config, peers) (a dataclass).

Peers (WebRTC clients)

from fishjam import PeerOptions

peer, peer_token = fishjam_client.create_peer(
    room.id,
    PeerOptions(metadata={'userId': 'user-123', 'name': 'Jane'}),
)

fishjam_client.delete_peer(room.id, peer.id)
new_token = fishjam_client.refresh_peer_token(room.id, peer.id)

PeerOptions fields:

  • metadata: dict[str, Any] | None — initial peer metadata set at creation. The backend cannot mutate it afterwards, but the client owning the peer can update it mid-session (web: useUpdatePeerMetadata), surfacing as peerMetadataUpdated notifications.
  • subscribe_mode: Literal['auto', 'manual'] — default 'auto'

Return: tuple[Peer, str] — the peer object and the peer token. The token is valid for 24 hours from creation; the initial connect consumes it and established sessions stay alive on their own. For peers that haven't connected (or need to reconnect after 24h), call refresh_peer_token for a fresh one.

Agents (server-side programmatic peers)

from fishjam import AgentOptions, AgentOutputOptions

agent = fishjam_client.create_agent(
    room.id,
    AgentOptions(
        output=AgentOutputOptions(audio_format='pcm16', audio_sample_rate=16000),
        subscribe_mode='auto',
    ),
)
# `agent` is a fishjam.agent.Agent — use as async context manager:
async with agent.connect() as session:
    ...  # see agent.md

AgentOutputOptions controls the format of incoming audio (what other peers' tracks get downmixed into for the agent).

Vapi agents

from fishjam import PeerOptionsVapi

peer = fishjam_client.create_vapi_agent(
    room.id,
    PeerOptionsVapi(api_key=os.environ['VAPI_API_KEY'], call_id=vapi_call_id),
)

Returns just a Peer — Vapi runs the agent for you; nothing to await or context-manage. PeerOptionsVapi requires both api_key and call_id (strings); also accepts optional subscribe_mode.

Selective subscriptions

Only meaningful with subscribe_mode='manual' rooms — see selective-subscriptions.md.

fishjam_client.subscribe_peer(room.id, subscriber_peer_id, target_peer_id)
fishjam_client.subscribe_tracks(room.id, subscriber_peer_id, [track_id1, track_id2])

Livestream tokens

streamer_token = fishjam_client.create_livestream_streamer_token(room.id)
viewer_token = fishjam_client.create_livestream_viewer_token(room.id)

Issue only for livestream rooms. Public livestreams skip the viewer token.

Compositions

fishjam_client.forward_room_tracks(room.id, composition_client.composition_url(composition_id))

whip_url = fishjam_client.livestream_whip_url()
whep_url = fishjam_client.livestream_whep_url()

forward_room_tracks forwards a room into a composition; livestream_whip_url and livestream_whep_url are the livestream endpoints for composition outputs and WHEP inputs. Everything else lives on CompositionClient: composition.md.

MoQ tokens

publisher_token = fishjam_client.create_moq_token(publish_path='my-room/alice')
subscriber_token = fishjam_client.create_moq_token(subscribe_path='my-room')

publish_path and subscribe_path are separate kwargs (unlike the JS SDK which takes a config object).

Exception types

All HTTP errors raise subclasses of fishjam.errors.HTTPError:

Class Triggered by
BadRequestError 400
UnauthorizedError 401 — bad management token
NotFoundError 404 — room or peer missing
ConflictError 409 — name collision / state conflict
ServiceUnavailableError 503
InternalServerError 500 / any other

Pattern:

from fishjam.errors import NotFoundError, UnauthorizedError, HTTPError

try:
    peer, token = fishjam_client.create_peer(room_id, options)
except NotFoundError:
    raise HTTPException(404, detail='Room not found')
except UnauthorizedError:
    # OUR creds — surface as a server-side config error, not a user 401
    logger.exception('Fishjam credentials misconfigured')
    raise HTTPException(502)
except HTTPError as e:
    logger.exception('Fishjam call failed: %s', e)
    raise

HTTPError.__init__ stores errors from the response body — inspect for debugging.

Calling sync client from async code

Each method is a single HTTP round-trip, usually under ~50ms. From async code, two valid patterns:

# Pattern 1 — just call it. Fine for most cases.
peer, token = fishjam_client.create_peer(room.id, options)

# Pattern 2 — for hot paths or when you care about not blocking the event loop.
peer, token = await asyncio.to_thread(fishjam_client.create_peer, room.id, options)

If you wrap it for async, do so consistently — don't mix patterns in the same module.

Sources

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at 43cde80. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated last month

README badge

README badge for software-mansion-labs/skills/python-server-sdk