livekit/python-sdks
LiveKit real-time and server SDKs for Python
LiveKit Python SDK
What it is – A pair of Python packages that let you connect a Python program to a LiveKit server (cloud‑hosted or self‑hosted) and act as a real‑time participant in a video/audio room. One package (livekit) provides the real‑time client API; the other (livekit‑api) offers server‑side helpers such as token creation and REST‑style room management.
Why it matters – LiveKit is a platform for low‑latency, multi‑party video, audio and data streams. By exposing these capabilities in Python, the SDK makes it easy to build:
- AI‑powered voice agents (speech‑to‑text, LLM‑driven dialogue, text‑to‑speech, turn detection) that run in a live call.
- Real‑time streaming or broadcasting apps that need to publish or consume media from Python code.
- Custom back‑ends that orchestrate rooms, egress/ingress, SIP dialing, or agent dispatch via the server API.
Key components
| Component | Purpose |
|---|---|
livekit |
Connects to a LiveKit room, publishes/receives audio‑video tracks, handles events, and supports RPC between participants. |
livekit-api |
Generates JWT access tokens, calls server endpoints (create/list rooms, egress, SIP, agent dispatch, etc.) using async aiohttp. |
MediaDevices (in livekit.rtc) |
High‑level wrapper around the sounddevice library for microphone capture and speaker playback, with built‑in acoustic echo cancellation, noise suppression, etc. |
| RPC system | Register a Python coroutine as a remote method and invoke it from another participant; useful for forwarding LLM function calls. |
| Agents integration | The SDK can be combined with the separate LiveKit Agents framework to run voice‑AI bots that internally use STT, LLM, TTS, turn detection, and tool usage without managing provider keys. |
Typical workflow
- Install –
pip install livekit livekit-api. - Create a token (backend) with
api.AccessToken()and appropriate grants. - Connect –
room = rtc.Room(); await room.connect(url, token). - Publish media – use
MediaDevicesto open a microphone or speaker, wrap the source inLocalAudioTrack/LocalVideoTrack, and publish it. - Handle events – register callbacks like
room.on("track_subscribed", ...)to receive remote streams. - Optional RPC – register a method with
@room.local_participant.register_rpc_methodand call it from another participant viaperform_rpc. - Server‑side management – use
LiveKitAPIto create rooms, list participants, start egress recordings, dial SIP participants, etc.
Example snippets
# generate a token (backend)
from livekit import api
token = api.AccessToken().with_identity("bot").with_grants(
api.VideoGrants(room_join=True, room="demo")
).to_jwt()
# connect and publish microphone
from livekit import rtc
room = rtc.Room()
await room.connect(LIVEKIT_URL, token)
devices = rtc.MediaDevices()
mic = devices.open_input(enable_aec=True, noise_suppression=True)
track = rtc.LocalAudioTrack.create_audio_track("mic", mic.source)
await room.local_participant.publish_track(track)
Where to go next
- Browse the
examples/folder (basic room, face‑landmark, hue video, full‑duplex audio). - Read the LiveKit Agents docs if you want a voice‑AI bot that bundles STT/LLM/TTS.
- Join the LiveKit Slack community for help and to contribute.
License – The SDK is released under the MIT License (as indicated in the repository).
Related
- Project
- Project
- Project
- Project
- Project