Skip to main content

clinical-contract

Write healthcare data contracts, validate their structure, and check CSV or Parquet datasets against them.

PyPI Python License: MIT

clinical-contract is a lightweight tool for teams that need to describe, share, and verify clinical data expectations.

It helps you:

  • write a data contract with a guided web editor or YAML;
  • validate that the contract is correctly composed;
  • check that a real .parquet or .csv file conforms to the expected schema;
  • run expressive SQL quality rules with DuckDB using equality, thresholds, or ranges;
  • use the same logic in the browser, the CLI, and Python pipelines.

clinical-contract web editor demo

Live Web App

The project includes a static browser application designed for GitHub Pages:

Open the web editor

The web app lets users create or load a contract, edit it visually, inspect the generated YAML, validate the contract, upload a CSV/Parquet file, preview the dataset, and run schema/quality checks directly in the browser with PyScript, Pyodide, and DuckDB.

Why It Exists

Clinical data exchanges often fail because the expected dataset is documented in one place while the real delivered file follows another reality.

clinical-contract keeps the expectation and the verification close together:

  • the contract explains what the dataset should contain;
  • the checker verifies what the dataset actually contains;
  • the quality rules make important assumptions executable.

This makes data delivery easier to review, easier to automate, and easier to discuss between data producers and data consumers.

What It Checks

clinical-contract currently focuses on three practical layers:

  1. Contract structure Required metadata, description fields, schema definitions, columns, and quality rules are validated before checking data.

  2. Schema compatibility Required columns must exist and detected DuckDB types must match the contract logical or physical types.

  3. Quality rules SQL checks are executed against the loaded CSV/Parquet tables and reported as passed or failed. Rules may join several contract tables.

Python Package

The same engine is available as a Python package on PyPI.

Python 3.11 or newer is required.

pip install clinical-contract

Validate a contract:

clinical-contract validate site/examples/clinical-template.yaml

Check a data file:

clinical-contract check site/examples/clinical-template.yaml site/examples/clinical_template.parquet

For a multi-table contract, pass one file per table. Each filename stem must match its schema name:

clinical-contract check contract.yaml orders.parquet line_items.csv

Display the installed version with clinical-contract --version.

Use it from Python to validate a contract structure:

from clinical_contract import DataContract, load_raw

raw_contract = load_raw("contract.yaml")
report = DataContract.validate_structure(raw_contract)

print(report.success)

Or check a data file against a contract:

from clinical_contract import load_contract

contract, _ = load_contract("contract.yaml")
report = contract.check("data.parquet")

print(report.success)

Multi-table checks accept a list of named files or an explicit mapping, which is useful for in-memory data:

report = contract.check(["orders.parquet", "line_items.csv"])
report = contract.check({"orders": orders_bytes, "line_items": lines_bytes})

Security Model

Data contracts are treated as untrusted input. Each SQL quality rule must contain exactly one read-only SELECT statement and return one finite numeric value. Commands that modify data, files, extensions, or DuckDB settings are rejected.

Before quality rules run, each selected CSV or Parquet file is loaded into an isolated in-memory DuckDB connection. External file and network access is then disabled, extensions are locked down, and execution resources are limited. The web application performs these checks locally in the browser and does not upload the contract or dataset.

Read-only SQL can still be computationally expensive. Contracts received from an untrusted organization should therefore be reviewed before automated execution on shared production infrastructure.

Local Development

Clone the repository:

git clone https://github.com/artheioupfat/clinical-contract.git
cd clinical-contract

Install Python dependencies:

uv sync --extra dev

Run Python tests:

uv run pytest -v

Install web dependencies:

npm ci

Run site tests:

npm run test:site

Build the site CSS:

npm run build:site:css

Serve the static site locally:

python3 -m http.server 8000 --directory site

Then open http://127.0.0.1:8000.

Project Structure

src/clinical_contract/   Python package and validation engine
site/                    Static web app for GitHub Pages
site/examples/           Bundled contract/dataset example pairs
tests/                   Python test suite
site/tests/              JavaScript site tests

Status

The project is still evolving. The current focus is to keep the Python library, CLI, and browser app aligned around one DuckDB-based validation engine.

License

MIT — see LICENSE for details.

Author

Arthur PRIGENT — GitHub

Metadata

Release files for clinical-contract 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clinical-contract 0.3.0
File Size Uploaded Provenance Actions
clinical_contract-0.3.0.tar.gz 6.4 MB With provenance Details for clinical_contract-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for clinical-contract 0.3.0
File Interpreter ABI Platform Actions
clinical_contract-0.3.0-py3-none-any.whl Python 3 none any Details for clinical_contract-0.3.0-py3-none-any.whl

Total release size: 6.4 MB

Release files / clinical_contract-0.3.0.tar.gz

Download URL clinical_contract-0.3.0.tar.gz
Size 6.4 MB
Tags Source
SHA-256 checksum
How to use checksums
fd6c8cbed1cf5476acff2b3631c9120a2d4c0780e7c4c8250bca93aa1401f32b
BLAKE2b-256 checksum
How to use checksums
8ea8ace21e67bc42e7f2066fa4b7c676c251935e5f052ed0e17ee0e22207b03f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release files / clinical_contract-0.3.0-py3-none-any.whl

Download URL clinical_contract-0.3.0-py3-none-any.whl
Size 25.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc60ed061dd9ac8e6ca68f82ad2e00294de95a0338988544edb824f17ffd5b86
BLAKE2b-256 checksum
How to use checksums
15b873d2e6d18eb976bd1b448d884a2e0b17e3f128fbc112f597d49421e61227
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Security for clinical-contract 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for clinical_contract-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page