# Storage

# Storage

machinable.Storage(url:Union[str, NoneType]=None, directory:Union[str, NoneType]=None, submission:Union[str, NoneType]=None, component:Union[str, NoneType]=None)

# log property

Log interface

# record property

Record interface

# data

data(self, name=None, default=<object object at 0x7f2d3595c430>)

Retrieves a data object from the storage

# Arguments

  • name: Name of the data object. If None, a list of available objects is returned

# file

file(self, filepath, default=<object object at 0x7f2d3595c430>)

Returns the content of a file in the storage

# Arguments

  • filepath: Relative filepath
  • default: Optional default if file does not exist

# get_local_directory

get_local_directory(self, append='')

Returns the local storage filesystem path, or False if non-local

# Returns

Local filesystem path, or False if non-local

# get_path

get_path(self, append='', create=False) -> str

Returns the storage's relative path

# Arguments

  • append: String, optional postfix that is appended to the path
  • create: Boolean, if True path is being created if not existing

# get_records

get_records(self, scope=None, events=None, created_at=None) -> Union[dict, machinable.storage.record.Record]

Creates or returns an instance of a record writer

# Arguments

  • scope: Name of the record writer. If None, a dict of all registered writers will be returned
  • events: Event callback

# get_stream

get_stream(self, path, mode='r', *args, **kwargs)

Returns a file stream on the storage

# Arguments

  • path: Relative file path
  • mode: Python file mode *args, **kwargs: Optional arguments passed into stream open()

# get_submission

get_submission(self, component=False, or_fail=False)

Returns the Submission

# Arguments

  • component: Component to be returned if the URL is a submission containing multiple components. For example, set to 0 or -1 to retrieve first or last in the collection respectively
  • or_fail: Boolean, by default None is returned if the submission does not exist. If True, an Exception will be raised instead

# has_file

has_file(self, filepath) -> bool

Checks if a file exists

# Arguments

  • filepath: String, file name

# has_log

has_log(self) -> bool

Determines whether log has been written

# has_records

has_records(self, scope='default') -> bool

Determines whether records have been written

# Arguments

  • scope: String, name of the record writer. Defaults to 'default'

# save_data

save_data(self, name, data, overwrite=True)

Stores a data object

# Arguments

  • name: String, name identifier. Supported formats are .json (JSON), .npy (numpy), .p (pickle), .txt (txt)
  • data: The data object
  • overwrite: Boolean, if False write will be appended to file if existing

# save_file

save_file(self, filepath, data, overwrite=True)

Writes data to file

# Arguments

  • filepath: String, filepath with extension. Supported formats are .json (JSON), .npy (numpy), .p (pickle), .txt (txt)
  • data: The data object
  • overwrite: Boolean, if False write will be appended instead of overwritten