# Create virtual environment
python3.11 -m venv venv
source venv/bin/activate
# Install Requirements
pip install --upgrade pip setuptools wheel
pip install -e '.[dev]'
# Setup pre-commit hooks
pre-commit install
Alternatively, using uv (recommended):
# Pin Python version
uv python pin 3.11
uv pip install -e '.[dev]'
Tests that use PySpark (e.g., test_test_kafka.py, test_test_delta.py, test_test_dataframe.py, test_import_spark.py) require Java 21. Set JAVA_HOME to a Java 21 installation before running these tests.
# Using SDKMAN
source ~/.sdkman/bin/sdkman-init.sh
sdk use java 21-open
# Or set JAVA_HOME directly
export JAVA_HOME=$(/usr/libexec/java_home -v 21)
# Run all tests
pytest
# Run tests in parallel
pytest -n 8
# Run a specific test file
pytest tests/test_specific.py
# Run a specific test function
pytest tests/test_specific.py::test_function_name
# Check code with ruff
ruff check .
# Fix linting issues automatically
ruff check --fix .
# Format code
ruff format .
# Run all pre-commit hooks
pre-commit run --all-files
# Initialize a new data contract
datacontract init
# Lint a data contract file
datacontract lint datacontract.yaml
# Test a data contract against actual data
datacontract test datacontract.yaml
# Export a data contract to a different format
datacontract export html datacontract.yaml --output datacontract.html
# Import from a different format
datacontract import sql --source my-ddl.sql --dialect postgres --output datacontract.yaml
# Show a changelog between two data contracts
datacontract changelog datacontract-v1.yaml datacontract-v2.yaml
# Regenerate the command help sections in README.md
python update_help.py
# Update the bundled Data Contract Editor (datacontract/editor_assets/, used by `datacontract edit`)
# to a specific version of the datacontract-editor npm package (latest if omitted)
python update_editor_assets.py 0.1.10
# Validate every example data contract under examples/ (also runs in CI)
python lint_examples.py
# Regenerate the command + output examples on the docs export/import pages
# (runs the CLI against examples/ and updates the AUTOGENERATED blocks)
python update_export_examples.py
python update_import_examples.py
The Data Contract CLI is an open-source command-line tool for working with data contracts:
CLI Interface (datacontract/cli.py): Entry point for the command-line interface using Typer.
Data Contract Core (datacontract/data_contract.py): Central class for working with data contracts, handling operations like testing, validation, and export/import.
datacontract/engines/: Contains implementations for testing against various data sourcesdatacontract/export/: Converters for formats like Avro, SQL, dbt, HTML, etc.datacontract/imports/: Importers from formats like SQL, Avro, JSON Schema, etc.Linting (datacontract/lint/): Tools for validating data contract files against schema and best practices.
datacontract/changelog/): Semantic comparison of ODCS data contracts.The project uses factory patterns for extensibility:
exporter_factory and importer_factory allow registering custom exporters/importerstests/ directorytests/fixtures/ which provide sample data contracts and test dataCHANGELOG.md entries should be one line each: what changed (user-facing), not how or why. Append the fixed issue, if exists, as (#NNN). No details on mechanism, rationale, or edge cases.