Metadata-Version: 2.4
Name: vcti-ywf-template
Version: 3.0.1
Summary: Template discovery, repository, and run-state management for the vcti-ywf workflow engine.
Author: Visual Collaboration Technologies Inc.
License-Expression: LicenseRef-Proprietary
Project-URL: Repository, https://github.com/vcollab/vcti-python-ywf-template
Project-URL: Changelog, https://github.com/vcollab/vcti-python-ywf-template/blob/main/CHANGELOG.md
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: <3.15,>=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.0
Requires-Dist: vcti-ywf<7,>=6.1.0
Requires-Dist: vcti-archive>=1.0.2
Requires-Dist: vcti-git[pygit2]<3,>=2.0.0
Requires-Dist: vcti-path>=1.2.0
Requires-Dist: vcti-path-tree<3,>=2.0.0
Requires-Dist: vcti-short-uid<3,>=2.0.0
Provides-Extra: fastapi
Requires-Dist: fastapi>=0.100; extra == "fastapi"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Requires-Dist: fastapi>=0.100; extra == "test"
Provides-Extra: lint
Requires-Dist: ruff; extra == "lint"
Provides-Extra: typecheck
Requires-Dist: mypy; extra == "typecheck"
Dynamic: license-file

# vcti-ywf-template

Template discovery, repository, and run-state management for the vcti-ywf workflow engine.

## Overview

`vcti-ywf-template` is the template-management layer on top of the
[`vcti-ywf`](https://pypi.org/project/vcti-ywf/) YAML workflow engine. The
engine loads and executes one workflow directory; this package manages a
*directory of templates* around it: listing them as a catalog, reading and
changing the files inside a template, and recording the state of each run.
A **template** is a directory holding a workflow under `source/` and its
per-run state under `runs/`; a **repository** is a directory of templates,
optionally cloned from a Git remote.

Install it when you are building a host application — a REST service, a
desktop GUI, an editor extension — that lets users browse, upload or run
workflow templates. To execute a known workflow headless, `vcti-ywf` alone
is enough.

## Installation

```bash
pip install vcti-ywf-template
```

### In `requirements.txt`

```
vcti-ywf-template>=3.0.1
```

### In `pyproject.toml` dependencies

```toml
dependencies = [
    "vcti-ywf-template>=3.0.1",
]
```

---

## Quick Start

A template is a directory with a root workflow node named by
`source/.entrypoint`. Write the smallest valid one, then open the directory
that holds it as a repository:

```python
from pathlib import Path

from vcti.ywf.template import TemplatesRepository, get_template_catalog

node = Path("templates/modal-analysis/source/main")
node.mkdir(parents=True)
(node.parent / ".entrypoint").write_text("main", encoding="utf-8")
(node / "about.yaml").write_text("title: Modal Analysis\n", encoding="utf-8")

# Point at an existing directory of templates, or pass remote_repo_url=
# to clone one on first use.
repo = TemplatesRepository(Path("templates"))

catalog = get_template_catalog(repo)
for manifest in catalog.root:
    title = manifest.metadata.title if manifest.metadata else "(no metadata)"
    print(manifest.id, "—", title)
```

Open a single template to reach its workflow nodes, files and runs:

```python
template = repo.get_template("modal-analysis")
print(template.workflow_nodes.root_node)        # main

# Files are addressed by POSIX-style IDs relative to the template root.
print(template.files.resolve_path("source/main/about.yaml", must_be_file=True))
```

The package records the state of a run; launching the runner is the host
application's job:

```python
from vcti.ywf.template import RunState, RunStatusManager

run_id = template.runs.create_run()
template.runs.set_active_run(run_id)

status = RunStatusManager(template.runs.get_run_path(run_id))
status.update(state=RunState.RUNNING, pid=12345)
status.update(state=RunState.COMPLETED, pid=None)   # None clears the PID

print(template.runs.get_run_status(run_id).state)   # completed
```

Uploads are binary streams and downloads are descriptions, so the
package needs no web framework:

```python
import io

template.files.upload("notes.txt", io.BytesIO(b"hello"))

download = template.download()                 # the template as a .vyf archive
print(download.filename)                       # modal-analysis.vyf
archive_bytes = b"".join(download.chunks)      # runs/ is left out by default
```

With FastAPI, install the `fastapi` extra
(`pip install vcti-ywf-template[fastapi]`) and use the adapter module
`vcti.ywf.template.fastapi` to convert `UploadFile` and responses to and
from these types. [docs/patterns.md](docs/patterns.md) shows the routes,
along with validating uploads, safe replacement, run tracking, and the
pitfalls worth knowing.

---

## Key API

| Name | What it is |
|------|------------|
| `TemplatesRepository` | A directory of templates: list, get, create from an uploaded ZIP, and clone or pull from a Git remote. |
| `TemplateCatalog`, `get_template_catalog` | The manifests of every valid template in a repository, serialized as a JSON array. |
| `TemplateManifest`, `get_template_manifest` | A template's ID and the metadata of its root workflow node. |
| `Template` | One template directory: `files`, `workflow_nodes` and `runs`, plus download, duplicate, rename and delete. |
| `TemplateFiles` | File operations confined to the template root: resolve, tree, upload, download, rename, duplicate, delete. |
| `WorkflowNodes`, `ValidationProblem` | Read access to the workflow nodes under `source/`: the root node, its metadata and declared variables, and `validate()` for a full check. |
| `TemplateRuns` | The run directories under `runs/` and the active-run pointer. |
| `FileDownload`, `ArchiveDownload` | What the download methods return: a file's path, or the chunks of a ZIP, with the name to send it under. |
| `vcti.ywf.template.fastapi` | Optional adapter: `download_response`, `upload_file`, `create_template_from_upload`. |
| `RunState`, `RunStatus`, `RunStatusManager` | The state of a run and its persistence in `status.json`. |

---

## Dependencies

- [`vcti-ywf`](https://pypi.org/project/vcti-ywf/) 5 — the workflow engine
  (`vcti.ywf.engine`) whose workflow directories this package manages.
- [`vcti-archive`](https://pypi.org/project/vcti-archive/) — ZIP extraction
  for uploads and streaming ZIP downloads.
- [`vcti-git`](https://pypi.org/project/vcti-git/) 2 (with the `pygit2`
  backend) — clone and pull for Git-backed repositories.
- [`vcti-path`](https://pypi.org/project/vcti-path/) — file-ID resolution
  and file-name validation.
- [`vcti-short-uid`](https://pypi.org/project/vcti-short-uid/) — generated
  template and run IDs.
- [`vcti-path-tree`](https://pypi.org/project/vcti-path-tree/) — the
  directory tree of a template's files.
- [`pydantic`](https://pypi.org/project/pydantic/) — the manifest,
  catalog and run-status models.

Optional: [`fastapi`](https://pypi.org/project/fastapi/), installed with
the `fastapi` extra, for the adapter module only.

---

## Documentation

| If you want to… | Read |
|---|---|
| Get started using the package | Quick Start above |
| Build a host application: FastAPI routes, uploads, runs, pitfalls | [docs/patterns.md](docs/patterns.md) |
| Understand the layers, the on-disk layout and the package's boundaries | [docs/design.md](docs/design.md) |
| Navigate and understand the source | [docs/source-guide.md](docs/source-guide.md) |
