Metadata-Version: 2.5
Name: msw-plugin-api
Version: 0.5.0
Summary: Minimal structural interfaces for MSW plugin packages
Project-URL: Homepage, https://github.com/MurineShiftWork/msw-plugin-api
Project-URL: Issue Tracker, https://github.com/MurineShiftWork/msw-plugin-api/issues
Author-email: "Lars B. Rollik" <lars@rollik.me>
License: BSD-3-Clause-NonCommercial
        
        Copyright (c) 2020-present, Lars B. Rollik.
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted for NON-COMMERCIAL research, academic, and
        educational purposes only, provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice,
           this list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its contributors
           may be used to endorse or promote products derived from this software
           without specific prior written permission.
        
        4. Any use of this software or its derivatives for COMMERCIAL purposes -
           including sale, paid licensing, or providing paid services built on it -
           requires a separate commercial licence. Contact lars@rollik.me.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
        LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        POSSIBILITY OF SUCH DAMAGE.
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: Free for non-commercial use
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.11
Provides-Extra: dev
Requires-Dist: commitizen; extra == 'dev'
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: pre-commit; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Description-Content-Type: text/markdown

# msw-plugin-api

Minimal structural interfaces for [MurineShiftWork](https://github.com/MurineShiftWork/murineshiftwork) plugin packages.

Zero dependencies (stdlib `typing` and `dataclasses` only). Provides:

- `HostSessionInfo` — concrete dataclass plugins return after attaching
- `HostSessionInfoProtocol` — `runtime_checkable` Protocol for structural typing
- `HostSessionProtocol` — `runtime_checkable` Protocol for host session plugins

## Usage

```python
from msw_plugin_api import HostSessionInfo, HostSessionProtocol

class MyHostSession:
    def attach(self, **kwargs) -> HostSessionInfo:
        return HostSessionInfo(
            backend="myplugin",
            acquisition_name="subject__20260609_143022__ext",
            subject="subject",
            parent_directory="/data/recordings",
        )

    def start(self) -> None: ...
    def stop(self) -> None: ...
```

Declare the plugin entry point in `pyproject.toml`:

```toml
[project.entry-points."msw.host"]
myplugin = "my_package.session:MyHostSession"
```

## Plugin contract

MSW core checks `isinstance(session, HostSessionProtocol)` at dispatch time.
Plugins may implement the interface structurally (without importing this package)
or depend on `msw-plugin-api` explicitly for IDE support and test conformance checks.

## Camera backends

A camera backend drives one group of cameras of a setup and registers under
the `msw.camera` entry-point group, named as the setup's `backend:` key:

```toml
[project.entry-points."msw.camera"]
flir_bonsai = "msw_flir_bonsai.msw:FlirBonsaiBackend"
```

The host calls `configure(settings, units)` once, then `preflight()`,
`start(target)`, `stop(reason)` and `close()`. Each of `preflight`, `start` and
`stop` returns one `UnitResult` per camera: a backend reports a missing or failed
camera instead of raising, and the host decides whether that aborts the run.
`configure` raises `CameraConfigError` for invalid settings, so a broken setup
fails before any hardware starts. `load_camera_backend(name)` finds and creates
an installed backend.

A backend whose cameras can keep recording after the host dies may also
implement `ResettableCameraBackend`: `reset()` ends any recording left from an
earlier session, saves what it recorded and returns one `UnitResult` per camera.
The host calls it before a new session when the previous session's owner process
is dead. Backends without `reset` remain valid `CameraBackend`s.
