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

The real engine

ICE, DTLS, SCTP, congestion control, jitter buffers and codecs are Chrome’s own, so interop with browsers is the browsers’ interop.

The browser API

Written against the W3C specifications and tested with the web-platform-tests the browsers use.

Native media path

Packets, decoding and encoding never touch Python. You see frames, not packets.

Every modern codec

VP8, VP9, AV1, H.264 and Opus. Hardware H.264 through VideoToolbox on macOS. See H.264.

Fast connection setup

WARP: DTLS 1.3, SNAP and SPED cut round trips off every new connection.

pip install and go

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 (RTCPeerConnection, createOffer, …)

✅

similar

❌ rooms

❌ GObject signals

Media path

native

Python

native

native

VP9 and AV1

✅

❌

✅

✅

pip install on Linux, macOS and Windows

✅

✅

✅

❌ system packages

Where to start

Quickstart

Install it and connect two peers with a data channel. Five minutes.

Quickstart
Guides

Connections, data channels, events and media, organised by what you are trying to do.

Guides
Examples

Every runnable example in the repository, inlined and ready to copy.

Examples
Media

Read the frames of a track, write your own, transform them on the way.

Media
API reference

Every interface, dictionary, enum and exception of the package.

API reference
Changelog

What changed in each release.

Change Log

What it covers

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.