RPi Camera Ensemble
Central orchestration of synchronized video acquisition across multiple Raspberry Pi cameras.
Runs a Conductor on the acquisition machine that controls one or more Agents: each Agent is a FastAPI server running on an individual Raspberry Pi, managing local camera acquisition and GPIO-based TTL synchronization.
Features
- Multi-camera orchestration: start/stop all cameras with a single call; UUID-guarded sessions prevent accidental stops
- TTL synchronization: per-frame GPIO pulses (emitter) and edge-detection timestamps (receiver) via
lgpio(RPi 4 + RPi 5) or legacypigpio - PiCamera2 backend: uses the modern
libcamerastack; preview and recording states - REST API on each agent under
/api/v1:GET /agent/status,GET /agent/info(version, API schema version, instance name, capabilities),POST /agent/acquisition/init,/preview,/record,/stop; a failed command answers 409 (wrong state or UUID), 422 (invalid config), 503 (camera or process failure) or 507 (storage) with{"success": false, "error": ...} - Heartbeat monitoring: one background health check per agent, started by
setup_agents(), with configurable interval - Disk space check: pre-acquisition guard based on estimated bitrate and free space
- CLI:
rce-agent run/configentrypoints for systemd or docker-compose deployment
Architecture
Conductor (acquisition machine)
│ HTTP via aiohttp
├── AgentClient → Agent (RPi cam01) → Acquisition → PiCamera2
├── AgentClient → Agent (RPi cam02) → Acquisition → PiCamera2
└── AgentClient → Agent (RPi cam03) → Acquisition → PiCamera2
│
TTL out pin (lgpio)
TTL in pin (lgpio)
Requirements
- Python ≥ 3.11
- On each Raspberry Pi:
picamera2(system package),lgpio(pip install lgpio),gpiod(system package, diagnostic tools) - On the acquisition machine (Conductor):
aiohttp
Installation
# Acquisition machine (Conductor only)
pip install "rpi-camera-ensemble[conductor]"
# On each Raspberry Pi (Agent + TTL sync)
pip install "rpi-camera-ensemble[agent,lgpio]"
Install from source:
git clone https://github.com/MurineShiftWork/rpi-camera-ensemble.git
cd rpi-camera-ensemble
pip install -e ".[agent,lgpio,dev]"
Quick start
Agent (on each Raspberry Pi)
Create a config file (agent.yaml):
instance_name: cam01
api_host: 0.0.0.0
api_port: 8876
data_dir: /data/recordings
log_dir: /data/logs
Start the agent:
rce-agent run --config agent.yaml
Generate a template config:
rce-agent config --to-template agent.template.yaml
Conductor (on the acquisition machine)
from rpi_camera_ensemble.conductor.conductor import Conductor
from rpi_camera_ensemble.config.acquisition import EnsembleAcquisitionConfig
from rpi_camera_ensemble.config.conductor import ConductorConfig
ensemble_cfg = EnsembleAcquisitionConfig.from_yaml("ensemble.yaml")
conductor_cfg = ConductorConfig(log_dir="/data/logs/conductor")
with Conductor(config=conductor_cfg, ensemble_config=ensemble_cfg) as conductor:
conductor.setup_agents()
conductor.initialize_acquisition(
acquisition_path="recordings/experiment_001", # under each agent's data_dir
acquisition_name="experiment_001",
)
conductor.start_preview()
conductor.start_recording()
# ... recording ...
conductor.stop_acquisition()
Ensemble config (ensemble.yaml). api_url is the agent's address; the client adds
the /api/v1 prefix (http://host:port/api/v1 and the older http://host:port//api/v1
also work):
schema_version: 1
agents:
cam01:
api_url: http://cam01.local:8876
camera_config: {}
cam02:
api_url: http://cam02.local:8876
camera_config: {}
msw camera backend
pip install "rpi-camera-ensemble[msw]" registers RceBackend as the rce backend
of the msw.camera entry point group (contract from msw-plugin-api). It drives
one ensemble as one camera group.
- Settings:
config, the ensemble YAML (required),data_dir, where the conductor saves each acquisition's ensemble and conductor YAML (optional), andtoken, the agent API token (optional, else the ensembleapi_token, elseRCE_API_TOKEN). Any other key is a configuration error. - Each unit is one agent, matched by
camera_config.description; a unit'shw_id, if given, must be that agent's host. Agents not named by a unit are never contacted. Without units, every agent is used, named by its description. preflightsets up the agents and reads their status: an agent that does not answer ismissingand is left out of the session. An agent that still holds an acquisition (agent_statenotidle, e.g. left recording by a killed host process) isfailedwithagent_busy(agent_failedfor a dead acquisition process), naming that acquisition's name, UUID and start; preflight does not end it.resetends whatever acquisition each agent holds (Conductor.reset, files saved) and reports each cameraready, orfailedif its agent could not reset. msw runs it asmsw cameras reset --setup <setup>.startandstoprun the conductor commands withraise_on_failure=Falseand report each agent'sAgentResultas that camera'sUnitResult. A camera that fails one step keeps that failure (withstepand the agent'serror_code) while the others record.stopsends one stop and returns the same results on later calls.- The videos stay on the Pis:
filesis empty andextranames the host and the acquisition path and UUID under the agent's data root.
API token
The agent requires a bearer token on every command and on /agent/logs and
/agent/config when one is configured: api_token in agent.yaml, or the
RCE_API_TOKEN environment variable (for example from a root-only environment file
of the service). /agent/status and /agent/info stay open. An agent without a
token accepts every request and logs a warning at start.
The conductor sends the token from api_token in the ensemble YAML or from
RCE_API_TOKEN; it is never written to the saved session YAML. setup_agents
leaves out an agent that refuses the token (error_code unauthorized).
curl -H "Authorization: Bearer $RCE_API_TOKEN" http://cam01.local:8876/api/v1/agent/config
TTL synchronization
The GPIO facts of each Pi (TTL library, GPIO chip, pins, sensor mode) live in its agent
config under hardware, rendered by the deploy (defaults in
deploy/roles/rce_defaults/defaults/main.yaml, set per rig or host in the inventory). The agent finds the header GPIO chip by label when it starts (pinctrl-rp1 on a
Pi 5, pinctrl-bcm2711 / pinctrl-bcm2835 on earlier models), because its number depends on
the kernel. camera_config.ttl in ensemble.yaml leaves these fields at agent and
overrides one only when it sets it. Pins are BCM GPIO numbers (0 to 27):
agents:
cam01:
api_url: http://192.0.2.10:8876
camera_config:
ttl:
out_duration_us: 1000
# optional overrides of the agent's hardware settings:
# library: lgpio
# gpiochip: pinctrl-rp1 # a label, or a number for /dev/gpiochipN
# out_pin: 25 # emits a pulse on each encoded frame; null disables
# in_pin: 23 # records edges from an external trigger; null disables
lgpio uses the GPIO character device directly (no libgpiod needed):
pip install lgpio
RPi 5 note: leave
gpiochipto the agent; RP1 is gpiochip4 on early Pi 5 kernels and gpiochip0 on current ones.gpiodetecton the Pi lists the chips.
Output structure
Each agent writes files named {basename}.rce.{instance}.{timestamp}.{type}.{ext}:
/data/recordings/experiment_001/
├── session.rce.cam01.20260101_120000_000000.video.h264
├── session.rce.cam01.20260101_120000_000000.ttl_out.npz
├── session.rce.cam01.20260101_120000_000000.ttl_in.npz
├── session.rce.cam02.20260101_120000_000000.video.h264
├── session.rce.cam02.20260101_120000_000000.ttl_out.npz
└── session.rce.cam02.20260101_120000_000000.ttl_in.npz
Load and validate a session from the acquisition machine:
from rpi_camera_ensemble.io import RCESession, validate_session
session = RCESession.from_directory("/data/recordings/experiment_001/")
qc = validate_session(session)
qc.print_report()
Deployment
See deploy/ for Ansible playbooks to provision Raspberry Pis (apt packages, Python venv, systemd service).
Development
uv sync --extra dev
uv run pre-commit install
uv run pytest
License
BSD-3-Clause-NonCommercial: free to use, modify and redistribute for non-commercial research, academic and educational purposes under the BSD 3-clause conditions. Commercial use, including sale, paid licensing or paid services built on it, needs a separate commercial licence. Copyright (c) 2025-present Lars B. Rollik. Full terms in LICENSE.
Metadata
Release files for rpi-camera-ensemble 0.27.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rpi_camera_ensemble-0.27.2.tar.gz | 191.0 kB | Without provenance | Details for rpi_camera_ensemble-0.27.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rpi_camera_ensemble-0.27.2-py3-none-any.whl | Python 3 | none | any | Details for rpi_camera_ensemble-0.27.2-py3-none-any.whl |
Total release size: 324.5 kB
Release files / rpi_camera_ensemble-0.27.2.tar.gz
| Download URL | rpi_camera_ensemble-0.27.2.tar.gz |
|---|---|
| Size | 191.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6cfdd5fb828bb1a8e7ad8165f6b0557e2f318ebf663ee091f4bd0f1ad066e4e8
|
|
BLAKE2b-256 checksum How to use checksums |
45f582e07c54fd377322c166dfd999d6366b239904855df417809f1397603b5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.11 {"installer":{"name":"uv","version":"0.13.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / rpi_camera_ensemble-0.27.2-py3-none-any.whl
| Download URL | rpi_camera_ensemble-0.27.2-py3-none-any.whl |
|---|---|
| Size | 133.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0a1e97d3945190faefc24e7831691c87a0c9899420b93d05bd53cd4417d9d4d0
|
|
BLAKE2b-256 checksum How to use checksums |
8a835e78b800cb78fc1d857853578b31b2cdf756438c021cd1a9af65f6efc80a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.11 {"installer":{"name":"uv","version":"0.13.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for rpi-camera-ensemble 0.27.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.