API Reference#
Merge#
- class ocdsmerge.merge.Merger(schema=None, merge_rules=None, rule_overrides=None)[source]#
- Parameters:
- __init__(schema=None, merge_rules=None, rule_overrides=None)[source]#
Initializes a reusable
Merger
instance for creating merged releases.- Parameters:
schema (dict or str) – the release schema (if not provided, will default to the latest version of OCDS)
merge_rules (Dict[Tuple[str, ...], str] | None) – the merge rules (if not provided, will determine the rules from the
schema
)rule_overrides (Dict[Tuple[str, ...], MergeStrategy] | None) – any rule overrides, in which keys are field paths as tuples, and values are either
ocdsmerge.APPEND
orocdsmerge.MERGE_BY_POSITION
- class ocdsmerge.merge.MergedRelease(data=None, schema=None, merge_rules=None, rule_overrides=None)[source]#
Whether the class is for merging versioned releases.
- Parameters:
- __init__(data=None, schema=None, merge_rules=None, rule_overrides=None)[source]#
Initializes a merged release.
- Parameters:
data (Dict[str, Any] | None) – the latest copy of the merged release, if any
schema (dict or str) – the release schema (if not provided, will default to the latest version of OCDS)
merge_rules (Dict[Tuple[str, ...], str] | None) – the merge rules (if not provided, will determine the rules from the
schema
)rule_overrides (Dict[Tuple[str, ...], MergeStrategy] | None) – any rule overrides, in which keys are field paths as tuples, and values are either
ocdsmerge.APPEND
orocdsmerge.MERGE_BY_POSITION
- __annotations__ = {'versioned': typing.Optional[bool]}#
- class ocdsmerge.merge.CompiledRelease(data=None, **kwargs)[source]#
-
- __init__(data=None, **kwargs)[source]#
Initializes a merged release.
- Parameters:
data (Dict[str, Any] | None) – the latest copy of the merged release, if any
schema (dict or str) – the release schema (if not provided, will default to the latest version of OCDS)
merge_rules – the merge rules (if not provided, will determine the rules from the
schema
)rule_overrides – any rule overrides, in which keys are field paths as tuples, and values are either
ocdsmerge.APPEND
orocdsmerge.MERGE_BY_POSITION
Rules#
Flatten#
- class ocdsmerge.flatten.MergeStrategy(value)[source]#
An enumeration.
- APPEND = 1#
- MERGE_BY_POSITION = 2#
- class ocdsmerge.flatten.IdValue(identifier)[source]#
A string with
identifier
andoriginal_value
properties.
- ocdsmerge.flatten.is_versioned_value(value)[source]#
Returns whether the value is a versioned value.
- ocdsmerge.flatten.flatten(obj, merge_rules, rule_overrides, flattened, path=(), rule_path=(), versioned=False)[source]#
Flattens a JSON object into key-value pairs, in which the key is the JSON path as a tuple. For example:
Replaces numbers in JSON paths (representing positions in arrays) with special objects. This ensures that objects in arrays with different id values have different JSON paths – and makes it easy to identify such arrays.
{ "a": "I am a", "b": ["A", "list"], "c": [ {"id": 1, "cb": "I am ca"}, {"id": 2, "ca": "I am cb"} ] }
flattens to:
{ ('a',): 'I am a', ('b',): ['A', 'list'], ('a', '1', 'cb'): 'I am ca', ('a', '1', 'id'): 1, ('a', '2', 'ca'): 'I am cb', ('a', '2', 'id'): 2, }
- Parameters:
- Return type:
Utilities#
Exceptions#
- exception ocdsmerge.exceptions.OCDSMergeError[source]#
Base class for exceptions from within this package
- exception ocdsmerge.exceptions.MissingDateKeyError(key, message)[source]#
Raised when a release is missing a ‘date’ key
- exception ocdsmerge.exceptions.NonObjectReleaseError[source]#
Raised when a release is not an object
- exception ocdsmerge.exceptions.NullDateValueError[source]#
Raised when a release has a null ‘date’ value
- exception ocdsmerge.exceptions.NonStringDateValueError[source]#
Raised when a release has a non-string ‘date’ value
- exception ocdsmerge.exceptions.InconsistentTypeError[source]#
Raised when a path is a literal and an object in different releases