Skip to main content

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

reactor_webrtc-0.4.0-cp310-abi3-win_amd64.whl (7.8 MB view details)

Uploaded CPython 3.10+Windows x86-64

reactor_webrtc-0.4.0-cp310-abi3-manylinux_2_34_x86_64.whl (8.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.34+ x86-64

reactor_webrtc-0.4.0-cp310-abi3-manylinux_2_34_aarch64.whl (8.3 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.34+ ARM64

reactor_webrtc-0.4.0-cp310-abi3-macosx_13_0_x86_64.whl (8.0 MB view details)

Uploaded CPython 3.10+macOS 13.0+ x86-64

reactor_webrtc-0.4.0-cp310-abi3-macosx_11_0_arm64.whl (7.0 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file reactor_webrtc-0.4.0-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for reactor_webrtc-0.4.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9e0c530e4b5cb0a7d049aee9a93545334fa901e2f740ac9e00e210d68b988589
MD5 cdfd0545917f43938e1740493f2d5ec8
BLAKE2b-256 20088435206a5434d73f0e9c7a08442aa67c6cc0fc01e650a27d1011e5a1f861

See more details on using hashes here.

Provenance

The following attestation bundles were made for reactor_webrtc-0.4.0-cp310-abi3-win_amd64.whl:

Publisher: publish.yml on reactor-team/reactor-webrtc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reactor_webrtc-0.4.0-cp310-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for reactor_webrtc-0.4.0-cp310-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 98972f4d3f0e4eedb4cccf95a7089bb9059a870cd5dc3db9f4adbb07eae7aee1
MD5 a4ab00ba5f408881d34e855189fc28f3
BLAKE2b-256 4e6112be1dac9151602b29dee46175dee15f16d7cd7142cfa9316ddeff95a544

See more details on using hashes here.

Provenance

The following attestation bundles were made for reactor_webrtc-0.4.0-cp310-abi3-manylinux_2_34_x86_64.whl:

Publisher: publish.yml on reactor-team/reactor-webrtc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reactor_webrtc-0.4.0-cp310-abi3-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for reactor_webrtc-0.4.0-cp310-abi3-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 0a7e816739ae05acad669a2bc006aa49014a99e34dc505af28369cb8d3f5db5b
MD5 26503ec2b71189e67d6b8b80a3d9371e
BLAKE2b-256 2873ded4cfbdf150a640359ba42f4fb73ea9171b9cb79674250274c48bd8147c

See more details on using hashes here.

Provenance

The following attestation bundles were made for reactor_webrtc-0.4.0-cp310-abi3-manylinux_2_34_aarch64.whl:

Publisher: publish.yml on reactor-team/reactor-webrtc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reactor_webrtc-0.4.0-cp310-abi3-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for reactor_webrtc-0.4.0-cp310-abi3-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 17d1223bfb2550dae1dd6f54507a725a7043e860bb58365916f7ee607d8f0e8e
MD5 37154a066969a77fdab91ef13d2da030
BLAKE2b-256 3c9614f3c1e314865e74040ec58d1e5639773f440058cec739081ac2fe5272e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for reactor_webrtc-0.4.0-cp310-abi3-macosx_13_0_x86_64.whl:

Publisher: publish.yml on reactor-team/reactor-webrtc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reactor_webrtc-0.4.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for reactor_webrtc-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 514a7ab395fa8656f4d1fa3dadd44598cf5ae63609faf2470feaa199f9aff44d
MD5 586ada6a0c800faac9c29a369084175a
BLAKE2b-256 4eb15159ef95f415e38e442cf7e215750b522cae078afe644e397f2fd766161a

See more details on using hashes here.

Provenance

The following attestation bundles were made for reactor_webrtc-0.4.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on reactor-team/reactor-webrtc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.14.0

5 files

0.13.0

5 files

0.12.1

5 files

0.12.0

5 files

0.11.0

5 files

0.10.0

5 files

0.9.0

5 files

0.8.0

5 files

0.7.2

5 files

0.7.1

5 files

0.7.0

5 files

0.6.0

5 files

0.5.0

5 files

0.4.2

5 files

0.4.1

5 files

This release

0.4.0 This release

5 files

0.3.0

4 files

0.2.0

4 files

0.1.0

4 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page