Write healthcare data contracts, validate their structure, and check CSV or Parquet datasets against them.
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
.parquetor.csvfile 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.
The project includes a static browser application designed for GitHub Pages:
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.
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.
clinical-contract currently focuses on three practical layers:
-
Contract structure Required metadata, description fields, schema definitions, columns, and quality rules are validated before checking data.
-
Schema compatibility Required columns must exist and detected DuckDB types must match the contract logical or physical types.
-
Quality rules SQL checks are executed against the loaded CSV/Parquet tables and reported as passed or failed. Rules may join several contract tables.
The same engine is available as a Python package on PyPI.
Python 3.11 or newer is required.
pip install clinical-contractValidate a contract:
clinical-contract validate site/examples/clinical-template.yamlCheck a data file:
clinical-contract check site/examples/clinical-template.yaml site/examples/clinical_template.parquetFor 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.csvDisplay 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})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.
- Only CSV and Parquet data files are currently supported.
- Type validation is limited to the logical and physical types listed in the supported type catalog. Unsupported types are rejected during contract validation.
- CSV column types are inferred and are therefore less reliable than the explicit types stored in Parquet files.
- The web application runs entirely in the browser and does not upload contracts or datasets. Its performance and maximum practical file size therefore depend on the memory and processing resources available on the user's machine.
See planned improvements and open issues.
Clone the repository:
git clone https://github.com/artheioupfat/clinical-contract.git
cd clinical-contractInstall Python dependencies:
uv sync --extra devRun Python tests:
uv run pytest -vInstall web dependencies:
npm ciRun site tests:
npm run test:siteBuild the site CSS:
npm run build:site:cssServe the static site locally:
python3 -m http.server 8000 --directory siteThen open http://127.0.0.1:8000.
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
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.
MIT — see LICENSE for details.
Arthur PRIGENT — GitHub
