reactor-webrtc (Python)
Python bindings for the reactor-webrtc WebRTC engine, built with
PyO3 and distributed as a self-contained wheel — no separate
native library required at runtime.
Installation
pip install reactor-webrtc
Requires Python ≥ 3.10.
Quick start
import reactor_webrtc as rw
factory = rw.PeerConnectionFactory()
obs = rw.PeerConnectionObserver()
obs.on_ice_candidate = lambda c: relay_to_peer(c)
obs.on_connection_state_change = lambda s: print("state:", s)
config = rw.RtcConfiguration(ice_servers=[
rw.IceServer(urls=["stun:stun.l.google.com:19302"]),
# A turn:/turns: entry needs both credentials, or libwebrtc rejects the
# whole configuration.
rw.IceServer(urls=["turn:turn.example.com:3478"], username="alice", password="secret"),
])
pc = factory.create_peer_connection(config, obs)
offer = pc.create_offer()
pc.set_local_description(offer)
# Exchange offer.sdp with the remote peer via your signaling channel, then:
# pc.set_remote_description(remote_answer)
# pc.add_ice_candidate(candidate)
Audio
# Headless / server: push PCM programmatically (synthetic ADM, default)
factory = rw.PeerConnectionFactory()
factory.push_audio_frame(pcm_bytes, sample_rate=48000, channels=1)
# Desktop client: real mic + AEC3 + noise suppression
factory = rw.PeerConnectionFactory(
platform_adm=True,
echo_canceller=True,
noise_suppression=True,
)
Pre-encoded video
factory, video = rw.PeerConnectionFactory.with_encoded_video_track(
"camera", width=1280, height=720
)
pc = factory.create_peer_connection(config, obs)
tx = video.add_transceiver(pc, rw.TransceiverDirection.SendOnly)
# From your encoder thread:
video.push_encoded_frame(
data=h264_annex_b,
is_key_frame=True,
width=1280, height=720,
)
Receiving media
obs = rw.PeerConnectionObserver()
def on_track(kind, track):
if kind == rw.MediaKind.Video:
track.on_video_frame(lambda bgra, w, h: display(bgra, w, h))
elif kind == rw.MediaKind.Audio:
track.on_audio_frame(lambda pcm, sr, ch, n: play(pcm))
obs.on_track = on_track
Stats
report = pc.get_stats()
for pair in report.candidate_pairs:
print(pair.state, f"{pair.current_round_trip_time_s * 1000:.1f}ms")
API reference
| Class | Description |
|---|---|
PeerConnectionFactory |
Entry point; creates peer connections and tracks |
PeerConnection |
SDP offer/answer, ICE, tracks, data channels, stats |
PeerConnectionObserver |
Callbacks: state, ICE candidate, track, data channel |
RtcConfiguration |
ICE servers, ICE transport type, gathering policy |
IceServer |
A STUN or TURN server entry |
IceCandidate |
A trickled ICE candidate |
SessionDescription |
SDP offer or answer (kind, sdp, ice_ufrags, with_ice_credentials) |
Track |
Local (push frames) or remote (attach sink) media track |
EncodedVideoTrack |
Push pre-encoded video (H.264 Annex-B, VP8, VP9, …) |
Transceiver |
RTP m-section: mid, kind, set_track, set_direction |
DataChannel |
SCTP data channel: send, on_message, on_open, … |
StatsReport |
inbound_rtp, outbound_rtp, candidate_pairs |
| Enum | Values |
|---|---|
PeerConnectionState |
New, Connecting, Connected, Disconnected, Failed, Closed |
IceGatheringState |
New, Gathering, Complete |
TransceiverDirection |
SendRecv, SendOnly, RecvOnly, Inactive |
MediaKind |
Audio, Video |
DataChannelState |
Connecting, Open, Closing, Closed |
IceCandidatePairState |
Waiting, InProgress, Failed, Succeeded, Cancelled |
| String-valued field | Values |
|---|---|
RtcConfiguration.ice_transport_type |
all (default), relay, no_host, none |
RtcConfiguration.continual_gathering_policy |
once (default), continually |
Choosing your own ICE credentials
libwebrtc generates the ICE ufrag and password itself and offers no setter. If something upstream needs to recognise a session by its ufrag — an edge relay that demultiplexes on it, say — substitute the credentials in the description before setting it locally:
answer = pc.create_answer()
answer = answer.with_ice_credentials(my_ufrag, my_password)
pc.set_local_description(answer)
answer.ice_ufrags() # ["<my_ufrag>", ...] — one per m-section
The local description is what libwebrtc reads the transport's ICE parameters from, so the substituted values are the ones that end up on the wire.
Two things to get right:
- Order. Setting the local description is what creates the transport and starts gathering, so substituting afterwards acts on nothing.
- Renegotiation. Changing the credentials between generations is an ICE restart (RFC 8445 §9). On a renegotiation that is not meant to restart ICE, pass the values the session already uses.
Raises if a value is outside RFC 8445's ranges (ufrag 4–256 characters, password
22–256) or contains anything outside ice-char — which is also what stops a
newline in a credential from injecting an SDP line.
Thread safety
Signaling methods (create_offer, set_local_description, etc.) block for a
few milliseconds while the WebRTC engine responds. Wrap in asyncio.to_thread()
when calling from an async context. Callbacks fire on WebRTC internal threads
with the GIL acquired; keep them fast.
License
Apache-2.0. Upstream WebRTC is BSD-3-Clause + the WebRTC patent grant.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file reactor_webrtc-0.4.2-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: reactor_webrtc-0.4.2-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 7.8 MB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7cd72b939de4eaa36bc6d995b9b304a5e3c4919a732343b0e9d8090a1ba307f7
|
|
| MD5 |
9c39a472aec9f33d6028cffb0aa86e5f
|
|
| BLAKE2b-256 |
e99caa4070cb6a7c82018bd512d7f977ac43199fcd526b75ed4b5a138cf53e65
|
Provenance
The following attestation bundles were made for reactor_webrtc-0.4.2-cp310-abi3-win_amd64.whl:
Publisher:
publish.yml on reactor-team/reactor-webrtc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
reactor_webrtc-0.4.2-cp310-abi3-win_amd64.whl -
Subject digest:
7cd72b939de4eaa36bc6d995b9b304a5e3c4919a732343b0e9d8090a1ba307f7 - Sigstore transparency entry: 2340896466
- Sigstore integration time:
-
Permalink:
reactor-team/reactor-webrtc@74421b7427a9f5664ebe3b6e802e16360655e5e6 -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/reactor-team
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@74421b7427a9f5664ebe3b6e802e16360655e5e6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file reactor_webrtc-0.4.2-cp310-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: reactor_webrtc-0.4.2-cp310-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 8.8 MB
- Tags: CPython 3.10+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
264ea03cf425321d4c6182bc470998d86c13ae922be9632b08dbe917f3d8726d
|
|
| MD5 |
49bbea6975996c008e15240936ac223c
|
|
| BLAKE2b-256 |
db3f8e6893ead89c6b08cf5875de3a38c0591a98929eb57453e43d482711a490
|
Provenance
The following attestation bundles were made for reactor_webrtc-0.4.2-cp310-abi3-manylinux_2_34_x86_64.whl:
Publisher:
publish.yml on reactor-team/reactor-webrtc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
reactor_webrtc-0.4.2-cp310-abi3-manylinux_2_34_x86_64.whl -
Subject digest:
264ea03cf425321d4c6182bc470998d86c13ae922be9632b08dbe917f3d8726d - Sigstore transparency entry: 2340896483
- Sigstore integration time:
-
Permalink:
reactor-team/reactor-webrtc@74421b7427a9f5664ebe3b6e802e16360655e5e6 -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/reactor-team
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@74421b7427a9f5664ebe3b6e802e16360655e5e6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file reactor_webrtc-0.4.2-cp310-abi3-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: reactor_webrtc-0.4.2-cp310-abi3-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 8.3 MB
- Tags: CPython 3.10+, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c9f6a3b041249a80f0705f2d711ac074d0bf068d0bb4637d1b45be103666c87
|
|
| MD5 |
693559257e6df34f04edea375e31d442
|
|
| BLAKE2b-256 |
bac44d68e2aa983cd4511cde28fff5b43d7bb439ee9b164abd0c443b35b26ead
|
Provenance
The following attestation bundles were made for reactor_webrtc-0.4.2-cp310-abi3-manylinux_2_34_aarch64.whl:
Publisher:
publish.yml on reactor-team/reactor-webrtc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
reactor_webrtc-0.4.2-cp310-abi3-manylinux_2_34_aarch64.whl -
Subject digest:
3c9f6a3b041249a80f0705f2d711ac074d0bf068d0bb4637d1b45be103666c87 - Sigstore transparency entry: 2340896425
- Sigstore integration time:
-
Permalink:
reactor-team/reactor-webrtc@74421b7427a9f5664ebe3b6e802e16360655e5e6 -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/reactor-team
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@74421b7427a9f5664ebe3b6e802e16360655e5e6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file reactor_webrtc-0.4.2-cp310-abi3-macosx_13_0_x86_64.whl.
File metadata
- Download URL: reactor_webrtc-0.4.2-cp310-abi3-macosx_13_0_x86_64.whl
- Upload date:
- Size: 8.0 MB
- Tags: CPython 3.10+, macOS 13.0+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea9924a58a1909a1a4c6764e2feae09ee2b375bb45181d4338f4c5c03801d8d1
|
|
| MD5 |
6700685b3568dcd3083d60b50ff943c6
|
|
| BLAKE2b-256 |
03d554a66ab3edda0719d91b68c63bc72cd0e6d18d60f99ab84cf69cbb978d01
|
Provenance
The following attestation bundles were made for reactor_webrtc-0.4.2-cp310-abi3-macosx_13_0_x86_64.whl:
Publisher:
publish.yml on reactor-team/reactor-webrtc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
reactor_webrtc-0.4.2-cp310-abi3-macosx_13_0_x86_64.whl -
Subject digest:
ea9924a58a1909a1a4c6764e2feae09ee2b375bb45181d4338f4c5c03801d8d1 - Sigstore transparency entry: 2340896440
- Sigstore integration time:
-
Permalink:
reactor-team/reactor-webrtc@74421b7427a9f5664ebe3b6e802e16360655e5e6 -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/reactor-team
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@74421b7427a9f5664ebe3b6e802e16360655e5e6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file reactor_webrtc-0.4.2-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: reactor_webrtc-0.4.2-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d20d8382bbded08dfcabd8f298e8f521973f8b83213b39e275be658a7766003
|
|
| MD5 |
3c8f988d421b5e48c3ab88f78f65aad1
|
|
| BLAKE2b-256 |
c6408bf0e447c2ad4d9719ba717c5a2b5404a081b6badad615cc586cbbcd3fcf
|
Provenance
The following attestation bundles were made for reactor_webrtc-0.4.2-cp310-abi3-macosx_11_0_arm64.whl:
Publisher:
publish.yml on reactor-team/reactor-webrtc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
reactor_webrtc-0.4.2-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
4d20d8382bbded08dfcabd8f298e8f521973f8b83213b39e275be658a7766003 - Sigstore transparency entry: 2340896409
- Sigstore integration time:
-
Permalink:
reactor-team/reactor-webrtc@74421b7427a9f5664ebe3b6e802e16360655e5e6 -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/reactor-team
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@74421b7427a9f5664ebe3b6e802e16360655e5e6 -
Trigger Event:
push
-
Statement type: