{"id":4495,"library":"datacontract-specification","title":"Data Contract Specification (Python Library)","description":"The `datacontract-specification` Python library provides a Pydantic model for the Data Contract Specification. It allows users to define, load, and validate data contracts in a machine-readable YAML format, enabling programmatic interaction with data contract definitions. It's actively developed and frequently updated, mirroring the Data Contract Specification versions. The library serves as the programmatic core for tools like the `Data Contract CLI`.","status":"active","version":"1.2.3","language":"en","source_language":"en","source_url":"https://github.com/datacontract/datacontract-specification-python","tags":["data contracts","specification","pydantic","data governance","schema validation","data quality"],"install":[{"cmd":"pip install datacontract-specification","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Requires Python 3.10 or newer.","package":"python","optional":false},{"reason":"The library is built on Pydantic models for data contract representation.","package":"pydantic","optional":false}],"imports":[{"symbol":"DataContractSpecification","correct":"from datacontract_specification.model import DataContractSpecification"}],"quickstart":{"code":"import os\nfrom datacontract_specification.model import DataContractSpecification\n\n# Create a dummy data contract YAML file for the example\ndummy_contract_content = \"\"\"\ndataContractSpecification: 1.2.0\nid: urn:datacontract:example:orders-latest\ninfo:\n  title: Example Orders Latest\n  version: 1.0.0\n  description: |\n    Successful customer orders example.\n  owner: Example Team\n  status: active\nmodels:\n  orders:\n    type: table\n    fields:\n      order_id:\n        type: string\n        required: true\n        description: Unique identifier for the order.\n      customer_id:\n        type: string\n        description: Identifier for the customer.\n\"\"\"\n\nfile_path = \"example_datacontract.yaml\"\nwith open(file_path, \"w\") as f:\n    f.write(dummy_contract_content)\n\ntry:\n    # Load the data contract from the file\n    data_contract = DataContractSpecification.from_file(file_path)\n\n    print(\"Data Contract Loaded Successfully:\")\n    print(data_contract.to_yaml())\n\n    # Access some properties\n    print(f\"\\nContract Title: {data_contract.info.title}\")\n    print(f\"Contract Version: {data_contract.info.version}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # Clean up the dummy file\n    if os.path.exists(file_path):\n        os.remove(file_path)","lang":"python","description":"This quickstart demonstrates how to load a data contract definition from a YAML file using `DataContractSpecification.from_file()` and then access its properties. It creates a temporary YAML file with a basic contract for demonstration purposes."},"warnings":[{"fix":"Migrate to the Open Data Contract Standard (ODCS). The `datacontract-cli` (the primary consumer of this library) supports ODCS natively. Consider using the `datacontract-cli` for `export --format odcs` functionality if available.","message":"The underlying Data Contract Specification, for which this library provides a Pydantic model, is officially deprecated in favor of the Open Data Contract Standard (ODCS) as of ODCS v3.1. Users are recommended to migrate to ODCS.","severity":"breaking","affected_versions":"All versions of the library, as it reflects the state of the specification."},{"fix":"Install `datacontract-cli` (`pip install datacontract-cli`) for command-line tools and programmatic interaction with data contracts including schema validation and quality checks against actual data.","message":"This `datacontract-specification` library provides only the Pydantic model of the Data Contract Specification. It does *not* include the CLI tools (like `lint`, `test`, `export`, `import`, `breaking`) or direct programmatic interaction with data sources. For command-line functionality and comprehensive data contract enforcement, use the `datacontract-cli` library.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement semantic versioning for data contracts. Prioritize additive, backward-compatible changes. For unavoidable breaking changes, coordinate with consumers, update major versions, and provide clear migration paths. Leverage `datacontract-cli breaking` command to detect such changes in CI/CD pipelines.","message":"Modifying data contract definitions (e.g., changing field types incompatibly, removing required fields, or making optional fields required) is a breaking change that can significantly affect downstream data consumers. Incompatible changes will lead to data pipeline failures and erode trust.","severity":"breaking","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}