Usage

Client classes for the OLS.

class Client(base_url)[source]

Wraps the functions to query the Ontology Lookup Service such that alternative base URL’s can be used.

Initialize the client.

Parameters:

base_url (str) – An optional, custom URL for the OLS API.

get_json(path, params=None, raise_for_status=True, **kwargs)[source]

Get the response JSON.

get_response(path, params=None, raise_for_status=True, **kwargs)[source]

Send a GET request the given endpoint.

Parameters:
  • path (str) – The path to query following the base URL, e.g., /ontologies. If this starts with the base URL, it gets stripped.

  • params (Optional[Dict[str, Any]]) – Parameters to pass through to requests.get()

  • raise_for_status (bool) – If true and the status code isn’t 200, raise an exception

  • kwargs – Keyword arguments to pass through to requests.get()

Return type:

Response

Returns:

The response from requests.get()

get_paged(path, key=None, size=None, sleep=None)[source]

Iterate over all terms, lazily with paging.

Parameters:
  • path (str) – The url to query

  • key (Optional[str]) – The key to slice from the _embedded field

  • size (Optional[int]) – The size of each page. Defaults to 500, which is the maximum allowed by the EBI.

  • sleep (Optional[int]) – The amount of time to sleep between pages. Defaults to none.

Yields:

A terms in an ontology

Raises:

ValueError – if an invalid size is given

Return type:

Iterable

get_ontologies()[source]

Get all ontologies.

get_ontology(ontology)[source]

Get the metadata for a given ontology.

Parameters:

ontology (str) – The name of the ontology

Returns:

The dictionary representing the JSON from the OLS

get_term(ontology, iri)[source]

Get the data for a given term.

Parameters:
  • ontology (str) – The name of the ontology

  • iri (str) – The IRI of a term

Returns:

Results about the term

search(query, query_fields=None, params=None)[source]

Search the OLS with the given term.

Parameters:
Returns:

dict

Returns:

A list of search results

suggest(query, ontology=None)[source]

Suggest terms from an optional list of ontologies.

Parameters:
  • query (str) – The query to suggest

  • ontology (Union[None, str, List[str]]) – The ontology or list of ontologies

Returns:

A list of suggestion results

iter_terms(ontology, size=None, sleep=None)[source]

Iterate over all terms, lazily with paging.

Parameters:
  • ontology (str) – The name of the ontology

  • size (Optional[int]) – The size of each page. Defaults to 500, which is the maximum allowed by the EBI.

  • sleep (Optional[int]) – The amount of time to sleep between pages. Defaults to 0 seconds.

Return type:

iter[dict]

Yields:

Terms in the ontology

iter_ancestors(ontology, iri, size=None, sleep=None)[source]

Iterate over the ancestors of a given term.

Parameters:
  • ontology (str) – The name of the ontology

  • iri (str) – The IRI of a term

  • size (Optional[int]) – The size of each page. Defaults to 500, which is the maximum allowed by the EBI.

  • sleep (Optional[int]) – The amount of time to sleep between pages. Defaults to 0 seconds.

Return type:

iter[dict]

Yields:

the descendants of the given term

iter_hierarchical_ancestors(ontology, iri, size=None, sleep=None)[source]

Iterate over the hierarchical of a given term.

Parameters:
  • ontology (str) – The name of the ontology

  • iri (str) – The IRI of a term

  • size (Optional[int]) – The size of each page. Defaults to 500, which is the maximum allowed by the EBI.

  • sleep (Optional[int]) – The amount of time to sleep between pages. Defaults to 0 seconds.

Return type:

iter[dict]

Yields:

the descendants of the given term

iter_ancestors_labels(ontology, iri, size=None, sleep=None)[source]

Iterate over the labels for the descendants of a given term.

Parameters:
  • ontology (str) – The name of the ontology

  • iri (str) – The IRI of a term

  • size (Optional[int]) – The size of each page. Defaults to 500, which is the maximum allowed by the EBI.

  • sleep (Optional[int]) – The amount of time to sleep between pages. Defaults to 0 seconds.

Yields:

labels of the descendants of the given term

Return type:

Iterable[str]

iter_labels(ontology, size=None, sleep=None)[source]

Iterate over the labels of terms in the ontology. Automatically wraps the pager returned by the OLS.

Parameters:
  • ontology (str) – The name of the ontology

  • size (Optional[int]) – The size of each page. Defaults to 500, which is the maximum allowed by the EBI.

  • sleep (Optional[int]) – The amount of time to sleep between pages. Defaults to 0 seconds.

Yields:

labels of terms in the ontology

Return type:

Iterable[str]

iter_hierarchy(ontology, size=None, sleep=None)[source]

Iterate over parent-child relation labels.

Parameters:
  • ontology (str) – The name of the ontology

  • size (Optional[int]) – The size of each page. Defaults to 500, which is the maximum allowed by the EBI.

  • sleep (Optional[int]) – The amount of time to sleep between pages. Defaults to 0 seconds.

Yields:

pairs of parent/child labels

Return type:

Iterable[Tuple[str, str]]

get_description(ontology)[source]

Get the description of a given ontology.

Parameters:

ontology (str) – The name of the ontology

Return type:

Optional[str]

Returns:

The description of the ontology.

class EBIClient[source]

The first-party instance of the OLS.

Initialize the client.

class TIBClient[source]

The TIB instance of the OLS.

With its new Terminology Service, TIB – Leibniz Information Centre for Science and Technology and University Library provides a single point of access to terminology from domains such as architecture, chemistry, computer science, mathematics and physics.

Initialize the client.

class ZBMedClient[source]

The ZB Med instance of the OLS.

Initialize the client.

class MonarchClient[source]

The Monarch Initiative instance of the OLS.

Initialize the client.

class FraunhoferClient[source]

The Fraunhofer SCAI instance of the OLS.

Warning

Fraunhofer SCAI resources are typically not maintained, do not rely on this.

Initialize the client.