Metadata-Version: 2.4
Name: pyconveyor
Version: 1.0.1
Summary: Deterministic YAML pipeline engine for structured LLM extraction
Project-URL: Repository, https://github.com/VictorGambarini/pyconveyor
Project-URL: Documentation, https://pyconveyor.readthedocs.io
Project-URL: Changelog, https://github.com/VictorGambarini/pyconveyor/blob/main/CHANGELOG.md
License: MIT License
        
        Copyright (c) 2026 Victor Gambarini
        
        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.
License-File: LICENSE
Keywords: deterministic,extraction,llm,pipeline,pydantic,structured-output,yaml
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: jinja2>=3.0
Requires-Dist: openai>=1.0
Requires-Dist: pydantic>=2.0
Requires-Dist: python-dotenv>=1.0
Requires-Dist: pyyaml>=6.0
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.25; extra == 'anthropic'
Provides-Extra: dev
Requires-Dist: mypy>=1.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.1; extra == 'dev'
Requires-Dist: types-pyyaml; extra == 'dev'
Requires-Dist: types-tqdm; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
Requires-Dist: mkdocs>=1.6; extra == 'docs'
Provides-Extra: progress
Requires-Dist: tqdm>=4.0; extra == 'progress'
Description-Content-Type: text/markdown

# pyconveyor

**Deterministic YAML pipeline engine for structured LLM extraction.**

[![PyPI](https://img.shields.io/pypi/v/pyconveyor)](https://pypi.org/project/pyconveyor/)
[![Python](https://img.shields.io/pypi/pyversions/pyconveyor)](https://pypi.org/project/pyconveyor/)
[![CI](https://github.com/VictorGambarini/pyconveyor/actions/workflows/ci.yml/badge.svg)](https://github.com/VictorGambarini/pyconveyor/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

pyconveyor lets you build reliable LLM extraction pipelines by declaring them in YAML. It handles prompt rendering, schema validation, self-correcting retries, parallel steps, and controlled-vocabulary normalisation — so your code handles the domain logic, not the plumbing.

```yaml
steps:
  - name: extract
    type: llm
    model: default
    prompt: prompts/extract.j2
    schema: schemas:ArticleSummary
    max_attempts: 3
```

```python
from pyconveyor import PipelineRunner

runner = PipelineRunner("pipeline.yaml")
result = runner.run({"text": open("article.txt").read()})

summary = result.steps["extract"].value  # validated ArticleSummary instance
print(summary.title)
```

---

## Install

```bash
pip install pyconveyor
```

For Anthropic Claude support:

```bash
pip install "pyconveyor[anthropic]"
```

---

## Quickstart

Bootstrap a working project in one command:

```bash
pyconveyor init my_project/
cd my_project/
export OPENAI_API_KEY=sk-...
pyconveyor run pipeline.yaml --input '{"document": "The quick brown fox."}'
```

---

## How it works

You write three files. pyconveyor owns the runner.

```
your_project/
├── pipeline.yaml       # what to do and in what order
├── schemas.py          # what shape the output must have (Pydantic models)
└── prompts/
    └── extract.j2      # what to ask the model (Jinja2 templates)
```

When `runner.run(input_data)` is called:

1. The input dict becomes `ctx` — available in every prompt template and expression
2. Steps execute in declaration order
3. Each step's result is stored and can be referenced by later steps as `{{ steps.name.value }}`
4. A `RunContext` is returned with all results, attempt logs, and timing

---

## Features

### Structured output with automatic retries

Every `llm` step validates the model's response against a Pydantic schema. If validation fails, pyconveyor feeds the error back to the model and retries — up to `max_attempts` times.

```yaml
- name: extract
  type: llm
  model: default
  prompt: prompts/extract.j2
  schema: schemas:ArticleSummary
  max_attempts: 3
  on_error: continue   # "raise" | "continue" | "skip_remaining"
```

### All step types

| Step type | What it does |
|---|---|
| `llm` | Call a model, validate output against a Pydantic schema, retry on failure |
| `transform` | Call a Python function with step outputs as inputs |
| `validate` | Assert a condition; fail or skip remaining steps if it's false |
| `io` | Call a Python function for side effects (DB write, file save) |
| `parallel` | Run multiple sub-pipelines concurrently with `ThreadPoolExecutor` |
| `condition` | Branch to different steps based on a runtime expression |

### Provider support

| Provider | How |
|---|---|
| OpenAI | `provider: openai_compat` |
| Anthropic Claude | `provider: anthropic` + `pip install pyconveyor[anthropic]` |
| Ollama / vLLM / LM Studio | `provider: openai_compat` + `base_url:` override |
| Custom | `@register_provider("name")` decorator |
| Tests | `provider: mock` — no API calls |

### Vocabulary-constrained fields

`VocabField` constrains a Pydantic field to a controlled vocabulary, normalises fuzzy matches, and grows the vocabulary over time.

```python
from pyconveyor.vocab import Vocabulary, VocabField
from pydantic import BaseModel

PlasticVocab = Vocabulary(
    known={"PET", "PE", "PLA", "PP"},
    label="plastic_type",
    growth_policy="human",   # queue novel terms for CLI review
    persist=True,            # save after each run
)

class Record(BaseModel):
    plastic: str = VocabField(vocab=PlasticVocab)
    quantity: int
```

Growth policies: `"auto"` (add immediately), `"human"` (queue for CLI review), `"llm"` (LLM decides), or any callable `fn(VocabSuggestion) -> bool`.

Review pending terms interactively:

```bash
pyconveyor vocab review pipeline.yaml
```

### Batch processing

Process a JSONL file with configurable concurrency:

```bash
pyconveyor batch pipeline.yaml inputs.jsonl --concurrency 4 --output results.jsonl
```

```python
from pyconveyor import BatchRunner

runner = BatchRunner("pipeline.yaml", concurrency=4)
batch = runner.run_all(records)  # list of dicts
print(batch.summary())           # total, succeeded, failed, error_rate
```

### Load-time validation

`PipelineRunner("pipeline.yaml")` validates everything before spending any tokens — all schema imports, model references, expression syntax, and field names. Errors include the YAML line number and "did you mean?" suggestions.

```bash
pyconveyor validate pipeline.yaml
# ✓ pipeline.yaml is valid

# Or on error:
# pipeline.yaml:14: unknown field 'max_attempt' on llm step — did you mean 'max_attempts'?
```

### Hooks and observability

```python
runner.on_llm_call = lambda model, prompt, response: log_to_db(model, prompt, response)
runner.on_run_end  = lambda rctx: metrics.record(rctx.summary())
```

### Response caching

Cache LLM responses during development to avoid burning tokens on repeated runs:

```bash
pyconveyor run pipeline.yaml --input '...' --cache
pyconveyor run pipeline.yaml --input '...' --cache --cache-ttl 3600
```

### DAG visualisation

```bash
pyconveyor visualise pipeline.yaml
# Outputs Mermaid diagram
```

---

## CLI reference

```
pyconveyor init <dir>              Bootstrap a new project
pyconveyor run <pipeline.yaml>     Run a pipeline
pyconveyor validate <pipeline>     Validate without running
pyconveyor batch <pipeline> <jsonl> Batch process a JSONL file
pyconveyor vocab review <pipeline> Review pending vocabulary suggestions
pyconveyor schema                  Emit JSONSchema for editor autocomplete
pyconveyor visualise <pipeline>    Print Mermaid DAG diagram
```

---

## Python API

```python
from pyconveyor import PipelineRunner, BatchRunner

# Single run
runner = PipelineRunner("pipeline.yaml")
result = runner.run({"text": "..."})

result.failed                          # bool
result.steps["extract"].value          # Pydantic model instance
result.steps["extract"].last_attempt   # AttemptLog with timing and token counts
result.summary()                       # RunSummary with aggregates

# Batch
batch_runner = BatchRunner("pipeline.yaml", concurrency=8)
batch = batch_runner.run_all(records)
for record in batch.successes:
    save(record)
```

---

## Versioning policy

The YAML pipeline format (`pipeline.yaml`) is treated as a public API subject to the same semver rules as the Python API. A breaking change to the YAML schema will increment the major version.

---

## Documentation

Full documentation at **[pyconveyor.readthedocs.io](https://pyconveyor.readthedocs.io)**

- [Quickstart](https://pyconveyor.readthedocs.io/en/latest/quickstart/)
- [Step Types](https://pyconveyor.readthedocs.io/en/latest/guides/step-types/)
- [Vocabulary Fields](https://pyconveyor.readthedocs.io/en/latest/guides/vocab/)
- [Batch Processing](https://pyconveyor.readthedocs.io/en/latest/guides/batch/)
- [Response Caching](https://pyconveyor.readthedocs.io/en/latest/guides/caching/)
- [YAML Schema Reference](https://pyconveyor.readthedocs.io/en/latest/reference/schema/)

---

## License

MIT
