Discover aiortc

Aiortc

WebRTC and ORTC for Python, built on asyncio

aiortc is an open-source library that lets a Python program behave as a real WebRTC peer. Instead of driving a browser, you create an RTCPeerConnection directly in your own code, negotiate a session with an offer and an answer, and then exchange encrypted audio, video and arbitrary data with a browser tab or another WebRTC endpoint.

It is built on asyncio, handles media through PyAV, and is published under the MIT licence. This site is an independent guide that collects practical notes on installing, using and troubleshooting aiortc.

Pure Python

asyncio API

MIT licence

Open source

pip install

From PyPI

● ● ●
peer.py

# a minimal aiortc peer
from aiortc import RTCPeerConnection
from aiortc.contrib.media import MediaPlayer

pc = RTCPeerConnection()
player = MediaPlayer(“clip.mp4”)
pc.addTrack(player.video)

offer = await pc.createOffer()
await pc.setLocalDescription(offer)

Live media track
DTLS-SRTP

media encrypted

Data channel

SCTP · open

Easy to Understand

Plain-language explanations of peer connections, signalling, ICE and media tracks, written for developers meeting WebRTC for the first time.

Feature Focused

Walkthroughs of the parts of aiortc people actually reach for: media players and recorders, data channels, relays and codec negotiation.

Updated Resources

Links pointing back to the official documentation, the source repository and the release notes, so you always verify against the current version.

User Friendly

Checklists, install notes and troubleshooting steps for both first-time users and engineers debugging a stubborn connection in production.

The basics

What Is aiortc?

aiortc is a Python implementation of WebRTC and ORTC. WebRTC is the set of standards browsers use to send audio, video and data directly between two endpoints; ORTC is a related object-oriented API that exposes the same transports at a lower level. aiortc brings both into Python, so a script, a service or a device can be one end of that connection.

The API deliberately mirrors the JavaScript one. You create an RTCPeerConnection, attach tracks or a data channel, call createOffer() and setLocalDescription(), hand the resulting SDP to the other side, and apply the reply with setRemoteDescription(). If you have written browser WebRTC before, the shape of the code will look familiar — the main difference is that everything is a coroutine, because the library is built on asyncio.

Underneath, aiortc leans on focused dependencies rather than bundling a whole browser engine. Connectivity checks and STUN or TURN handling come from aioice. Audio and video encoding and decoding go through PyAV, which wraps FFmpeg. Media is protected with DTLS-SRTP, and data channels ride on SCTP over DTLS. The result is a comparatively small, readable codebase that you can actually step through in a debugger.

One thing aiortc intentionally leaves out is signalling. The standards never specified how two peers should first find each other and swap session descriptions, so aiortc does not pick for you. WebSockets, HTTP, a message queue or copy-and-paste over the terminal all work; the bundled examples show several approaches. That freedom is why the library shows up in such different places: robots streaming a camera feed, test harnesses that need a scriptable peer, media servers, recording bots and IoT gateways.

At a glance

Language

Python 3, asyncio-native

Media

PyAV / FFmpeg pipeline

Security

DTLS-SRTP encrypted media

Connectivity

ICE via aioice, STUN & TURN

Licence

MIT, open source

Not a browser replacement

aiortc speaks the same protocols as a browser, but it is a library, not a runtime with a rendering engine, a microphone picker or a permissions prompt. You supply the media and the signalling yourself.

Capabilities

aiortc Features

What the library gives you out of the box, and where each piece fits into a working real-time connection.

Asyncio-native API

Every network operation is a coroutine, so a single event loop can manage signalling, media and application logic without threads. The class names follow the WebRTC specification closely, which makes browser examples easy to translate into Python.

Audio and video tracks

Media flows through PyAV, the Python binding for FFmpeg. aiortc negotiates common audio codecs such as Opus, PCMU and PCMA, and video codecs including VP8 and H.264, then handles the RTP packetisation and jitter buffering for you.

SCTP data channels

Data channels give you an ordered or unordered, reliable or partially reliable message stream between peers. They run over SCTP inside the same DTLS transport as the media, so no extra port or server is required once the connection is up.

ICE connectivity

Candidate gathering, connectivity checks and STUN and TURN support come from the companion aioice library. You configure ICE servers through RTCConfiguration, and aiortc works through the usual NAT traversal dance the same way a browser does.

DTLS-SRTP security

Media is encrypted end to end with SRTP, keyed by a DTLS handshake, and certificate fingerprints are carried in the SDP exactly as the specification requires. This is what allows aiortc to interoperate with browsers that refuse unencrypted media.

Media helper classes

The contrib.media module ships practical building blocks: MediaPlayer reads files, webcams or streams, MediaRecorder writes them back out, MediaRelay lets several consumers share one source, and MediaBlackhole quietly discards a track you must consume but do not need.

Signalling agnostic

aiortc never dictates how offers and answers reach the far end. Wire it to a WebSocket, an HTTP endpoint, a broker or a terminal paste, and the library is happy. The examples include several small signalling helpers you can copy or replace.

Readable, testable code

Because the whole stack is Python, you can set breakpoints inside the connection logic, log SDP as it is generated, and write automated tests that drive a real peer. That visibility is a large part of why the library is used for research and CI.

The handshake

How aiortc Works

Four stages take you from an empty peer connection to encrypted media moving between two endpoints.

01

Create the peer connection

Instantiate RTCPeerConnection, optionally passing an RTCConfiguration with your STUN or TURN servers, then attach the media tracks or data channel you want to share.

02

Exchange the session description

One side creates an offer, the other replies with an answer. aiortc generates and parses the SDP; carrying it between peers is your signalling channel’s job.

03

Connect and secure the transport

ICE gathers candidates and runs connectivity checks until a working path is found. A DTLS handshake follows, deriving the keys that protect the media and data.

04

Stream, then close cleanly

Media flows as SRTP with RTCP feedback, data channel messages ride over SCTP, and when you are finished you await pc.close() to release everything.

Search intent

Why People Search for aiortc

Search traffic around a library is a surprisingly honest description of where it is hard to use. The questions people bring to aiortc cluster into a handful of recognisable groups, and this page is organised around them rather than around a marketing narrative.

If you already know which group you are in, jump straight to the relevant section — installation, compatibility, usage or troubleshooting each has its own place further down.

Understanding what it is

Most visitors arrive after seeing aiortc in a requirements file or a tutorial and want a straight answer: it is a Python WebRTC library, not an application you launch.

Checking the feature list

Can it record? Can it relay? Does it do data channels as well as media? The capability questions usually come before anyone writes a line of code.

Compatibility questions

Which Python versions are supported, whether wheels exist for a given platform, and whether it will interoperate with Chrome, Firefox and Safari.

Installation problems

A large share of searches are pip failures — usually a build of the media dependencies that cannot find FFmpeg headers on the system.

Updates and versions

People want to know what changed between releases, whether an upgrade will break their pinned dependencies, and how to check the version they have.

Troubleshooting a connection

Connections that stay in checking, media that never arrives, DTLS errors and choppy audio are the classic symptoms people come looking to diagnose.

Comparing alternatives

aiortc sits alongside options such as GStreamer's webrtcbin, Pion in Go and mediasoup in Node, and readers want to know when Python is the right trade-off.

Learning WebRTC itself

Because the code is short and readable, some visitors are not building anything yet — they are using aiortc to understand how WebRTC actually works.

Requirements

aiortc Compatibility

Where aiortc runs, what it needs, and which details genuinely depend on the release you install.

Python runtime

aiortc targets modern CPython 3 releases. The supported range moves forward over time as older Python versions reach end of life, so check the documentation or the package metadata for the version you are installing.

Install inside a virtual environment
Version support varies by release

Operating systems

Linux, macOS and Windows are all used in practice. Pre-built wheels for the compiled dependencies cover many common platform and architecture combinations; where none exists, pip falls back to building from source.

Wheels available for common platforms
Source builds need dev headers

Build dependencies

Compiling the media stack from source needs FFmpeg development files (libavformat, libavcodec, libavdevice, libavfilter), plus Opus, libvpx and OpenSSL headers, and a working C toolchain with pkg-config.

Only required when no wheel matches
Package names differ per distro

Browser interoperability

aiortc implements the same standards browsers do, so it can connect to Chrome, Firefox, Edge and Safari. Which codecs are actually used is decided by negotiation, and H.264 in particular depends on how your FFmpeg build was compiled.

Codec choice is negotiated
H.264 depends on the local build

Other WebRTC stacks

Because the wire protocols are standard, aiortc has been used against SFUs and gateways such as Janus, and against implementations in other languages. The repository includes examples that connect to external services.

Standards-based interop
Behaviour depends on the remote stack

Python dependencies

Installing aiortc pulls in its own dependency set, including aioice for ICE, av for media, cryptography and pylibsrtp for the security layer, and pyee for events. Exact pins change between releases.

Resolved automatically by pip
Pin versions for reproducible builds

Always verify against your own version. Supported Python releases, dependency pins and available wheels change between aiortc releases. Treat the notes above as orientation and confirm the specifics in the official documentation and release notes for the version you install.

Practical usage

How to Use aiortc

A seven-step path from an empty project to a working connection, in the order you will actually meet each piece.

01

Install the package into a clean environment

Create and activate a virtual environment, upgrade pip, then install aiortc from PyPI. Keeping the project isolated avoids clashes with system packages and makes the dependency set easy to inspect later.

02

Create a peer connection

Import RTCPeerConnection and instantiate it. If your peers sit behind NAT, pass an RTCConfiguration containing the STUN and TURN servers you intend to use rather than relying on defaults.

03

Attach media or open a data channel

Use MediaPlayer to read a file, a webcam or a stream and add its audio and video tracks with addTrack. For messaging instead of media, call createDataChannel and handle its open and message events.

04

Negotiate with an offer and an answer

The initiating side calls createOffer and setLocalDescription; the responding side applies it with setRemoteDescription and replies with createAnswer. Both descriptions must be applied before media can flow.

05

Carry the SDP over your own signalling

aiortc does not ship a signalling server. Send the session descriptions and any ICE candidates over whatever channel suits your application — a WebSocket, an HTTP endpoint or a message broker.

06

Handle incoming tracks

Register a handler for the track event. Every received track must be consumed — write it out with MediaRecorder, forward it through MediaRelay, or discard it with MediaBlackhole — otherwise buffers grow.

07

Watch state changes and close cleanly

Listen to connectionstatechange to detect failures, and always await pc.close() when you are finished so transports, recorders and background tasks are released.

Setup

How to Install aiortc

In most cases installation is a single pip command, because pre-built wheels exist for the compiled dependencies on common platforms. The steps below cover the path that works everywhere, including machines that have to build from source.

1 · Requirements

  • A supported CPython 3 release — check the current documentation, since the minimum moves forward over time
  • pip, setuptools and wheel updated to recent versions
  • Network access to PyPI
  • A C toolchain and development headers only if no wheel matches your platform

2 · Prepare an isolated environment

python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
python -m pip install –upgrade pip setuptools wheel

3 · Install the package

pip install aiortc

Several of the examples also need an HTTP server or signalling helper; the repository lists the extra packages each one expects, commonly aiohttp.

4 · Build dependencies, if pip has to compile

When no wheel matches your platform, pip builds the media layer from source and needs FFmpeg, Opus and libvpx headers present. Package names differ between distributions — the commands below are typical starting points, not a guarantee for your system.

# Debian / Ubuntu
sudo apt install pkg-config libavdevice-dev libavfilter-dev libopus-dev libvpx-dev libssl-dev

# macOS with Homebrew
brew install pkg-config ffmpeg opus libvpx

5 · Verify the installation

pip show aiortc

The output confirms the installed version and location. For a functional check, import the library and construct a peer connection inside a small asyncio script — if that succeeds, the compiled dependencies loaded correctly.

6 · Configuration

There is no configuration file to edit. Behaviour is set in code: ICE servers through RTCConfiguration and RTCIceServer, media sources through the contrib.media helpers, and logging through Python’s standard logging module.

7 · Updating

pip install –upgrade aiortc

Read the release notes first. Because aiortc tracks evolving standards and compiled dependencies, minor releases can change supported Python versions or codec behaviour. Pin versions in your requirements file and test upgrades in a branch.

Install from official sources only. Use PyPI or the project’s own repository. This site does not host, mirror or link to unofficial builds, and you should treat any third-party package claiming to be aiortc with suspicion.

Why teams reach for it

A real WebRTC peer that lives inside your Python process

The usual way to automate WebRTC is to drive a headless browser and hope it behaves. aiortc removes that layer entirely. Your service holds the peer connection itself, so you can inspect the SDP it produces, decide frame by frame what to send, and keep the whole pipeline inside code you can test.

That matters most where a browser is awkward or impossible: a robot streaming a camera over a mobile link, a recording bot joining a room, a load test that needs fifty scriptable peers, or an embedded gateway with no display at all.

Media
Opus · VP8 · H.264
Transport
ICE · DTLS · SRTP · SCTP

Scriptable peers for testing

Spin up as many peers as you need inside a test suite, drive them deterministically, and assert on what actually arrived instead of screenshotting a browser.

Devices and edge hardware

Read from a camera with MediaPlayer, encode once, and share the result with several viewers through MediaRelay — no browser runtime on the device.

Recording and post-processing

MediaRecorder writes incoming tracks to disk in the formats FFmpeg supports, which makes archiving or offline analysis a few lines rather than a project.

Side by side

aiortc Comparison

How a Python peer differs from the browser stack most WebRTC tutorials assume.

Feature
aiortc
Browser / JS stack
Notes

Runtime

A Python process using asyncio

A browser tab or headless browser instance

Removes the browser from your deployment

API style

RTCPeerConnection mirrored in Python coroutines

The standard JavaScript WebRTC API

Concepts and method names transfer directly

Media source

Files, cameras and streams via PyAV and FFmpeg

getUserMedia and browser capture APIs

aiortc can serve media on machines with no UI

Signalling

Not included — you provide the transport

Also not included; usually a WebSocket

Neither standard defines signalling

Codec support

Depends on how the FFmpeg build was compiled

Fixed by the browser vendor

Verify H.264 availability in your environment

Debugging

Breakpoints and logs inside the connection logic

Browser devtools and internal WebRTC pages

Different strengths rather than a clear winner

This comparison describes structural differences between running WebRTC in Python and running it in a browser. It is not a performance benchmark, and neither option is universally better — a browser remains the right choice for user-facing calling interfaces.

An honest read

Strengths and Trade-offs

Both columns matter. Knowing the constraints early saves more time than any feature list.

aiortc Highlights

  • Standards-based, so it interoperates with browsers and other WebRTC implementations rather than needing a matching client
  • The asyncio API closely follows the specification, which makes browser examples straightforward to port
  • Media, security and data channels are all handled — you are not assembling RTP and DTLS yourself
  • Small enough to read: you can trace a connection through the source when something behaves unexpectedly
  • Useful helper classes for playing, recording, relaying and discarding media
  • MIT licensed, with examples covering servers, webcams, data channels and external gateways

Things to Consider

  • Signalling is not provided, so every project starts by building or borrowing that layer
  • You need to be comfortable with asyncio; blocking calls in a coroutine will disrupt media timing
  • Installation can require compiling media dependencies when no wheel matches your platform
  • Codec availability, particularly H.264, depends on how the underlying FFmpeg build was configured
  • Software encoding in Python-managed processes is heavier than native pipelines at large scale
  • Supported Python versions and dependency pins shift between releases, so upgrades need testing
Diagnostics

Common aiortc Problems & Solutions

Eight failures that account for most of the time people lose, with the reason behind each one.

pip install fails while building a dependency

Likely reason: No pre-built wheel matched your Python version, platform or architecture, so pip tried to compile the media layer and could not find the FFmpeg, Opus or libvpx headers.

Suggested fix

Upgrade pip, setuptools and wheel first, then install the development packages for FFmpeg, Opus, libvpx and OpenSSL plus pkg-config, and retry the install.

The connection never leaves checking

Likely reason: ICE could not find a working path between the peers. This is normal when both endpoints sit behind restrictive NATs or firewalls and only STUN is configured.

Suggested fix

Add a TURN server to your RTCConfiguration and confirm the credentials work. Test both peers on the same LAN first to prove the rest of the pipeline is sound.

The connection succeeds but no video appears

Likely reason: Usually a codec that both sides advertised but only one can actually handle, a track that is never consumed, or a sender that was added after the offer was created.

Suggested fix

Log the negotiated SDP, attach a handler to the track event, and make sure every incoming track is consumed by a recorder, a relay or a blackhole so frames are pulled.

DTLS handshake errors or certificate failures

Likely reason: A badly wrong system clock, a stale or mismatched fingerprint in the SDP, or a proxy or middlebox interfering with UDP can all break the handshake.

Suggested fix

Check the system time on both machines, confirm the fingerprint in the SDP matches the peer that sent it, and retest without the proxy to isolate the cause.

Audio or video stutters and drifts

Likely reason: Something blocking is running inside the event loop, or the machine cannot encode fast enough for the resolution and frame rate you chose.

Suggested fix

Move CPU-heavy or blocking work to an executor, lower the resolution or frame rate, and reuse one encoded source across viewers with MediaRelay instead of encoding per peer.

The connection closes almost immediately

Likely reason: A very common Python cause: the RTCPeerConnection was created inside a function and garbage collected once that function returned, taking the transports with it.

Suggested fix

Keep a reference to every active peer connection, for example in a set or a dictionary keyed by session, and remove it only after awaiting pc.close().

MediaPlayer cannot open a camera or file

Likely reason: The device path or format string is wrong for the platform, another process already holds the device, or FFmpeg was built without that input format.

Suggested fix

Confirm the source works with the ffmpeg command line first, pass the correct format for your operating system, and close other applications using the device.

Errors about the event loop or coroutines

Likely reason: aiortc is asynchronous throughout, so calling its methods without awaiting them, or mixing them with a blocking framework, produces confusing runtime errors.

Suggested fix

Await every coroutine, run your application from a single asyncio entry point, and use an async-aware web framework for the signalling side.

Field notes

aiortc Tips & Best Practices

Six habits that consistently separate a demo that works once from a service that keeps working.

Pin your dependencies

Record exact versions of aiortc and its dependency tree in a requirements or lock file. Real-time stacks are sensitive to small changes, and a pinned environment turns a mysterious regression into a one-line diff.

Encode once, share with MediaRelay

If several peers need the same camera or file, wrap the source in a MediaRelay rather than opening it repeatedly. One decode feeds every subscriber and CPU use stops scaling with the audience.

Always close what you open

Await pc.close() when a session ends, stop recorders explicitly, and clear the reference you kept. Skipping cleanup is the usual cause of processes that grow steadily over days.

Budget for TURN before launch

STUN alone works on friendly networks and fails on corporate and mobile ones. Decide who runs your TURN server and what it costs while you are still prototyping, not the week you go live.

Log SDP and connection state early

Enable Python logging for the library and record connection and ICE state changes from the first prototype. When something breaks in the field, that history is usually what identifies the cause.

Start from the bundled examples

The repository ships working servers, webcam senders, data channel clients and gateway integrations. Adapting one is far faster — and far less error-prone — than assembling a connection from scratch.

In depth

Complete aiortc Guide

What aiortc actually is

aiortc is a library, not an application. Installing it does not start a server or open a window; it adds a set of classes to your Python environment that together implement the WebRTC and ORTC specifications. The centrepiece is RTCPeerConnection, which owns the negotiation, the transports and the tracks for a single session with a single remote peer. Everything else in the library either feeds that object or reads from it.

Because it follows the standards rather than inventing a protocol, an aiortc peer can talk to anything else that speaks WebRTC — a browser tab, a media server, another aiortc process, or an implementation written in a different language. That interoperability is the whole point, and it is worth remembering when a connection fails: the problem is usually in your network path or your negotiation, not in an incompatible dialect.

Who it is for

The library suits people who need a programmable endpoint. Typical users include engineers streaming from robots, drones and embedded cameras; teams building recording or transcription bots that join existing calls; researchers who want to observe how a real WebRTC session behaves; and QA groups who need dozens of predictable peers in a test run. If your goal is a video calling interface for humans, a browser front-end plus a media server is still the conventional answer — aiortc more often sits behind that, or replaces the awkward automation around it.

The pieces you will use most

  • RTCPeerConnection — creates offers and answers, manages senders and receivers, and reports connection state.
  • RTCSessionDescription — the offer or answer object you move across your signalling channel.
  • MediaPlayer — reads a file, a device or a stream and exposes audio and video tracks.
  • MediaRecorder — writes received tracks out to a file in any container FFmpeg supports.
  • MediaRelay — subscribes many consumers to one source without decoding it repeatedly.
  • MediaBlackhole — consumes a track you must drain but do not want to keep.
  • RTCDataChannel — sends text or binary messages over SCTP inside the same secure transport.

Requirements and environment

You need a supported CPython 3 release and pip. Everything else arrives as a dependency: aioice for connectivity, av for media, cryptography and pylibsrtp for the security layer, and pyee for the event emitter pattern the API uses. On platforms where wheels are published, none of this needs compiling. Where they are not, pip builds from source and your system must already provide FFmpeg, Opus, libvpx and OpenSSL development files.

Work inside a virtual environment. Real-time media stacks pull in compiled extensions, and mixing them with a system Python installation is the fastest route to a confusing failure that is hard to reproduce on a colleague’s machine.

How a session actually runs

A session has a predictable shape. You build a peer connection and attach what you want to send. You create an offer, apply it locally, and transmit it. The far end applies it, produces an answer, and sends that back. While this is happening, ICE gathers candidates and tests paths; once one succeeds, a DTLS handshake establishes keys, and media begins flowing as SRTP with RTCP feedback. Data channel messages travel over SCTP inside the same encrypted transport. When you are done, closing the peer connection tears all of it down.

The part that trips people up is that none of this starts until both session descriptions are applied — and that carrying them between peers is entirely your responsibility. If you are watching a connection sit idle, check your signalling before you suspect the library.

Updating without surprises

Upgrade deliberately. Read the release notes, because a new version can move the supported Python range, change a dependency pin, or adjust codec handling. Upgrade in a branch, run your interoperability tests against a real browser, and keep the previous pinned set until the new one has proved itself. This is ordinary dependency hygiene, but it matters more here than usual because failures often appear as degraded media rather than a clean exception.

Things worth knowing before you commit

Two constraints shape most projects. The first is that Python’s concurrency model rewards non-blocking code: anything slow inside the event loop shows up directly as jitter or dropped frames, so heavy work belongs in an executor or another process. The second is that software encoding costs CPU, so serving many viewers means relaying one encoded stream rather than encoding per viewer, or moving that responsibility to a dedicated media server.

Neither is a reason to avoid the library. They are simply the shape of the tool, and projects that plan around them from the start tend to go smoothly. For anything authoritative — supported versions, current APIs, exact dependency requirements — read the official documentation and source repository for the release you are installing.

The one rule to remember

Keep a reference to every live peer connection. Losing it to garbage collection ends the session silently and looks like a network fault.

Signalling is yours

The specification never defined it. Pick a transport you already operate — a WebSocket is the usual choice — and keep it simple.

Plan for CPU

Encoding is the expensive part. Relay one encoded source to many consumers instead of encoding separately for each of them.

Trust the source

Version-specific answers belong in the official documentation and release notes, not in any third-party page including this one.

Keep reading

The sections above cover installation, compatibility, usage and troubleshooting in more detail. The FAQ below answers the twenty questions that come up most often.

Where to look next

aiortc Download & Resources

Pointers rather than mirrors. Every link below is a placeholder you can repoint inside Elementor.

aiortc Resources

Official documentation, the source repository and the package listing. Replace this button's link in Elementor with your chosen destination.

Installation Guide

Requirements, environment setup, the install command and what to do when pip has to build from source.

Latest Information

Release notes and changelogs are the only reliable place to confirm supported versions and recent behaviour changes.

Use reputable sources and check the version. Install aiortc from PyPI or the official repository only, and confirm compatibility details against the documentation for the release you are using. The buttons above are editable placeholders — no download URLs are supplied here, and this site does not mirror or redistribute any package.

Answers

aiortc Frequently Asked Questions

Twenty questions, answered plainly. Version-specific details should always be confirmed in the official documentation.

aiortc is an open-source library that implements WebRTC and ORTC in Python. It lets your own code act as a real peer: negotiating a session, exchanging encrypted audio and video, and opening data channels with a browser or another WebRTC endpoint. It is built on asyncio, released under the MIT licence, and installed from PyPI with pip.

You create an RTCPeerConnection and attach tracks or a data channel. One side produces an offer, the other answers, and you carry those session descriptions over your own signalling channel. ICE then finds a working network path, a DTLS handshake establishes encryption keys, and media flows as SRTP while data channel messages travel over SCTP.

An asyncio API that mirrors the browser WebRTC interface, audio and video through PyAV with codecs such as Opus, PCMU, PCMA, VP8 and H.264, SCTP data channels, ICE connectivity via aioice with STUN and TURN support, DTLS-SRTP encryption, and helper classes for playing, recording, relaying and discarding media.

It is approachable if you already know asyncio and have seen browser WebRTC, because the class and method names match the specification. The learning curve comes from WebRTC itself — signalling, ICE and codec negotiation — rather than from the library. Starting with one of the bundled examples is much easier than building from scratch.

Anywhere a supported CPython 3 release runs, which in practice means Linux, macOS and Windows, including many single-board computers. Pre-built wheels cover common platform and architecture combinations; elsewhere pip compiles the media dependencies from source and needs the relevant development headers present.

Create and activate a virtual environment, upgrade pip, setuptools and wheel, then run pip install aiortc. On systems without a matching wheel, install the FFmpeg, Opus, libvpx and OpenSSL development packages plus pkg-config beforehand so the build can find its headers.

Run pip install –upgrade aiortc inside the same environment. Read the release notes first, because a new version may change supported Python releases or dependency pins. Upgrade in a branch, run your interoperability tests against a real browser, and keep the previous pinned versions until the new set is proven.

The frequent causes are ICE failing without a TURN server, a peer connection being garbage collected because no reference was kept, an incoming track that is never consumed, blocking code inside the event loop, or missing system libraries after a source build. Enable logging and check the connection state to narrow it down.

Confirm your Python version is supported by the release you want, work inside a virtual environment, update pip and its build tools, and decide whether a wheel exists for your platform. If not, install the media development packages first. Also check that outbound STUN and TURN traffic is permitted on your network.

Yes, and this matters. Supported Python releases, dependency pins, available wheels and codec handling can all change between versions. Treat any general guidance, including the notes on this page, as orientation, and confirm the details in the documentation and release notes for the specific version you install.

The official documentation, the source repository with its examples directory, the package listing on PyPI, and the project’s issue tracker are the authoritative sources. The examples in particular are the fastest way to see a complete working session, since they include signalling code that the library itself does not provide.

Work outward from the simplest case. Test both peers on the same local network first to prove the media pipeline works, then add NAT traversal. Enable Python logging, record connection and ICE state changes, and print the negotiated SDP so you can see which codecs and candidates were actually agreed.

Yes. Run pip uninstall aiortc, or simply delete the virtual environment if the project used a dedicated one. Note that dependencies installed alongside it, such as aioice, av, cryptography and pylibsrtp, are not removed automatically and may still be needed by other packages in the same environment.

Record your current working versions in a requirements or lock file, read the changelog for the release you are moving to, and upgrade in a branch rather than in production. Re-run your tests, including a real browser connection, before you promote the change.

Its Python dependencies install automatically with pip. Building from source additionally requires FFmpeg, Opus, libvpx and OpenSSL development files with a C toolchain. Several of the bundled examples also expect an extra package such as aiohttp to serve their signalling endpoint.

Run pip show aiortc in the environment where it is installed. The output reports the version, the install location and the dependency list. pip list gives a broader view when you want to see the versions of aioice, av and the other supporting packages at the same time.

Build failures during pip install, connections stuck in the checking state, media that never arrives despite a successful connection, DTLS handshake errors, choppy audio or video caused by blocking code, and sessions that close immediately because the peer connection object was not kept alive.

Read the official documentation for the API reference, then work through the examples in the source repository — they cover a media server, a webcam sender, data channel clients and gateway integrations. Reading the WebRTC specifications alongside them explains why the API is shaped the way it is.

No. This site is an independent, community-run information resource about the open-source aiortc project. It is not affiliated with, endorsed by or operated by the aiortc maintainers, and it does not host or distribute the software. For authoritative and current information, always refer to the official repository and documentation.

Three things save the most time. Learn enough asyncio to keep blocking work out of the event loop. Accept that you must build the signalling layer yourself. And expect to need a TURN server before real users connect, because STUN alone will not get you through restrictive networks.

Start here

Explore aiortc

Read the guide, work through the installation steps, then adapt one of the official examples into your own project. Real-time media rewards a careful first hour more than almost anything else you will build this week.

Editorial note. aiortc.com is an independent information resource about the open-source aiortc project. It is not affiliated with, endorsed by or operated by the project’s maintainers or any related organisation. aiortc is released by its authors under the MIT licence; all trademarks and project names belong to their respective owners. Technical details change between releases, so always verify version-specific information against the official documentation and repository before relying on it.

Scroll to Top