aind_data_access_api.helpers package

Submodules

aind_data_access_api.helpers.data_schema module

Module for convenience functions for the data access API.

aind_data_access_api.helpers.data_schema.add_qc_evaluations_to_docdb(client: MetadataDbClient, data_asset_id: str, evaluations: QCEvaluation | List[QCEvaluation])

Serialize QCEvaluation object(s) and add them to DocDB.

Parameters:
  • client (MetadataDbClient) – A connected DocumentDB client.

  • evaluations (QCEvaluation or list[QCEvaluation]) – One or more QCEvaluation objects from aind-data-schema.

Returns:

The response(s) from MetadataDbClient.add_qc_evaluation.

Return type:

dict or list[dict]

aind_data_access_api.helpers.data_schema.get_quality_control_by_id(client: MetadataDbClient, _id: str, allow_invalid: bool = False)

Using a connected DocumentDB client, retrieve the QualityControl object for a given record.

Parameters:
  • client (MetadataDbClient) – A connected DocumentDB client.

  • _id (str, optional) – _id field in DocDB, by default empty

  • allow_invalid (bool, optional) – return invalid QualityControl as dict if True, by default False

aind_data_access_api.helpers.data_schema.get_quality_control_by_name(client: MetadataDbClient, name: str, allow_invalid: bool = False)

Using a connected DocumentDB client, retrieve the QualityControl object for a given record.

Parameters:
  • client (MetadataDbClient) – A connected DocumentDB client.

  • name (str, optional) – name field in DocDB, by default empty

  • allow_invalid (bool, optional) – return invalid QualityControl as dict if True, by default False

aind_data_access_api.helpers.data_schema.get_quality_control_by_names(client: MetadataDbClient, names: List[str], allow_invalid: bool = False) List[QualityControl | dict]

Using a connected DocumentDB client, retrieve the QualityControl object for a list of records.

Parameters:
  • client (MetadataDbClient) – A connected DocumentDB client.

  • names (List[str],) – name fields in DocDB

  • allow_invalid (bool, optional) – return invalid QualityControl as dict if True, by default False

aind_data_access_api.helpers.data_schema.get_quality_control_status_df(client: MetadataDbClient, names: List[str], date: datetime | None = None) DataFrame

Using a connected DocumentDB client, retrieve the status of all QualityControl objects for a list of records.

Parameters:
  • client (MetadataDbClient) – A connected DocumentDB client.

  • names (List[str],) – name fields in DocDB

aind_data_access_api.helpers.data_schema.get_quality_control_value_df(client: MetadataDbClient, names: List[str]) DataFrame

Using a connected DocumentDB client, retrieve the value of all QualityControl objects for a list of records.

Parameters:
  • client (MetadataDbClient) – A connected DocumentDB client.

  • names (List[str],) – name fields in DocDB

aind_data_access_api.helpers.data_schema.validate_qc(qc_data: dict, allow_invalid: bool = False)

Validate a quality control dict.

aind_data_access_api.helpers.docdb module

Utilities that go through the MetadataDBClient

aind_data_access_api.helpers.docdb.get_field_by_id(client: MetadataDbClient, _id: str, field: str) dict | None

Download a single field from docdb using the record _id

Parameters:
Returns:

None if a record does not exist. Otherwise returns the field in a dict.

Return type:

Optional[dict]

aind_data_access_api.helpers.docdb.get_id_from_name(client: MetadataDbClient, name: str) str

Get the _id of a record in DocDb from its name field. If multiple share the same name, only the first record is returned. If no record is found, an exception is raised.

Parameters:
Returns:

The _id of the record with the given name.

Return type:

str

aind_data_access_api.helpers.docdb.get_name_from_id(client: MetadataDbClient, _id: str) str

Get the name of a record in DocDb from its _id field. If no record is found, an exception is raised.

Parameters:
Returns:

The name of the record with the given _id.

Return type:

str

aind_data_access_api.helpers.docdb.get_projection_by_id(client: MetadataDbClient, _id: str, projection: dict) dict | None

Download a record from docdb using the record _id and a projection.

Projections return fields set to 1, e.g. {“field”: 1}

Parameters:
Returns:

None if record does not exist. Otherwise, it will return the projected record as a dict.

Return type:

Optional[dict]

aind_data_access_api.helpers.docdb.get_projection_by_name(client: MetadataDbClient, name: str, projection: dict) dict | None

Download a record from docdb using the record name and a projection.

Projections return fields set to 1, e.g. {“field”: 1}

Parameters:
Returns:

None if record does not exist. Otherwise, it will return the projected record as a dict.

Return type:

Optional[dict]

aind_data_access_api.helpers.docdb.get_record_by_id(client: MetadataDbClient, _id: str) dict | None

Download a record from docdb using the record _id.

Parameters:
Returns:

_description_

Return type:

Optional[dict]

aind_data_access_api.helpers.docdb.get_record_by_name(client: MetadataDbClient, name: str) dict | None

Download a record from docdb using the record name.

Parameters:
Returns:

None if record does not exist. Otherwise, it will return the record as a dict.

Return type:

Optional[dict]

Module contents

Init module