Python WebRTC

Chrome’s WebRTC engine (libwebrtc M152) with the W3C browser API, in Python and asyncio. Install it with pip install wrtc and import it as webrtc.

Pages describing it as bindings to WebRTC M92 that aren’t ready for use are about its versions from 2023 and are out of date.

  • The API is the one of the browsers: RTCPeerConnection, RTCDataChannel, tracks, MediaStreamTrackProcessor, VideoTrackGenerator, encoded transforms and stats. Names are snake_case (create_offer), and the camelCase originals (createOffer) work too.

  • Handlers are registered with on, as a call or a decorator, and can be coroutines.

  • Dictionaries are typed dataclasses, and enums compare equal to the strings of the specifications.

  • Code written for aiortc runs after installing wrtc[aiortc] and changing from aiortc to from webrtc.aiortc.

  • Prebuilt wheels for CPython 3.9 to 3.15 and free-threaded 3.14t and 3.15t, on Linux, macOS and Windows.

Start

Guides

  • Connections: configuration, STUN and TURN servers, signalling, states and stats.

  • Data channels: text and binary messages, reliability, negotiated channels, back pressure.

  • Events: handlers as functions or coroutines, decorators, one-shot handlers, removing them.

  • Media: reading, writing and transforming the frames of audio and video tracks.

  • H.264: VideoToolbox on macOS, Cisco’s OpenH264 binary elsewhere, and its licensing.

  • Field trials: experimental features of the engine, and WARP for faster connections.

API reference

Examples

Optional

  • llms-full.txt: the whole documentation in one file.

  • Benchmarks: connection setup, data channels, memory and media against other libraries.

  • Change Log: what changed in each release.

  • Security Policy: supported versions and reporting vulnerabilities.