Python WebRTC Models
A Python library providing lightweight models designed for analyzing WebRTC statistics. It helps estimate quality of experience, predict network congestion, and perform other related tasks using simple prediction models. Currently at version 0.3.0, it follows a feature-driven release cadence, with updates for new models or API refinements.
Common errors
-
TypeError: PacketLossPredictor.predict() got an unexpected keyword argument 'inbound_rtp_packets_lost'
cause The `predict` method signature changed in version 0.3.0 from accepting keyword arguments to a single dictionary.fixPass a dictionary of features instead: `predictor.predict({'inbound_rtp_packets_lost': 0, 'inbound_rtp_packets_received': 100})`. -
KeyError: 'some_missing_feature'
cause The input dictionary to `predict` is missing a required feature key or has a misspelled key for the specific model being used.fixProvide all necessary feature keys as defined by the model. Check the model's documentation or the library's source for required keys (e.g., in the `__init__` or `predict` method definitions). -
ModuleNotFoundError: No module named 'webrtc_models'
cause The `webrtc-models` library is not installed in the current Python environment.fixInstall the library using `pip install webrtc-models`. Ensure your Python environment is correctly activated. -
ImportError: cannot import name 'models' from 'webrtc_models'
cause Attempting to import an internal module or a non-existent symbol directly from the top-level `webrtc_models` package.fixImport specific model classes directly from the `webrtc_models` package (e.g., `from webrtc_models import PacketLossPredictor`). Do not try to import submodules like `webrtc_models.models`.
Warnings
- breaking The `predict` method for all models (e.g., `PacketLossPredictor`, `BandwidthPredictor`, `QoEPredictor`) changed its signature in version 0.3.0.
- gotcha Models expect specific feature keys in the input dictionary passed to the `predict` method. Missing or misspelled keys will raise a `KeyError`.
- gotcha The `webrtc-models` library explicitly requires Python 3.12 or newer.
Install
-
pip install webrtc-models
Imports
- PacketLossPredictor
from webrtc_models import PacketLossPredictor
- BandwidthPredictor
from webrtc_models import BandwidthPredictor
- QoEPredictor
from webrtc_models import QoEPredictor
Quickstart
from webrtc_models import PacketLossPredictor
# Initialize the predictor model
predictor = PacketLossPredictor()
# Prepare features as a dictionary
# (Note: Specific keys are required by each model)
features = {
'inbound_rtp_packets_lost': 0,
'inbound_rtp_packets_received': 100
}
# Make a prediction
prediction = predictor.predict(features)
print(f"Predicted packet loss: {prediction}")