Skip to content

Datasets

from qdl import Dataset

Dataset

A dataset represent a measurement or simulation run and as such is the primary abstraction of QDL.

A dataset functions as a container of files which are intrinsically linked (raw data, analysis, configuration, etc.) and their metadata (collection data, attributes, etc.). A dataset can be added to multiple collections, but only to one sequence.

Parameters:

Name Type Description Default
scope_uid UID

UID of the scope in which to create the dataset.

required
name NonEmptyString256

Name of the dataset.

required
uid Optional[UID]

UID of the dataset. Defaults to the dataset name.

None

__ensure_dataset_path

Return valid path for datasets.

When local_path is given, this is taken as dataset path. We create the directory when needed. When local path is not given the default path from the configuration is taken and scope_uid and dataset_uid are attached to it.

__ensure_dir staticmethod

The path is created when it does not exist.

Returns:

Type Description
Path

The requested path (given or configured) that exists.

__ensure_local_dir

When local dir is not specified, the preconfigured path is taken.

The directory is created when it does not exist.

Returns:

Type Description
Path

The requested path (given or configured) that exists.

__get_datasets classmethod

Get the datasets for the given filters from QDL.

Fetch all pages and add the datasets to the result.

add_attribute

Add a key-value(s) attribute to the local dataset.

Attributes are user defined metadata that can be used to identify datasets. For the same key, multiple values can be added. Values are numeric or string values. For numeric values a unit can be added.

Parameters:

Name Type Description Default
key NonEmptyString64

Name of the attribute.

required
value Union[NumericOrStrType, List[NumericOrStrType]]

Value(s) belonging to the attribute. This can be a string, or a list of strings.

required
unit Optional[str]

Optional unit for the numeric attribute.

None
description Optional[str]

Optional description for the attribute.

None
Notes

Only after updating the dataset, is the attribute added to the dataset in QDL.

add_collection

Add a collection to the local dataset.

Parameters:

Name Type Description Default
collection Union[Collection, UID]

UID of the collection in QDL as a string, or a local Collection instance.

required
Notes

Only after updating the dataset, is the collection added to the dataset in QDL.

add_dir

Add directory metadata to the local dataset recursively.

This means all files contained within this directory and subdirectories are added. To add the file contents to the dataset, use the "upload" method. To add individual files, use the "add file" method.

Parameters:

Name Type Description Default
local_path NonEmptyString2000

Local path to the directory, including the directory name.

required
qdl_path Optional[NonEmptyString2000]

Optionally, path to the directory in QDL, including the directory name.

None

Raises:

Type Description
ValueError

Local path is not a directory.

Notes

Only after updating the dataset, are the files added to the dataset in QDL.

See Also

SDK documentation to ignore specific files when adding a directory to a local dataset.

add_file

Add file metadata to the local dataset, except when the qdl_path is excluded due to the .qdlignore list.

To add the file contents to the dataset, use the "upload" method.

Parameters:

Name Type Description Default
local_path NonEmptyString2000

Local path to the file, including the local file name.

required
qdl_path Optional[NonEmptyString2000]

Optionally, path to the file in QDL, including the file name.

None

Raises:

Type Description
ValueError

File with the QDL path is already part of the dataset with a different local_path.

ValueError

Local path cannot change from a file to a directory or vice versa in the dataset.

Notes

Only after updating the dataset, is the file metadata added to the dataset in QDL.

See Also

SDK documentation for a detailed explanation about the differences between the local and QDL paths.

add_schema

Add a schema to the local dataset.

The dataset is automatically validated against this schema after it is updated. The result of this validation is stored in the "schema_validation_result" attribute.

Parameters:

Name Type Description Default
schema Union[Schema, UID]

UID of the schema in QDL as a string, or a local Schema instance.

required
Notes
  • Only after updating the dataset, is the schema added to the dataset in QDL.
  • The dataset will still be updated if the schema validation fails.
  • The schema can be overridden if a default schema is set for the scope, depending on the validation level.
  • Once added, the schema can no longer be removed from the dataset in QDL.
See Also

SDK documentation for the different validation methods for datasets against a schema.

add_sequence

Add a sequence to the local dataset.

Parameters:

Name Type Description Default
sequence Union[Sequence, UID]

UID of the sequence in QDL as a string, or a local Sequence instance.

required
Notes

Only after updating the dataset, is the sequence added to the dataset in QDL.

attributes property

Attributes added to the dataset.

check_file_in_dataset

Check if File object referenced by qld_path exists in the dataset.

Returns:

Type Description
bool

True when it does exist, else False.

collected property writable

Timestamp of when the dataset is collected, including its timezone.

Notes

Defaults to the timestamp the dataset object is created, but may be overwritten with another timestamp in the past.

collections property

Collections the dataset is part of.

create

Create the local dataset in QDL.

Raises:

Type Description
QdlSdkException

HTTP error code with description.

Notes

If a schema was added to the local dataset, it is validated before creation.

description property writable

Description of the dataset.

deserialize classmethod

Deserialize a previously serialized dataset from a manifest file into a local dataset. The local path to this file can be defined in the following ways:

  • No arguments, in this case the working directory of the SDK is searched for the manifest file.
  • Add a "local_path" argument, excluding the manifest file name.
  • Add "scope_uid" and "name" arguments to expand the working directory of the SDK with.
  • Add "scope_uid" and "uid" arguments to expand the working directory of the SDK with.

Optionally, validate the local dataset against a schema after deserializing.

Parameters:

Name Type Description Default
local_path Optional[NonEmptyString2000]

Local path to the manifest file.

None
scope_uid Optional[UID]

UID of the scope.

None
name Optional[NonEmptyString256]

Name of the dataset.

None
uid Optional[UID]

UID of the dataset.

None
schema Optional[Union[Schema, UID]]

Optionally, UID of a schema in QDL as a string, or a local Schema instance.

None

Returns:

Type Description
Dataset

Dataset instance.

Raises:

Type Description
ValueError

Schema validation failed.

ValueError

No manifest file found in the given local path.

See Also

SDK "configure" function to change the working directory of the SDK.

download

Download all the files in the dataset from QDL.

Parameters:

Name Type Description Default
local_path Optional[NonEmptyString2000]

Path to the directory in which to store the downloaded files. If no path is given, the current working directory of the SDK is used.

None
overwrite bool

Overwrite existing files in the download directory if True, otherwise skip the files.

False
blocked bool

Wait for download to finish before continuing if True.

False
timeout int

Maximum seconds to wait for download to finish. This argument has no effect when blocked is False.

0

Raises:

Type Description
QdlSdkException

HTTP error code with description.

ValueError

Descriptor of the file is invalid for uploading the file.

AssertionError

Scope UID, dataset UID, file name, or file UUID is None.

QdlSdkException

Download did not finish before time out.

Notes

If a file is still being uploaded, it will not be downloaded.

See Also

SDK "configure" function to change the working directory of the SDK.

download_dir_in_progress

Check with daemon if a download is in progress for the directory given.

Daemon will return True when any file exists in the download queue that is not finished downloading to a path relative to the download_dir given.

Parameters:

Name Type Description Default
download_dir NonEmptyString2000

The directory we want to check.

required

Returns:

Type Description
bool

True when Daemon finds any file in the download queue that is not finished downloading to a path relative

bool

to the download_dir given, else False.

Raises:

Type Description
TypeError

Type of input parameter is invalid.

QdlSdkException

HTTP error code with description.

download_file

Download a single file in the dataset from QDL.

Parameters:

Name Type Description Default
qdl_path NonEmptyString2000

QDL path to the file in the dataset, including the file name.

required
version_id Optional[VersionIdType]

Specific version ID of the file to download. Defaults to the latest version.

None
local_path Optional[NonEmptyString2000]

Path to a directory in which to store the downloaded files. If no path is given, the current working directory of the SDK is used.

None
overwrite bool

Overwrite existing files in the download directory if True, otherwise skip the files.

False
blocked bool

Wait for download to finish before continuing if True.

False
timeout int

Maximum seconds to wait for download to finish. This argument has no effect when blocked is False.

0

Raises:

Type Description
QdlSdkException

HTTP error code with description.

ValueError

Descriptor of the file is invalid for uploading the file.

AssertionError

Scope UID, dataset UID, file name, or file UUID is None.

QdlSdkException

Download did not finish before time out.

Notes

If the file is still being uploaded, it will not be downloaded.

See Also
  • SDK "configure" function to change the working directory of the SDK.
  • SDK documentation for a detailed explanation about the differences between the local and QDL paths.

exists classmethod

Check if the dataset with the given scope UID and UID exists in QDL.

Parameters:

Name Type Description Default
scope_uid UID

Scope UID of the dataset.

required
uid UID

UID of the dataset.

required

Returns:

Type Description
bool

True when the dataset exists, otherwise False.

Raises:

Type Description
QdlSdkException

HTTP error code with description.

files property

Files added to the dataset.

files_by_name property

File names added to the dataset.

get classmethod

Get the dataset with the given scope UID and UID from QDL.

Parameters:

Name Type Description Default
scope_uid UID

Scope UID of the dataset.

required
uid UID

UID of the dataset.

required

Returns:

Type Description
Dataset

Dataset instance from QDL.

Raises:

Type Description
QdlSdkException

HTTP error code with description.

TypeError

Type of input parameter is invalid.

ValueError

Value of input parameter is invalid.

Notes

Collections, sequence, attributes, and files belonging to the dataset are not loaded immediately, only when accessed. File contents are not downloaded.

get_by_name classmethod

Get the dataset with the given scope UID and name from QDL.

Parameters:

Name Type Description Default
scope_uid UID

Scope UID of the dataset.

required
name NonEmptyString256

Name of the dataset.

required

Returns:

Type Description
Dataset

Dataset instance from QDL.

Raises:

Type Description
QdlSdkException

HTTP error code with description and status code.

QdlSdkException

No dataset found with the given name.

QdlSdkException

Multiple datasets found with the given name.

TypeError

Type of input parameter is invalid.

ValueError

Value of input parameter is invalid.

Notes

Collections, sequence, attributes, and files belonging to the dataset are not loaded immediately, only when accessed. File contents are not downloaded.

get_file

Return the File object referenced by qld_path, raise an error when it does not exist.

Parameters:

Name Type Description Default
qdl_path NonEmptyString2000

QDL path to the file in the dataset, including the file name.

required

Raises:

Type Description
QdlSdkException

When file is not found in the dataset.

get_file_versions

Get all the versions of a file in the local dataset.

Parameters:

Name Type Description Default
qdl_path NonEmptyString2000

QDL path to the file in the dataset, including the file name.

required

Returns:

Type Description
List[DictStrAny]

List with all the file versions.

Raises:

Type Description
QdlSdkException

HTTP error code with description.

See Also

SDK documentation for a detailed explanation about the differences between the local and QDL paths.

is_mutable property writable

Flag that defines if dataset updates are allowed.

list classmethod

Get the dataset(s) with the given scope UID from QDL.

Optionally, add additional filters as keyword arguments.

Parameters:

Name Type Description Default
scope_uid UID

Scope UID of the dataset(s).

required

Other Parameters:

Name Type Description
uid str

UID of the dataset.

name str

Name of the dataset(s).

uuid str

UUID of the dataset.

oid str

Old UID of the dataset(s).

since str

Datetime from when the dataset(s) were collected.

until str

Datetime until the dataset(s) were collected.

rank str

Rank of the dataset(s).

schema_name str

Name of the schema which is added to the dataset(s).

collection_names str or list[str]

(List of) collection name(s) which the dataset(s) is/are added to.

sequence_uid str

UID of the sequence which the dataset(s) is/are added to.

q str

Text contained in the dataset name, description, attribute keys, file names, or tags.

attribute_key (str, float, int)

Attribute key-value pair(s). For example, attribute_key=attribute_value.

See Also

SDK documentation for the different attribute filter methods.

Returns:

Type Description
List[Dataset]

List with the (filtered) dataset instances from QDL. Returns an empty list when no matches are found.

Raises:

Type Description
QdlSdkException

HTTP error code with description.

TypeError

Type of input parameter is invalid.

ValueError

Value of input parameter is invalid.

Notes

Collections, sequence, attributes, and files belonging to the dataset(s) are not loaded immediately, only when accessed. File contents are not downloaded.

name property writable

Name of the dataset.

oid property writable

Old ID of the dataset.

Notes

Added for compatibility with previously defined dataset IDs.

rank property writable

The rank of the dataset based on its importance.

Ranges from -5 to 5. Defaults to 0.

remove_attribute

Remove a specific value from an attribute key in the local dataset.

The attribute key is also removed from the local dataset when all attribute values have been removed.

Parameters:

Name Type Description Default
key NonEmptyString64

Key of the attribute.

required
value NumericOrStrType

Value belonging to the attribute key.

required
Notes

Only after updating the dataset, is the attribute value removed from the dataset in QDL.

remove_collection

Remove a collection from the local dataset.

Parameters:

Name Type Description Default
collection Union[Collection, UID]

UID of the collection in QDL as a string, or a local Collection instance.

required
Notes

Only after updating the dataset, is the collection removed from the dataset in QDL.

remove_file

Remove a single file from the local dataset.

Parameters:

Name Type Description Default
qdl_path NonEmptyString2000

Path to the file in QDL, including the file name.

required
Notes

Only after updating the dataset, is the file removed from the dataset in QDL.

remove_schema

Remove the schema from the local dataset.

remove_sequence

Remove the sequence from the local dataset.

Notes

Only after updating the dataset, is the sequence removed from the dataset in QDL.

restore_file

Restore the latest version of a file in the local dataset to the given previous version.

Parameters:

Name Type Description Default
qdl_path NonEmptyString2000

QDL path to the file in the dataset, including the file name.

required
version_id VersionIdType

Specific version ID of the file to restore the latest version to.

required

Raises:

Type Description
QdlSdkException

HTTP error code with description.

Notes
  • Only after updating the dataset, is the file version restored in QDL.
  • All previous versions including the current latest version of the file will still exist. No data will be overwritten.
See Also

SDK documentation for a detailed explanation about the differences between the local and QDL paths.

schema property writable

Schema the dataset is validated against.

schema_validation_result property

Read-only field that specifies the status of the validation of the dataset against the schema.

scope property writable

UID of the scope in which the dataset is defined.

sequence property

Sequence the dataset is part of.

serialize

Serialize a local dataset into a manifest file.

Optionally, validate the dataset against the given schema, before serializing.

Parameters:

Name Type Description Default
local_path Optional[NonEmptyString2000]

Optionally, local path to store the manifest file. If no path is given, the file will be stored in the current working directory of the SDK, expanded with the scope UID and dataset UID.

None
schema Optional[Union[Schema, UID]]

Optionally, UID of a schema in QDL as a string, or a local Schema instance.

None

Raises:

Type Description
ValueError

Schema validation failed.

See Also

SDK "configure" function to change the working directory of the SDK.

stream_file

Download a specific file in the dataset from QDL as bytes in memory.

Parameters:

Name Type Description Default
qdl_path NonEmptyString2000

QDL path to the file in the dataset, including the file name.

required
version_id Optional[VersionIdType]

Specific version ID of the file to download. Defaults to the latest version.

None
timeout int

Maximum seconds to wait for download to finish. This argument has no effect when blocked is False.

0

Returns:

Type Description
bytes

Content of the downloaded file as bytes.

Raises:

Type Description
QdlSdkException

HTTP error code with description.

ValueError

Descriptor of the file is invalid for uploading the file.

AssertionError

Scope UID, dataset UID, file name, or file UUID is None.

Notes

If the file is still being uploaded, it will not be downloaded.

tags property writable

Field that specifies the tags of the dataset.

to_dict

Returns a dictionary representation of the dataset.

Parameters:

Name Type Description Default
include_local_fields bool

When True, fields only known locally are added, as file_path in files.

True

Returns:

Type Description
DictStrAny

Dictionary representation of the dataset and all of its linked objects collections, sequence, attributes,

DictStrAny

and files.

uid property writable

UID of the dataset.

update

Update the dataset in QDL with the changes from the local dataset.

Raises:

Type Description
QdlSdkException

HTTP error code with description.

Notes
  • An error is raised when the dataset does not yet exist in QDL.
  • The scope UID, UID, and UUID of the dataset cannot be updated.
  • If a schema was added to the local dataset before updating, it is validated before the update.
  • A previously added schema does not trigger a re-validation before the update.

upload

Upload all the files in the dataset to QDL.

Before uploading, first create/update the dataset.

Parameters:

Name Type Description Default
overwrite bool

Create new versions of existing files in QDL if True, otherwise skip the files.

False
blocked bool

Wait for upload to finish before continuing if True.

False
timeout int

Maximum seconds to wait for upload to finish. This argument has no effect when blocked is False.

0

Raises:

Type Description
AssertionError

File path, or file UUID is None.

ValueError

Descriptor of the file is invalid for uploading the file.

ValueError

Path of the file is not set.

QdlSdkException

HTTP error code with description.

QdlSdkException

Path of the file does not exist.

QdlSdkException

Upload did not finish before time out.

upload_files

Upload a list of files (for example a subset of updated files) in the dataset to QDL.

Before uploading, first create/update the dataset.

Parameters:

Name Type Description Default
qdl_paths List[NonEmptyString2000]

List of QDL paths pointing to the relative file position within the dataset.

required
overwrite bool

Create a new version of the files if it exists in QDL if True, otherwise skip the file.

False
blocked bool

Wait for upload to finish before continuing if True.

False
timeout int

Maximum seconds to wait for upload to finish. This argument has no effect when blocked is False.

0

Raises:

Type Description
AssertionError

File path, or file UUID is None.

ValueError

Descriptor of the file is invalid for uploading the file.

ValueError

Path of the file is not set.

QdlSdkException

HTTP error code with description.

QdlSdkException

Path of the file does not exist.

QdlSdkException

Upload did not finish before time out.

See Also

SDK documentation for a detailed explanation about the differences between the local and QDL paths.

uuid property writable

UUID of the dataset with type UUID4.

validate

Validate the dataset against the given schema.

Parameters:

Name Type Description Default
schema Union[Schema, UID]

UID of the schema in QDL as a string, or local Schema instance to validate the dataset against.

required
local_validation bool

Validate the local dataset against the schema if True, otherwise validate the dataset as it is currently in QDL.

True

Returns:

Type Description
bool

True when the validation of the dataset against the schema was successful, otherwise False.

Raises:

Type Description
QdlSdkException

HTTP error code with description.

Notes
  • If the dataset does not (yet) exist in QDL with local validation set to False, an error is raised.
  • If the dataset does not pass the validation, the reason is printed in the console.
  • This method only returns the result of the validation, it does not affect the dataset.
See Also

SDK documentation for the different validation methods for datasets against a schema.