{"id":4665,"library":"open-data-contract-standard","title":"Open Data Contract Standard (Python)","description":"The `open-data-contract-standard` Python library provides a Pydantic model for reading and writing YAML files conforming to the Open Data Contract Standard (ODCS). It's extracted from the Data Contract CLI and its version number mirrors the major and minor versions of the ODCS it supports. The library is actively maintained, currently at version 3.1.2, supporting ODCS v3.1.0 and above.","status":"active","version":"3.1.2","language":"python","source_language":"en","source_url":"https://github.com/datacontract/open-data-contract-standard-python","tags":["data-contracts","pydantic","yaml","data-governance","schema-validation","odcs","data-quality"],"install":[{"cmd":"pip install open-data-contract-standard","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core library functionality is built upon Pydantic models for data validation and serialization.","package":"pydantic"}],"imports":[{"note":"The main Pydantic model for the data contract.","symbol":"OpenDataContractStandard","correct":"from open_data_contract_standard.model import OpenDataContractStandard"}],"quickstart":{"code":"from open_data_contract_standard.model import OpenDataContractStandard\n\n# Example 1: Load a data contract specification from a string\ndata_contract_str = \"\"\"\nversion: 1.0.0\nkind: DataContract\nid: 53581432-6c55-4ba2-a65f-72344a91553b\nstatus: active\nname: my_table\napiVersion: v3.1.0\n\"\"\"\ndata_contract_from_string = OpenDataContractStandard.from_string(data_contract_str)\nprint(\"--- Data Contract from string ---\")\nprint(data_contract_from_string.to_yaml())\n\n# Example 2: To load from a file, you would use from_file\n# Ensure 'data_contract.yaml' exists in the same directory\n# with valid ODCS content for this to run without error.\n# import os\n# file_path = 'data_contract.yaml'\n# with open(file_path, 'w') as f:\n#    f.write(data_contract_str)\n# data_contract_from_file = OpenDataContractStandard.from_file(file_path)\n# print(\"\\n--- Data Contract from file ---\")\n# print(data_contract_from_file.to_yaml())\n# os.remove(file_path) # Clean up file\n","lang":"python","description":"This quickstart demonstrates how to load an Open Data Contract Standard (ODCS) specification from a string using the `OpenDataContractStandard` Pydantic model and then print it back as a YAML string. It includes comments for how to load from a file, which requires an existing YAML file."},"warnings":[{"fix":"Always check the PyPI page or GitHub README for the exact version mapping between the pip module and the ODCS specification version it implements.","message":"The pip module version mirrors the major and minor versions of the Open Data Contract Standard (ODCS) it supports, but specifically does NOT mirror the patch version. For instance, ODCS v3.1.0 might correspond to pip module versions >=3.1.0 but not necessarily 3.1.0 exactly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review the ODCS v3.0.0 changelog for a comprehensive list of breaking changes. Update your data contract YAML files to conform to the ODCS v3.x specification.","message":"Migration from ODCS v2.x to v3.x involved significant breaking changes in the standard's schema, which the `open-data-contract-standard` Python library (v3.x and above) enforces. Key changes include renaming `uuid` to `id`, `columns` to `properties`, and changing the `team` (formerly `stakeholders`) structure from an array to an object.","severity":"breaking","affected_versions":"3.x.x (when processing v2.x ODCS contracts)"},{"fix":"Ensure your data contracts strictly adhere to the ODCS v3.1.0 (or later) JSON Schema, removing any properties not explicitly defined in the standard. Review the ODCS v3.1.0 release notes for details on stricter validation.","message":"ODCS v3.1.0 introduced stricter JSON Schema validation, disallowing additional or undefined properties in certain sections of the contract. While v3.1.0 was declared backward compatible with v3.0.x, contracts that previously contained extra, undefined fields (and were thus valid under a looser schema) will now fail validation.","severity":"breaking","affected_versions":"3.1.0 and later"},{"fix":"Avoid using `slaDefaultElement` and the top-level `dataProduct`. Consult the latest ODCS documentation for recommended alternatives or replacements.","message":"In ODCS v3.1.0, `slaDefaultElement` and the top-level `dataProduct` fields were deprecated. While still functional, they will generate warnings and are slated for removal in future major versions (e.g., ODCS v4).","severity":"deprecated","affected_versions":"3.1.0 and later"}],"env_vars":null,"search_vec":"'3.1.2':63 'activ':58 'cli':39 'conform':24 'contract':3,10,29,38,71 'current':60 'data':2,9,28,37,70,75,82 'data-contract':69 'data-govern':74 'data-qu':81 'extract':34 'file':23 'govern':76 'librari':13,56 'maintain':59 'major':46 'minor':48 'mirror':44 'model':17 'number':43 'odc':31,52,65,80 'open':1,8,27 'open-data-contract-standard':7 'provid':14 'pydant':16,72 'python':5,12 'qualiti':83 'read':19 'schema':78 'schema-valid':77 'standard':4,11,30 'support':54,64 'v3.1.0':66 'valid':79 'version':42,49,62 'write':21 'yaml':22,73","created_at":"2026-04-12T14:02:22.501912+00:00","updated_at":"2026-04-16T17:33:09.640523+00:00","problems":[{"fix":"Ensure the library is installed using `pip install open-data-contract-standard` and that you are importing it correctly, e.g., `from open_data_contract_standard.model import OpenDataContractStandard`.","cause":"The Python interpreter cannot find the installed `open-data-contract-standard` library, likely due to it not being installed, an incorrect environment, or a wrong import statement.","error":"ModuleNotFoundError: No module named 'open_data_contract_standard'"},{"fix":"Review your data contract YAML file to ensure all mandatory fields according to the Open Data Contract Standard (ODCS) specification are present and correctly structured. Refer to the ODCS documentation or examples for the expected schema.","cause":"The YAML file or data provided to the `OpenDataContractStandard` model is missing one or more required top-level fields (e.g., 'apiVersion', 'kind', 'id', 'name', 'version', 'status') as defined by the Open Data Contract Standard schema and enforced by Pydantic.","error":"ValidationError: 1 validation error for OpenDataContractStandard\n__root__\n  Field required [type=missing, input_value={'some_invalid_data':...}, input_type=dict]"},{"fix":"Carefully check the YAML file for syntax errors, paying close attention to indentation, colons, and valid YAML structure around the indicated line and column. Use a YAML linter or editor with YAML validation to identify and correct the syntax issues.","cause":"The input YAML string or file is malformed, typically due to incorrect indentation, missing colons, or other syntax errors, preventing the `PyYAML` parser (used by the library) from correctly loading the data.","error":"yaml.YAMLError: while parsing a block mapping\n  in \"<string>\", line X, column Y\nexpected <block end>, but found '<scalar>'"},{"fix":"Correct the data type of the problematic field in your YAML contract. For instance, if `logicalType` is expected to be a string like 'string' or 'integer', ensure it is enclosed in quotes and not provided as a number. Review the ODCS schema for the correct types of each field.","cause":"A field within the data contract, such as `logicalType` in the schema's properties, has been provided with an incorrect data type (e.g., an integer where a string is expected), violating the Pydantic model's type constraints.","error":"ValidationError: 1 validation error for OpenDataContractStandard\n__root__ -> schema -> 0 -> properties -> 0 -> logicalType\n  Input should be a valid string [type=string_type, input_value=123, input_type=int]"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"3.1.2","cli_name":"datacontract","cli_version":"sh: 1: datacontract: not found","type":"library","homepage":"https://opendatacontractstandard.org","github":"https://github.com/datacontract/open-data-contract-standard-python","docs":null,"changelog":null,"pypi":"https://pypi.org/project/open-data-contract-standard/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-30","next_check":"2026-07-28","install_tag":null}}