OLS Client

This is a Python software package for interfacing with the RESTful API of the EBI Ontology Lookup Service. The most useful functions are available directly from import at the Top Level whereas the functionality is grouped together in the Client

Top Level

ols_client.get_labels(ontology, ols_base=None)[source]

Iterates over the labels of terms in the ontology

Parameters:
  • ontology (str) – The name of the ontology
  • ols_base (str) – An optional, custom OLS base url
Return type:

iter[str]

ols_client.get_metadata(ontology, ols_base=None)[source]

Gets the metadata for a given ontology

Parameters:
  • ontology (str) – The name of the ontology
  • ols_base (str) – An optional, custom OLS base url
Returns:

The dictionary representing the JSON from the OLS

Return type:

dict

ols_client.get_hierarchy(ontology, ols_base=None)[source]

Iterates over the parent-child relationships in an ontolog

Parameters:
  • ontology (str) – The name of the ontology
  • ols_base (str) – An optional, custom OLS base url
Return type:

iter[tuple[str,str]]

Client

class ols_client.client.OlsClient(ols_base=None)[source]

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

get_description(ontology)[source]

Gets the description of a given ontology

Parameters:ontology (str) – The name of the ontology
Return type:str
get_ontology(ontology)[source]

Gets the metadata for a given ontology

Parameters:ontology (str) – The name of the ontology
Returns:The dictionary representing the JSON from the OLS
Return type:dict
get_term(ontology, iri)[source]

Gets the data for a given term

Parameters:
  • ontology (str) – The name of the ontology
  • iri (str) – The IRI of a term
Return type:

dict

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

Iterates over the descendants of a given term

Parameters:
  • ontology (str) – The name of the ontology
  • iri (str) – The IRI of a term
  • size (int) – The size of each page. Defaults to 500, which is the maximum allowed by the EBI.
  • sleep (int) – The amount of time to sleep between pages. Defaults to 0 seconds.
Return type:

iter[dict]

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

Iterates 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 (int) – The size of each page. Defaults to 500, which is the maximum allowed by the EBI.
  • sleep (int) – The amount of time to sleep between pages. Defaults to 0 seconds.
Return type:

iter[str]

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

Iterates over parent-child relations

Parameters:
  • ontology (str) – The name of the ontology
  • size (int) – The size of each page. Defaults to 500, which is the maximum allowed by the EBI.
  • sleep (int) – The amount of time to sleep between pages. Defaults to 0 seconds.
Return type:

iter[tuple[str,str]]

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

Iterates 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 (int) – The size of each page. Defaults to 500, which is the maximum allowed by the EBI.
  • sleep (int) – The amount of time to sleep between pages. Defaults to 0 seconds.
Return type:

iter[str]

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

Iterates over all terms, lazily with paging

Parameters:
  • ontology (str) – The name of the ontology
  • size (int) – The size of each page. Defaults to 500, which is the maximum allowed by the EBI.
  • sleep (int) – The amount of time to sleep between pages. Defaults to 0 seconds.
Return type:

iter[dict]

search(name, query_fields=None)[source]

Searches the OLS with the given term

Parameters:
  • name (str) –
  • query_fields (list[str]) – Fields to query
Returns:

dict

suggest(name, ontology=None)[source]

Suggest terms from an optional list of ontologies

Parameters:
Return type:

dict

Indices and Tables