Metadata-Version: 2.4
Name: sme-core
Version: 1.4.1
Summary: Sequence Method Engine — core validators, regression diff_report, and ingestion-pipeline base classes. Consumed by Scriptura SaaS and any other SME wrapper.
Author: Scriptura Health
License: UNLICENSED
Project-URL: Homepage, https://scripturahealth.com/sme
Project-URL: Repository, https://github.com/scripturahealth/sequence-method-engine
Project-URL: Issues, https://github.com/scripturahealth/sequence-method-engine/issues
Keywords: scriptura,sequence-method-engine,clinical-decision-support,json-schema,regulatory,compounding,peptide,trt,glp1
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Healthcare Industry
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: jsonschema>=4.21
Requires-Dist: referencing>=0.35
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: twine>=5.0; extra == "dev"

# sme-core

> Sequence Method Engine — core validators, regression diff_report, and ingestion-pipeline base classes.

`sme-core` is the Python runtime library for the Sequence Method Engine (SME). It packages canonical JSON schemas, schema validation, the §7.2.6 regression diff_report, and the abstract ingestion pipeline base used by P1 (PubMed), P2 (FDA), P3 (DEA), P4 (503A bulks), and future wrapper-defined pipelines.

Companion package: [`@scripturahealth/sme-schemas`](../sme-schemas) ships the same schemas as TypeScript types for the Scriptura SaaS frontend.

## Install

```bash
pip install sme-core
```

Requires Python ≥ 3.10.

## Usage

### Validate a document

```python
from sme_core import SchemaValidator

v = SchemaValidator()
errors = v.validate(my_compound_dict, schema_name="compound")
if errors:
    for e in errors:
        print(".".join(str(p) for p in e.absolute_path), "→", e.message)
```

### Regression diff_report

```python
from sme_core import generate_diff_report

report = generate_diff_report(
    baseline_protocol_json=old,
    new_protocol_json=new,
    baseline_id="2025-12-14-sabrina-v2.3",
    baseline_generated_at="2025-12-14T18:32:00Z",
)
print(report.drift_verdict)              # no_clinical_drift | clinical_drift_detected
print(report.requires_eric_approval_before_ship)
```

### Build an ingestion pipeline

```python
from sme_core import IngestionPipeline, RegulatoryRecord, ReviewQueueItem

class PubMedPipeline(IngestionPipeline):
    name = "p1_pubmed"

    def fetch(self, since):
        # call PubMed E-utilities, return raw items
        ...

    def transform(self, raw_items):
        records = [...]       # list[RegulatoryRecord]
        review_items = [...]  # list[ReviewQueueItem]
        return records, review_items

p = PubMedPipeline(
    cursor_loader=lambda: db.get_cursor("p1_pubmed"),
    cursor_saver=lambda v: db.set_cursor("p1_pubmed", v),
    record_sink=db.append_regulatory_records,
    review_queue_sink=webhook_to_wrapper,
)
result = p.run()
```

## CLI tools

```bash
sme-validate path/to/doc.json --schema compound
sme-diff-report baseline.json new.json
```

`sme-diff-report` exits 1 when clinical drift is detected — designed for CI gating.

## Versioning

The package version tracks the SME schema_version. Tagging the repo `v1.1.0` publishes both `sme-core==1.1.0` and `@scripturahealth/sme-schemas@1.1.0`.

## License

UNLICENSED — internal Scriptura Health distribution.
