API Reference#
Merge#
- class ocdsmerge.merge.Merger(schema=None, merge_rules=None, rule_overrides=None)[source]#
- __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) – the merge rules (if not provided, will determine the rules from the
schema
)rule_overrides (dict) – 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.
- versioned = None#
- __init__(data=None, schema=None, merge_rules=None, rule_overrides=None)[source]#
Initializes a merged release.
- Parameters:
data (dict) – 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) – the merge rules (if not provided, will determine the rules from the
schema
)rule_overrides (dict) – any rule overrides, in which keys are field paths as tuples, and values are either
ocdsmerge.APPEND
orocdsmerge.MERGE_BY_POSITION
- class ocdsmerge.merge.CompiledRelease(data=None, **kwargs)[source]#
- versioned = False#
- __init__(data=None, **kwargs)[source]#
Initializes a merged release.
- Parameters:
data (dict) – 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) – the merge rules (if not provided, will determine the rules from the
schema
)rule_overrides (dict) – 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.- property original_value#
- class ocdsmerge.flatten.IdDict[source]#
A dictionary with an
identifier
property.- property identifier#
- 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, }
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