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 file and reported as passed or failed.

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

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)

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, the 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.2.2

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.2.2
File Size Uploaded Provenance Actions
clinical_contract-0.2.2.tar.gz 6.3 MB With provenance Details for clinical_contract-0.2.2.tar.gz

Built distribution (wheel)

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

Total release size: 6.4 MB

Release files / clinical_contract-0.2.2.tar.gz

Download URL clinical_contract-0.2.2.tar.gz
Size 6.3 MB
Tags Source
SHA-256 checksum
How to use checksums
48b3386f035ea2c971e96f14d467821a9594e513b740e35bafd3b55dcf87295e
BLAKE2b-256 checksum
How to use checksums
ca61028728c5058e9cfa87bc3ec569721794dbb911e676a7cb6cac6d9193ee3a
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 4, 2026.

Transparency log

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

Download URL clinical_contract-0.2.2-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d4da59fc5823348d806a3d33e99f008b2ebf091d47ea7cc96602f19c589553c
BLAKE2b-256 checksum
How to use checksums
5f41093e5f01914590ab93a0c96c7586ab156d5b23d9120a37c2ee3457553943
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 4, 2026.

Transparency log

Security for clinical-contract 0.2.2

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.2.2.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 4, 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