Python WebRTC
Bindings to the native WebRTC M152, with the API of the browsers: peer connections, data channels, media tracks and their frames, encoded transforms and stats, as the W3C specifications define them, in asyncio.
import asyncio
import webrtc
async def main():
pc = webrtc.RTCPeerConnection()
channel = pc.create_data_channel('chat')
offer = await pc.create_offer()
await pc.set_local_description(offer)
print(pc.local_description.sdp)
asyncio.run(main())
pip install wrtc
Warning
Under development. Until the 1.0.0 release, compatibility between versions is not guaranteed.
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.
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.
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.