iprPy.record package

Module contents

class Record(model: str | IOBase | DataModelDict | None = None, name: str | None = None, database=None, **kwargs: any)

Bases: object

Class for handling different record styles in the same fashion. The base class defines the common methods and attributes.

build_model()

Generates and returns model content based on the values set to object.

cdcsquery(**kwargs: any) dict

Builds a CDCS-style query based on kwargs values for the record style.

Parameters:

**kwargs (any) – Any of the record style-specific search parameters.

Returns:

The CDCS-style query

Return type:

dict

clear_tar()

Closes and unsets the record’s tar file to save memory

property database

The default Database associated with the Record

Type:

yabadaba.Database or None

get_file(filename: str | Path, localroot: str | Path | None = None)

Retrieves a file either locally or from the record’s tar archive.

Parameters:
  • filename (str or Path) – The name/path for the file. For local files, this is taken relative to localroot. For files in the tar archive, this is taken relative to the tar’s root directory which is always named for the record, i.e., {self.name}/{filename}.

  • localroot (str, Path or None, optional) – The local root directory that filename (if it exists) is relative to. The default value of None will use the current working directory.

Raises:

ValueError – If filename exists in the tar but is not a file.

Returns:

A file-like object in binary read mode that allows for the file contents to be read.

Return type:

io.IOBase

html(render: bool = False) str | None

Returns an HTML representation of the object.

Parameters:

render (bool, optional) – If True, then IPython is used to render the HTML. If False (default), then the HTML code is returned as a str.

Returns:

The HTML code contents. Returned if render=False.

Return type:

str

load_model(model: str | IOBase | DataModelDict, name: str | None = None)

Loads record contents from a given model.

Parameters:
  • model (str, file-like object, or DataModelDict) – The model contents of the record to load.

  • name (str, optional) – The name to assign to the record. Often inferred from other attributes if not given.

metadata() dict

Generates a dict of simple metadata values associated with the record. Useful for quickly comparing records and for building pandas.DataFrames for multiple records of the same style.

property model: DataModelDict

The record’s model content.

Type:

DataModelDict

property modelroot: str

The name of the root element in the model contents.

Type:

str

mongoquery(name: str | list | None = None, **kwargs: any) dict

Builds a Mongo-style query based on kwargs values for the record style.

Parameters:
  • name (str or list, optional) – The record name(s) to parse by.

  • **kwargs (any) – Any of the record style-specific search parameters.

Returns:

The Mongo-style query

Return type:

dict

property name: str

The record’s name.

Type:

str

pandasfilter(dataframe: DataFrame, name: str | list | None = None, **kwargs: any) Series

Filters a pandas.DataFrame based on kwargs values for the record style.

Parameters:
  • dataframe (pandas.DataFrame) – A table of metadata for multiple records of the record style.

  • name (str or list, optional) – The record name(s) to parse by.

  • **kwargs (any) – Any of the record style-specific search parameters.

Returns:

Boolean map of matching values

Return type:

pandas.Series

property queries: dict

Query objects and their associated parameter names.

Type:

dict

property querydoc: str

A description of all the queries supported by the record.

Type:

str

property querynames: list

The query parameter names supported by the record.

Type:

list

reload_model()

Reloads the record based on the model content. This allows for direct changes to the model to be updated to the object.

set_values(name: str | None = None)

Set multiple object attributes at the same time.

Parameters:

name (str, optional) – The name to assign to the record. Often inferred from other attributes if not given.

property style: str

The record style

Type:

str

property tar

The tar archive associated with the record

Type:

tarfile.TarFile

valid_xml(xml_content: str | None = None) bool

Tests if XML content is valid with schema.

Parameters:

xml_content (str, optional) – XML content to test against the record’s schema. If not given, will generate the xml using build_model.

Returns:

Indicating if XML is valid.

Return type:

bool

property xsd: bytes

The xml schema for the record style.

Type:

bytes

property xsd_filename: tuple

The module path and file name of the record’s xsd schema

Type:

tuple

property xsl: bytes

The xsl transformer for the record style.

Type:

bytes

property xsl_filename: tuple

The module path and file name of the record’s xsl html transformer

Type:

tuple

load_record(style: str, model: str | DataModelDict | None = None, name: str | None = None, database=None, **kwargs) Record

Loads a Record subclass associated with a given record style.

Parameters:
  • style (str) – The record style.

  • name (str, optional) – The name to give to the specific record.

  • model (str, DataModelDict, optional) – Data model content to load for the given record style.

  • database (yabadaba.Database, optional) – Allows for a default database to be associated with the record.

  • **kwargs (any) – Any extra keyword parameter supported by the record style.

Returns:

A Record object for the style

Return type:

subclass of Record