Data Asset class

class starfish.asset.DataAsset(metadata_text: str, did: Optional[str] = None, data: Optional[Any] = None)

Bases: starfish.asset.asset_base.AssetBase, Generic[starfish.types.DataAsset]

File asset can be used manage a data asset on the dex network

Parameters
  • metadata (None or dict) – Dictionary metadata to provide for the asset.

  • did (None or str) – Optional did of the asset if it’s registered

  • data (str) – Optional data of the asset, this can be str or bytes

static create(name: str, data: Optional[Any] = None, metadata: Optional[Any] = None, json: Optional[Any] = None, csv_rows: Optional[List[Any]] = None, csv_header: Optional[List[str]] = None) starfish.types.DataAsset

Create a new DataAsset using string or bytes data.

Parameters
  • name (str) – Name of the asset to create

  • data (str, bytes) – Data to assign to the asset

  • metadata (dict) – Optional metadata to add to the assets metadata

Returns

a new DataAsset

Type

DataAsset

static create_from_file(name: str, filename: str, metadata: Optional[Any] = None, did: Optional[str] = None, is_read: bool = True) starfish.types.DataAsset

Create a new DataAsset using a file or filename.

Parameters
  • name (str) – Name of the asset to create

  • filename (str) – If the filename is assigned to a valid file, the contents will be saved in the asset

  • metadata (dict) – Optional metadata to add to the assets metadata

  • did (str) – Option DID to assign to this asset

  • is_read (bool) – If True read the file contents in as asset data.

Returns

a new DataAsset

Type

DataAsset

csv() Any
property data: Any
property is_csv: bool
property is_json: bool
json() Any
save_to_file(filename: str) None

Saves the data in the data asset to a file.

Parameters

filename (str) – Filename to save the data.

static set_metadata_content_data(metadata: dict, data: Any, content_type: Optional[str] = None) dict

Static method to generate the metadata values associated with storing data with an asset.

This method will try to assign ‘contentType’, ‘contentHash’, ‘contentLength’ in the metadata dict

Parameters
  • metadata (dict) – Metadata to assign and return

  • data (str,bytes) – Data to get the hash and length from

  • content_type (str) – Optional content_type, if not provided the data will be used to determin the contentType

Returns

a modified metadata dict with the new fields set