Metadata-Version: 2.4
Name: civex-plugin-sdk
Version: 0.2.0
Summary: SDK for authoring out-of-process Civex workflow plugins (subprocess/container tiers)
Author-email: James Sullivan <sullivanj041@gmail.com>
License: MIT License
        
        Copyright (c) 2026 James Sullivan
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Documentation, https://civexdata.github.io/civex-docs/extending/sdk-reference.html
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.0
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Provides-Extra: table
Requires-Dist: pandas>=2.0; extra == "table"
Dynamic: license-file

# civex-plugin-sdk

SDK for authoring out-of-process [civex](https://civexdata.github.io/civex-docs/) workflow plugins — subprocess-tier (`uv run --script`) and container-tier plugins that run as an isolated OS process/container and talk to the host over an RPC wire protocol, rather than importing into civex's own process.

Subclass `Plugin`, declare its metadata, implement `invoke()`, and call `serve()`:

```python
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.10"
# dependencies = ["civex-plugin-sdk"]
# ///
from pydantic import BaseModel
from civex_plugin_sdk import Ctx, Plugin as PluginBase, serve


class Plugin(PluginBase):
    id = "my_project.compute_duration"   # must be unique; use a namespace prefix
    name = "Compute Duration"
    category = "transforms"              # informational only
    capabilities = ["get_context_record"]  # every ctx.* method this plugin calls

    class Config(BaseModel):
        start_field: str
        end_field: str

    def invoke(self, inputs: dict, config: Config, ctx: Ctx) -> dict:
        record = ctx.get_context_record()
        start = record["data"].get(config.start_field, 0)
        end = record["data"].get(config.end_field, 0)
        return {"duration": end - start}


if __name__ == "__main__":
    serve(Plugin)
```

Drop the file in `_civex/plugins/` in a civex project and it's discovered automatically. See [Writing a plugin](https://civexdata.github.io/civex-docs/extending/writing-a-plugin.html) for the full authoring guide (the `Ctx` API, isolation/timeouts, constraints), [Container plugins](https://civexdata.github.io/civex-docs/extending/container-plugins.html) for the Tier 2 path, and the [SDK reference](https://civexdata.github.io/civex-docs/extending/sdk-reference.html) for the complete public API.

## Installing

```bash
pip install civex-plugin-sdk          # or: uv add civex-plugin-sdk
pip install "civex-plugin-sdk[table]" # adds pandas for `table`-typed inputs/outputs
```

In a plugin script the PEP 723 header is all you need — `uv run` resolves it. When civex runs the plugin it pins the SDK to the version civex itself uses, so you don't pin it yourself.

## Versioning

The SDK's version comes from `sdk-vX.Y.Z` git tags (setuptools-scm) — there is no version written in `pyproject.toml`. civex's own `vX.Y.Z` tags are a separate namespace. A build between tags is `X.Y.Z.postN`; only a tagged commit produces a plain release version. `requires-python` is `>=3.10`, looser than civex's own `>=3.12`, since plugins run in their own subprocess/container environment independent of the host's interpreter.

The wire protocol has its own number, `civex_plugin_sdk.PROTOCOL_VERSION`, which changes only for breaking wire changes; civex refuses a plugin whose protocol it doesn't speak. Release notes are in `CHANGELOG.md` in the source distribution.

## License

MIT — the full text ships in the package as `LICENSE`. (The `civex` application itself is under a different license.)
