Attachment

class audformat.Attachment(path, *, description=None, meta=None)[source]

Database attachment.

Adds a file or folder as attachment to a database. If a folder is provided, all of its sub-folders and files are included.

Parameters
  • path (str) – relative path to file or folder

  • description (Optional[str]) – attachment description

  • meta (Optional[dict]) – additional meta fields

Raises
  • ValueError – if path is absolute or contains \, .. or .

  • RuntimeError – when assigning an attachment to a database, but the database contains another attachment with an path that is identical or nested compared to the current attachment path

Examples

>>> Attachment("file.txt", description="Attached file")
{description: Attached file, path: file.txt}

__eq__()

Attachment.__eq__(other)

Return self==value.

Return type

bool

description

Attachment.description

Description

dump()

Attachment.dump(stream=None, indent=2)

Serialize object to YAML.

Parameters
  • stream – file-like object. If None serializes to string

  • indent (int) – indent

Return type

str

Returns

YAML string

files

Attachment.files

List all files that are part of the attachment.

List recursively the relative path of all files that exist under audformat.Attachment.path on hard disk.

Raises

from_dict()

Attachment.from_dict(d, ignore_keys=None)

Deserialize object from dictionary.

Parameters
  • d (dict) – dictionary of class variables to assign

  • ignore_keys (Optional[Sequence[str]]) – variables listed here will be ignored

meta

Attachment.meta

Dictionary with meta fields

path

Attachment.path

Attachment path

to_dict()

Attachment.to_dict()

Serialize object to dictionary.

Return type

dict

Returns

dictionary with attributes