Skip to main content

Apache Airflow provider for the Data Contract CLI: run data contract tests as quality gates in your DAGs

Project description

Data Contract Provider for Apache Airflow

Run Data Contract CLI tests as quality gates in your Airflow DAGs.

CI

Features

  • DataContractTestOperator runs datacontract test against a contract and fails the task when the contract is violated, so bad data stops before it propagates downstream.
  • Per-check results are rendered in the task log (pass/fail, reason, model/field).
  • Structured results are pushed to XCom (key datacontract_result), so downstream tasks can branch on the outcome.
  • On Airflow 3, a "Data Contract Results" view in the UI shows recent test runs across all DAGs.
  • A "Test Results" button on the task instance links to the published results, e.g. in Entropy Data.

Installation

pip install airflow-provider-datacontract

Extras are passed through to the Data Contract CLI, e.g. for Snowflake:

pip install "airflow-provider-datacontract[snowflake]"

Available extras: duckdb (local files, csv/parquet), snowflake, databricks, bigquery, postgres, s3, azure, kafka, trino.

Usage

from datetime import datetime
from airflow.sdk import dag
from datacontract_provider.operators.datacontract import DataContractTestOperator


@dag(schedule="0 2 * * *", start_date=datetime(2026, 1, 1), catchup=False)
def nightly_datacontract_test():
    DataContractTestOperator(
        task_id="test_orders_contract",
        data_contract_file="https://demo.datacontract.com/orders-latest/datacontract.yaml",
        server="production",
    )


nightly_datacontract_test()

Operator parameters

Parameter Description
data_contract_file Path or URL of the data contract YAML (templated)
data_contract_str Contract as a YAML string, alternative to data_contract_file
server Server key from the contract's servers section to test against
schema_name Schema/model to test, defaults to all
check_categories Subset of schema, quality, servicelevel, custom
server_conn_id Airflow connection with credentials for the server under test (see below)
entropy_data_conn_id Airflow connection for Entropy Data (password = API key, host optional)
config Dict of additional Data Contract CLI configuration fields
publish_url URL to publish test results to (optional)
results_web_url Web page of the published results, shown as a "Test Results" button (optional)
include_failed_samples Collect samples of failing rows
fail_on_warning Also fail the task on result warning
datacontract_kwargs Extra kwargs for the DataContract constructor, e.g. spark

Credentials via Airflow connections (recommended)

Pass server_conn_id to resolve credentials through Airflow's connection machinery, including any configured secrets backend (Vault, AWS Secrets Manager, Azure Key Vault, ...). The connection is mapped to Data Contract CLI configuration based on its type and passed programmatically; credentials never touch the process environment.

DataContractTestOperator(
    task_id="test_orders_contract",
    data_contract_file="...",
    server="production",
    server_conn_id="databricks_prod",       # conn type: databricks
    entropy_data_conn_id="entropy_data",    # password = API key
    publish_url="https://api.entropy-data.com/api/test-results",
)

Supported connection types: databricks (host, password=token, extra http_path), snowflake (login/password, extra account, warehouse, role), postgres, mysql, oracle, impala, trino, mssql, redshift (login/password/host/port/schema), aws (login/password=key pair, extra region_name), google_cloud_platform (extra key_path, project), wasb/azure, and kafka. For anything else, add datacontract_-prefixed keys to the connection extra (e.g. datacontract_trino_jwt_token); those pass through to any config field and also override the mapped values. The config parameter is merged last.

Requires datacontract-cli >= 1.0. Alternatively, the CLI still reads credentials from environment variables, e.g. DATACONTRACT_SNOWFLAKE_USERNAME, set on the worker.

XCom

The operator pushes two XCom entries:

  • datacontract_result: {result, data_contract_file, server, checks_total, checks_failed, checks: [{name, result, category, type, model, field, reason}]}
  • datacontract_results_url: the results_web_url, if configured

Results view in the Airflow UI (Airflow 3)

The provider ships a plugin that adds a Data Contract Results entry to the navigation, rendering the most recent test runs across all DAGs with expandable check details. It is served under /datacontract/results by the API server and reads the results from XCom. On Airflow 2 the plugin degrades gracefully and only registers the extra link.

Entropy Data (optional)

To publish test results to Entropy Data (formerly Data Mesh Manager), set the ENTROPY_DATA_API_KEY environment variable on the worker and configure:

DataContractTestOperator(
    task_id="test_orders_contract",
    data_contract_file="...",
    server="production",
    publish_url="https://api.entropy-data.com/api/test-results",
    results_web_url="https://app.entropy-data.com/...",  # optional deep link
)

Version support

  • Apache Airflow 2.10+ and 3.x (the UI results view requires Airflow 3)
  • Python 3.10+

Development

pip install -e ".[dev]"
ruff check src tests
pytest

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

airflow_provider_datacontract-0.2.1.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

airflow_provider_datacontract-0.2.1-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file airflow_provider_datacontract-0.2.1.tar.gz.

File metadata

File hashes

Hashes for airflow_provider_datacontract-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d1135fb474308ab2a21b3bf6429e2283ade79d7157c251669ce7ee1791cf4c36
MD5 459ae425862cffffb050f039970a5194
BLAKE2b-256 bbb2de1d2bbb77571033f23d2fa40bcfedc1cdfe7ba29cc27d575d404a398621

See more details on using hashes here.

Provenance

The following attestation bundles were made for airflow_provider_datacontract-0.2.1.tar.gz:

Publisher: release.yml on datacontract/airflow-provider-datacontract

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file airflow_provider_datacontract-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for airflow_provider_datacontract-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a7f1135b38bd48ef35263e0e28dde582f3872e0b978ca91ac67544b547f4863a
MD5 f4d3736326fffdaea28878fabc4fcdfe
BLAKE2b-256 297186e8d4e380b544baff6c505b2e8fbcb715c82251e86e42ead17dacd11952

See more details on using hashes here.

Provenance

The following attestation bundles were made for airflow_provider_datacontract-0.2.1-py3-none-any.whl:

Publisher: release.yml on datacontract/airflow-provider-datacontract

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page