tiled.client.base.BaseClient.update_metadata

BaseClient.update_metadata(metadata=None, specs=None)[source]

EXPERIMENTAL: Update metadata via a dict.update- like interface.

update_metadata is a user-friendly wrapper for patch_metadata. This is subject to change or removal without notice.

Parameters:
metadatadict, optional

User metadata. May be nested. Must contain only basic types (e.g. numbers, strings, lists, dicts) that are JSON-serializable.

specsList[str], optional

List of names that are used to label that the data and/or metadata conform to some named standard specification.

Notes

update_metadata constructs a JSON Patch (RFC6902) by comparing user updates to existing metadata. It uses a slight variation of JSON Merge Patch (RFC7386) as an intermediary to implement a python dict.update-like user-friendly interface, but with additional features like key deletion (see examples) and support for None (null) values.

Examples

Add or update a key-value pair at the top or a nested level

>>> node.update_metadata({'key': new_value})
>>> node.update_metadata({'top_key': {'nested_key': new_value}})

Remove an existing key

>>> from tiled.client.metadata_update import DELETE_KEY
>>> node.update_metadata({'key_to_be_deleted': DELETE_KEY})

Interactively update complex metadata using a copy of original structure (e.g., in iPython you may use tab completion to navigate nested metadata)

>>> md = node.metadata_copy()[0]
>>> md['L1_key']['L2_key']['L3_key'] = new_value  # use tab completion
>>> md['unwanted_key'] = DELETE_KEY
>>> node.update_metadata(metadata=md)  # Update the copy on the server