Open Data Contract Standard (Python)

3.1.2 · active · verified Sun Apr 12

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.

Warnings

Install

Imports

Quickstart

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.

from open_data_contract_standard.model import OpenDataContractStandard

# Example 1: Load a data contract specification from a string
data_contract_str = """
version: 1.0.0
kind: DataContract
id: 53581432-6c55-4ba2-a65f-72344a91553b
status: active
name: my_table
apiVersion: v3.1.0
"""
data_contract_from_string = OpenDataContractStandard.from_string(data_contract_str)
print("--- Data Contract from string ---")
print(data_contract_from_string.to_yaml())

# Example 2: To load from a file, you would use from_file
# Ensure 'data_contract.yaml' exists in the same directory
# with valid ODCS content for this to run without error.
# import os
# file_path = 'data_contract.yaml'
# with open(file_path, 'w') as f:
#    f.write(data_contract_str)
# data_contract_from_file = OpenDataContractStandard.from_file(file_path)
# print("\n--- Data Contract from file ---")
# print(data_contract_from_file.to_yaml())
# os.remove(file_path) # Clean up file

view raw JSON →