Serialize datasets
When working with Dataset instances in Python, it could be desired to store them as a file for later use. Additionally, this manifest could serve as a template or ensure schema compliance.
Serialize a dataset
In the snippet below, a manifest file is generated from a dataset in the current working directory.
If another directory is desired, it can be given with the local_path parameter.
from qdl import Dataset
dataset = Dataset(scope_uid="some_scope", name="some_dataset")
dataset.add_attribute(key="project", value="specific_project")
dataset.add_attribute(key="setup", value="specific_setup")
dataset.serialize()
Deserialize a dataset
To deserialize, multiple options exist to find the manifest file. Using the previous example, the following code snippet creates a dataset using all options.
from qdl import Dataset
dataset = Dataset.deserialize(local_path="./some_scope/some_dataset")
dataset = Dataset.deserialize(scope_uid="some_scope", name="some_dataset")
dataset = Dataset.deserialize(scope_uid="some_scope", uid="some_dataset")
Additionally, the dataset can be validated against a schema after it is created by providing the schema UID.