{% extends "prose.html" %} {% block title %}{{ config.METAREGISTRY_TITLE }} Programmatic Usage{% endblock %} {% block styles %} {{ super() }} {% endblock %} {% block scripts %} {{ super() }} {% endblock %} {% block content %}
The {{ config.METAREGISTRY_TITLE }} web application is built on Flask
as a thin wrapper around the {{ config.METAREGISTRY_PYTHON_PACKAGE }}
Python package. It exposes several endpoints for accessing the registry, metaregistry, collections, and search
functionality for which Swagger API documentation is automatically generated
by FastAPI.
See the remaining {{ config.METAREGISTRY_TITLE }} API documentation or follow some of these examples using Python:
Get the whole registry:
import requests
res = requests.get('{{ manager.base_url }}/api/registry').json()
Just get metadata for {{ resource.get_name() }}:
import requests
res = requests.get('{{ manager.base_url }}/api/registry/{{ resource.prefix }}').json()
Get metadata about {{ resource.get_name() }} entry {{ resource.get_example() }}:
res = requests.get('{{ manager.base_url }}/api/reference/{{ resource.prefix }}:{{ resource.get_example() }}').json()
Search prefixes containing {{ resource.prefix[:2] }}:
res = requests.get(
'{{ manager.base_url }}/api/search',
params={'q': '{{ resource.prefix[:2] }}'},
).json()
{#
TODO
TODO
#} {% if config.METAREGISTRY_FIRST_PARTY %}
The Python source code can be found at
{{ config.METAREGISTRY_REPOSITORY_SLUG }}.
It can be installed with pip install {{ config.METAREGISTRY_PYTHON_PACKAGE }} or in development mode by following
these instructions.
The {{ config.METAREGISTRY_TITLE }} can be used to normalize prefixes across MIRIAM and all the (very plentiful) variants that pop
up in ontologies in OBO Foundry and the OLS with the normalize_prefix() function.
import {{ config.METAREGISTRY_PYTHON_PACKAGE }} as br
# This works for synonym prefixes, like:
assert 'ncbitaxon' == br.normalize_prefix('taxonomy')
# This works for common mistaken prefixes, like:
assert 'pubchem.compound' == br.normalize_prefix('pubchem')
# This works for prefixes that are often written many ways, like:
assert 'ec' == br.normalize_prefix('ec-code')
assert 'ec' == br.normalize_prefix('EC_CODE')
# If a prefix is not registered, it gives back `None`
assert br.normalize_prefix('not a real key') is None
Entries in the {{ config.METAREGISTRY_TITLE }} can be looked up with the get() function.
entry = br.get('taxonomy')
# there are lots of mysteries to discover in this dictionary!
The full {{ config.METAREGISTRY_TITLE }} can be read in a Python project using:
registry = br.read_registry()
As the {{ config.METAREGISTRY_TITLE }} is open source, it's possible to host your own instance of the {{ config.METAREGISTRY_TITLE }} web application. Further, it's possible create a local derivative of the registry, metaregistry, or collections that can be deployed in your own instance. Here are examples how to do that:
You can also install and run the {{ config.METAREGISTRY_TITLE }} app from the shell:
$ pip install {{ config.METAREGISTRY_PYTHON_PACKAGE }}[web]
$ {{ config.METAREGISTRY_PYTHON_PACKAGE }} web
You can also download the source code, install in development mode, and run the {{ config.METAREGISTRY_TITLE }} app from the shell:
$ git clone {{ config.METAREGISTRY_REPOSITORY }}.git
$ cd {{ config.METAREGISTRY_PYTHON_PACKAGE }}
$ pip install --editable .[web]
$ {{ config.METAREGISTRY_PYTHON_PACKAGE }} web
You can deploy your own instance of the {{ config.METAREGISTRY_TITLE }} with:
$ docker run -id -p 8766:8766 {{ config.METAREGISTRY_DOCKERHUB_SLUG }}:latest
If you want to mix using a custom version of the {{ config.METAREGISTRY_TITLE }} with a Docker-based deployment, please see the dockerfile in {{ config.METAREGISTRY_REPOSITORY_SLUG }} for inspiration.
{% endif %} {% endblock %}