blue_cwl.nexus

Nexus stuff.

Functions

download_distribution(id_or_entity, *, ...)

Download an entity's distribution.

forge_to_config(forge)

Get nexus configuration from forge instance.

get_distribution(id_or_entity, *[, cls, ...])

Return the distribution's location path from the resource.

get_distribution_as_dict(id_or_entity, *[, ...])

Return the distribution json payload as a dictionary.

get_distribution_location_path(id_or_entity, *)

Return the distribution's location path from the resource.

get_forge([nexus_base, nexus_org, ...])

Create a KnowledgeGraphForge instance.

get_region_acronym(resource_id, *[, base, token])

Retrieve the hierarchy acronym from a KG registered region.

get_resource(forge, resource_id)

Get resource from knowledge graph.

blue_cwl.nexus.download_distribution(id_or_entity: str | type[~entity_management.core.Entity], *, output_dir: str | ~os.PathLike[str], filename: str | None = None, cls: type[~entity_management.core.Entity] = <class 'entity_management.core.Entity'>, encoding_format: str | None = None, base: str | None = None, org: str | None = None, proj: str | None = None, token: str | None = None) str

Download an entity’s distribution.

Parameters:
  • id_or_entity – Either the id to retrieve the entity or the entity.

  • cls – entity-management class to instantiate. Default is Entity.

  • output_dir – Output directory to download the distribution to.

  • filename – Filename to use. Resource’s file name is used by default.

  • encoding_format – The format to choose if many.

  • encoding_format – The format to match in case of multiple distributions.

  • base – The nexus base endpoint. If None entity-management’s runtime base is used.

  • org – The nexus organization. If None entity-management’s runtime org is used.

  • proj – The nexus project. If None entity-management’s runtime proj is used.

  • token – Optional OAuth token. If None entity-management’s runtime token is used.

Returns:

Instantiated entity from given id.

Raises:

CWLRegistryError if entity is not found.

blue_cwl.nexus.forge_to_config(forge) tuple[str, str, str, str]

Get nexus configuration from forge instance.

Parameters:

forge – The KnowledgeGraphForge instance.

Returns:

(base, org, proj, token) tuple

blue_cwl.nexus.get_distribution(id_or_entity: str | ~entity_management.core.Entity, *, cls: type[~entity_management.core.Entity] = <class 'entity_management.core.Entity'>, encoding_format: str | None = None, base: str | None = None, org: str | None = None, proj: str | None = None, token: str | None = None) DataDownload

Return the distribution’s location path from the resource.

Parameters:
  • id_or_entity – Either the id to retrieve the entity or the entity.

  • cls – entity-management class to instantiate. Default is Entity.

  • encoding_format – The format to match in case of multiple distributions.

  • base – The nexus base endpoint. If None entity-management’s runtime base is used.

  • org – The nexus organization. If None entity-management’s runtime org is used.

  • proj – The nexus project. If None entity-management’s runtime proj is used.

  • token – Optional OAuth token. If None entity-management’s runtime token is used.

Returns:

Instantiated entity from given id.

Raises:

CWLRegistryError

  • If entity is not found. * If multiple distributions and no matching encoding format.

Note

A resource may have many distributions with a different encoding format. If that’s the case the encoding format argument is mandatory to select the respective distribution.

blue_cwl.nexus.get_distribution_as_dict(id_or_entity: str | type[~entity_management.core.Entity], *, cls: type[~entity_management.core.Entity] = <class 'entity_management.core.Entity'>, base: str | None = None, org: str | None = None, proj: str | None = None, token: str | None = None) dict

Return the distribution json payload as a dictionary.

Parameters:
  • id_or_entity – Either the id to retrieve the entity or the entity.

  • cls – entity-management class to instantiate. Default is Entity.

  • base – The nexus base endpoint. If None entity-management’s runtime base is used.

  • org – The nexus organization. If None entity-management’s runtime org is used.

  • proj – The nexus project. If None entity-management’s runtime proj is used.

  • token – Optional OAuth token. If None entity-management’s runtime token is used.

Returns:

Instantiated entity from given id.

Raises:

CWLRegistryError if entity is not found.

blue_cwl.nexus.get_distribution_location_path(id_or_entity: str | type[~entity_management.core.Entity], *, cls: type[~entity_management.core.Entity] = <class 'entity_management.core.Entity'>, encoding_format: str | None = None, base: str | None = None, org: str | None = None, proj: str | None = None, token: str | None = None) str

Return the distribution’s location path from the resource.

Parameters:
  • id_or_entity – Either the id to retrieve the entity or the entity.

  • cls – entity-management class to instantiate. Default is Entity.

  • encoding_format – The encoding format of the distribution. Example: application/json

  • base – The nexus base endpoint. If None entity-management’s runtime base is used.

  • org – The nexus organization. If None entity-management’s runtime org is used.

  • proj – The nexus project. If None entity-management’s runtime proj is used.

  • token – Optional OAuth token. If None entity-management’s runtime token is used.

Returns:

Instantiated entity from given id.

Raises:

CWLRegistryError if entity is not found.

Note

A resource may have many distributions with a different encoding format. If that’s the case the encoding format argument is mandatory to select the respective distribution.

blue_cwl.nexus.get_forge(nexus_base: str | None = None, nexus_org: str | None = None, nexus_project: str | None = None, nexus_token: str | None = None, force_refresh: bool = False)

Create a KnowledgeGraphForge instance.

Parameters:
  • nexus_base – The nexus instance endpoint.

  • nexus_org – The nexus organization.

  • nexus_project – The nexus project.

  • nexus_token – The OAUth token.

  • force_refresh – Whether to attempt renew the token (Requires offline token).

Returns:

KnowledgeGraphForge instance

blue_cwl.nexus.get_region_acronym(resource_id: str, *, base: str | None = None, token: str | None = None) str

Retrieve the hierarchy acronym from a KG registered region.

blue_cwl.nexus.get_resource(forge, resource_id: str)

Get resource from knowledge graph.

Parameters:
  • forge – The KnowledgeGraphForge instance.

  • resource_id – The string id of the resource to retrieve.

Returns:

kgforge resource.

Raises:

CWLRegistryError if resource is not found.