Thank you for your interest in contributing! This guide covers how to get started.
git clone https://github.com/collabora/gst-python-ml.git
cd gst-python-ml
python3 -m venv --system-site-packages .venv
source .venv/bin/activate
pip install -e ".[all]"
pip install ruff black pytestWe use ruff for linting and black for formatting:
ruff check plugins/ tests/ utils/
black plugins/ tests/ utils/CI enforces these on every PR.
All GStreamer Python elements live in plugins/python/. To add a new element:
- Create
plugins/python/my_element.py - Import the appropriate base class (see table below)
- Define your class with
__gstmetadata__and__gstelementfactory__ - Register with
GObject.type_register()
| Base Class | Module | Use Case |
|---|---|---|
BaseTransform |
base_transform |
Generic video transforms |
BaseObjectDetector |
base_objectdetector |
Object detection |
BaseClassifier |
base_classifier |
Image classification |
BaseCaption |
base_caption |
Video/image captioning |
BaseLLM |
base_llm |
Large language models |
BaseTranscribe |
base_transcribe |
Speech-to-text |
BaseTranslate |
base_translate |
Text translation |
BaseTTS |
base_tts |
Text-to-speech |
BaseSeparate |
base_separate |
Audio source separation |
CAN_REGISTER_ELEMENT = True
try:
import gi
gi.require_version("Gst", "1.0")
gi.require_version("GstBase", "1.0")
gi.require_version("GObject", "2.0")
from gi.repository import GObject, Gst, GstBase
from base_transform import BaseTransform
except ImportError as e:
CAN_REGISTER_ELEMENT = False
print(f"my_element not available: {e}")
if CAN_REGISTER_ELEMENT:
class MyElement(BaseTransform):
__gstmetadata__ = (
"My Element",
"Video/Filter",
"Description of what it does",
"Your Name <email@example.com>",
)
GObject.type_register(MyElement)
__gstelementfactory__ = ("my_element", Gst.Rank.NONE, MyElement)Engine implementations live in plugins/python/engine/. To add a new engine:
- Create
plugins/python/engine/myengine_engine.py - Inherit from
MLEngine(inplugins/python/engine/ml_engine.py) - Implement the required methods:
load_model(),predict(),get_input_shape() - Register in
plugins/python/engine/engine_factory.py
Run tests with:
export GST_PLUGIN_PATH=$PWD/plugins
pytest tests/For pipeline testing:
gst-inspect-1.0 python # Verify all elements load
gst-launch-1.0 filesrc location=data/people.mp4 num-buffers=5 \
! decodebin ! videoconvert ! videoscale \
! "video/x-raw,format=RGB,width=640,height=640" \
! pyml_objectdetector engine-name=onnx model-name=yolo11n.onnx device=cpu \
input-format=nchw post-process=anchor_free \
! fakesink- Ensure
ruff checkandblack --checkpass - Add yourself to the element's
__gstmetadata__author field - Test with at least one engine (PyTorch or ONNX recommended for CI)
- Keep the
try/except ImportErrorpattern so elements degrade gracefully when optional dependencies are missing
This project is licensed under LGPL-2.0-or-later. By contributing, you agree that your contributions will be licensed under the same terms.