Python WebRTC
Chrome’s WebRTC engine, with the browser API, in Python.
Python WebRTC binds libwebrtc M152, the engine inside Chrome, and exposes it through the W3C APIs you already know from the browser: peer connections, data channels, tracks, WebCodecs frames, encoded transforms and stats, in asyncio. Talk to browsers, servers, SFUs and AI agents peer-to-peer, with no vendor service in between.
pip install wrtc
If you know it in JavaScript, you know it in Python
pc = webrtc.RTCPeerConnection()
channel = pc.create_data_channel('chat')
channel.on('open', lambda e: channel.send('Hello!'))
channel.on('message', lambda e: print(e.data))
pc.on('icecandidate', lambda e: signaling.send(e.candidate))
offer = await pc.create_offer()
await pc.set_local_description(offer)
signaling.send(pc.local_description)
const pc = new RTCPeerConnection();
const channel = pc.createDataChannel('chat');
channel.onopen = () => channel.send('Hello!');
channel.onmessage = (e) => console.log(e.data);
pc.onicecandidate = (e) => signaling.send(e.candidate);
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
signaling.send(pc.localDescription);
Names follow the specifications in snake_case (create_offer), and the camelCase originals (createOffer) work
too. Enums compare equal to the strings of the specification, and dictionaries are typed dataclasses.
Note
Pre-1.0: until the 1.0.0 release, compatibility between versions isn’t guaranteed.
Why Python WebRTC
ICE, DTLS, SCTP, congestion control, jitter buffers and codecs are Chrome’s own, so interop with browsers is the browsers’ interop.
Written against the W3C specifications and tested with the web-platform-tests the browsers use.
Packets, decoding and encoding never touch Python. You see frames, not packets.
VP8, VP9, AV1, H.264 and Opus. Hardware H.264 through VideoToolbox on macOS. See H.264.
WARP: DTLS 1.3, SNAP and SPED cut round trips off every new connection.
Prebuilt wheels for Linux, macOS and Windows, including free-threaded Python. Nothing else to install.
How it compares
Python WebRTC |
aiortc |
LiveKit SDK |
GStreamer webrtcbin |
|
|---|---|---|---|---|
Engine |
libwebrtc (Chrome’s) |
own, in Python |
libwebrtc |
own, in C |
Connects peer-to-peer to any WebRTC endpoint |
✅ |
✅ |
❌ needs a LiveKit server |
✅ |
Browser API ( |
✅ |
similar |
❌ rooms |
❌ GObject signals |
Media path |
native |
Python |
native |
native |
VP9 and AV1 |
✅ |
❌ |
✅ |
✅ |
|
✅ |
✅ |
✅ |
❌ system packages |
Where to start
Install it and connect two peers with a data channel. Five minutes.
Connections, data channels, events and media, organised by what you are trying to do.
Every runnable example in the repository, inlined and ready to copy.
Read the frames of a track, write your own, transform them on the way.
Every interface, dictionary, enum and exception of the package.
What changed in each release.
What it covers
WebRTC:
RTCPeerConnection, data channels, transceivers, senders and receivers, DTLS, ICE and SCTP transports, DTMF, certificates and the stats of WebRTC Statistics.Media Capture and Streams: tracks and streams, with a synthetic camera and microphone.
Media processing:
MediaStreamTrackProcessor,VideoTrackGeneratorandMediaStreamTrackGenerator, with theVideoFrameandAudioDataof WebCodecs and WHATWG Streams.WebRTC Encoded Transform:
RTCRtpScriptTransformand end-to-end encryption with SFrame.
Supported platforms
Pre-built wheels for CPython 3.9 to 3.15, and free-threaded 3.14t and 3.15t, on:
Linux |
macOS |
Windows |
|---|---|---|
x86_64 and aarch64 (glibc 2.27+, manylinux) |
13+, Intel and Apple Silicon |
x64 |
Elsewhere, pip builds it from sources. See Installation.