# 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

- [Quickstart](quickstart.md): installation, and two peers connected with a data channel.
- [Choosing a Python WebRTC library](guides/comparison.md): Python WebRTC, aiortc, the LiveKit SDK and GStreamer
  webrtcbin compared, and when each is the better choice.
- [Migrating from aiortc](guides/aiortc.md): run aiortc code by changing its imports, and what changes on the way.

## Guides

- [Connections](guides/connections.md): configuration, STUN and TURN servers, signalling, states and stats.
- [Data channels](guides/data-channels.md): text and binary messages, reliability, negotiated channels, back
  pressure.
- [Events](guides/events.md): handlers as functions or coroutines, decorators, one-shot handlers, removing them.
- [Media](guides/media.md): reading, writing and transforming the frames of audio and video tracks.
- [H.264](guides/h264.md): VideoToolbox on macOS, Cisco’s OpenH264 binary elsewhere, and its licensing.
- [Field trials](guides/field-trials.md): experimental features of the engine, and WARP for faster connections.

## API reference

- [API reference](api.md): every interface, dictionary, enum and exception.
- [RTCPeerConnection](api/interfaces/rtc_peer_connection.md): the connection to a remote peer.
- [RTCDataChannel](api/interfaces/rtc_data_channel.md): text and binary messages over SCTP.
- [RTCConfiguration](api/models/rtc_configuration.md): the configuration of a connection and its ICE servers.
- [RTCSessionDescriptionInit](api/models/rtc_session_description_init.md): offers and answers as plain data, to
  exchange over signalling.
- [MediaStreamTrack](api/interfaces/media_stream_track.md): tracks and the synthetic camera and microphone.
- [MediaStreamTrackProcessor](api/interfaces/media_stream_track_processor.md): reads the frames of a track.
- [Track generators](api/interfaces/track_generator.md): tracks of frames the application writes.
- [VideoFrame](api/models/video_frame.md) and [AudioData](api/models/audio_data.md): the frames of WebCodecs.
- [Event objects](api/models/events.md): the events handlers are called with.
- [Stats](api/models/rtc_stats.md): the dictionaries of WebRTC Statistics.
- [Enums](api/enums.md) and [Exceptions](api/exceptions.md).

## Examples

- [Echo peer](examples/echo.md): sends back the video it receives, in grayscale.
- [Recorder](examples/recorder.md): writes the video and audio a peer receives to files.
- [Browser and Python server](examples/browser_server.md): serves a page whose camera comes back from Python in
  grayscale, with a chat over a data channel.
- [Voice chat with OpenAI GPT-Live](examples/openai_live.md): talks to the model through the microphone and
  speakers.
- [Voice agent with Gemini Live](examples/gemini_live.md): a browser talks to Gemini over WebRTC through a Python
  server, which streams the audio to the Live API over a WebSocket.
- [Live stream in the terminal](examples/janus_streaming.md): plays a stream of the public Janus demo server.
- [WHIP and WHEP](examples/whip_whep.md): plays a WHEP stream, a public demo by default, or publishes the synthetic
  camera and microphone over WHIP.

## Optional

- [llms-full.txt](https://wrtc.marshal.dev/llms-full.txt): the whole documentation in one file.
- [Benchmarks](benchmarks.md): connection setup, data channels, memory and media against other libraries.
- [Change Log](change_log.md): what changed in each release.
- [Security Policy](security.md): supported versions and reporting vulnerabilities.
