idmtools.assets.asset module

idmtools asset class definition.

Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.

class idmtools.assets.asset.Asset(absolute_path: str | None = None, relative_path: str | None = <property object>, filename: str | None = <property object>, content: dataclasses.InitVar[typing.Any] = <property object>, persisted: bool = False, handler: ~typing.Callable = <class 'str'>, download_generator_hook: ~typing.Callable | None = None, checksum: dataclasses.InitVar[typing.Any] = <property object>)[source]

Bases: object

A class representing an asset. An asset can either be related to a physical asset present on the computer or directly specified by a filename and content.

absolute_path: str | None = None

The absolute path of the asset. Optional if filename and content are given.

persisted: bool = False

Persisted tracks if item has been saved

handler

Handler to api

alias of str

download_generator_hook: Callable = None

Hook to allow downloading from platform

property checksum

Checksum of asset. Only required for existing assets

property extension: str

Returns extension of asset.

Returns:

Extension

Notes

This does not preserve the case of the extension in the filename. Extensions will always be returned in lowercase.

property filename

Name of the file. Optional if absolute_path is given.

property relative_path

The relative path (compared to the simulation root folder).

property bytes

Bytes is the content as bytes.

Returns:

None

property length

Get length of item.

Returns:

Length of the content

property content

The content of the file. Optional if absolute_path is given.

deep_equals(other: Asset) bool[source]

Performs a deep comparison of assets, including contents.

Parameters:

other – Other asset to compare

Returns:

True if filename, relative path, and contents are equal, otherwise false

download_generator() Generator[bytearray, None, None][source]

A Download Generator that returns chunks of bytes from the file.

Returns:

Generator of bytearray

Raises:

ValueError - When there is not a download generator hook defined

Notes

TODO - Add a custom error with doclink.

download_stream() BytesIO[source]

Get a bytes IO stream of the asset.

Returns:

BytesIO of the Asset

__init__(absolute_path: str | None = None, relative_path: str | None = <property object>, filename: str | None = <property object>, content: dataclasses.InitVar[typing.Any] = <property object>, persisted: bool = False, handler: ~typing.Callable = <class 'str'>, download_generator_hook: ~typing.Callable | None = None, checksum: dataclasses.InitVar[typing.Any] = <property object>) None
download_to_path(dest: str, force: bool = False)[source]

Download an asset to path. This requires loadings the object through the platform.

Parameters:
  • dest – Path to write to. If it is a directory, the asset filename will be added to it

  • force – Force download even if file exists

Returns:

None

calculate_checksum() str[source]

Calculate checksum on asset. If previous checksum was calculated, that value will be returned.

Returns:

Checksum string

short_remote_path() str[source]

Returns the short remote path. This is the join of the relative path and filename.

Returns:

Remote Path + Filename

save_as(dest: str, force: bool = False)[source]

Download asset object to destination file. :param dest: the file path :param force: force download

Returns:

None

save_md5_checksum()[source]

Save the md5 checksum of the asset to a file in the same directory as the asset. :returns: None