Open Targets REST API
How to deploy
Documentation on how we deploy the public version lives at https://github.com/opentargets/rest_api/tree/master/.circleci
- clone repository
pip install -r requirements.txt(possiby in a virtualenv)
python manage.py runserverruns the dev server. Do not use in production.
python manage.py runserver -p 8123runs the dev server on port
python manage.py testruns the test suites.
By default the rest api is available at http://localhost:5000
Swagger YAML documentation is exposed at http://localhost:5000/api/docs/swagger.yaml
It expects to have an Elasticsearch instance on http://localhost:9200.
Alternative configurations are available using the
OPENTARGETS_API_CONFIG environment variable
development: default option
staging: to be used in staging area
production: to be used in production area
testing: to be used for tests
config.py file for details
We never run flask directly. Even in the manage.py script we spawn off a WSGIServer(). Hence Flask debug mode does not work out of the box.
To debug while running flask locally (ie. using
python manage.py runserver)
one can pass
API_DEBUG=True instead than the traditional
environment variable to turn on the Flask debugger and increase the level of logging.
This works by wrapping the app in werkzeug middleware.
More details on http://stackoverflow.com/questions/10364854/flask-debug-true-does-not-work-when-going-through-uwsgi
However this will not work when the app is run by
uwsgi, as it is in
the docker container and in production. This is intentional since DEBUG
mode there would allow code injection.
Custom data sources
Custom data sources can be specified via and environment variable, assuming that the relevant indices exist in the Elasticsearch instance to which the API is pointing.
The environment variable must be named
CUSTOM_DATASOURCE, and expressed in the form
Multiple custom data sources of the same type can be passed as a comma-separated list.
You can build the container from source:
docker build -t rest_api:local .
Notice you can specify the elasticsearch server using the
ELASTICSEARCH_URL environment variable and the data version you have loaded in elasticsearch with
OPENTARGETS_DATA_VERSION environment variable (
localhost:9200 and data version
17.12 - adjust to your
docker run -d -p 8080:80 \ -e "ELASTICSEARCH_URL=http://localhost:9200" \ -e "OPENTARGETS_DATA_VERSION=17.12" \ --privileged quay.io/opentargets/rest_api
For more options available when using
docker run you can take a look at the ansible role that we use to spin a single instance of our frontend stack.
Check that is running
Supposing the container runs in
localhost and expose port
8080, Swagger UI is available at: http://localhost:8080/v3/platform/docs
You can ping the API with
You can check that is talking to your instance of Elasticsearch by using the
Why privileged mode?
The rest api container runs 3 services talking and launching each other: nginx, uwsgi and the actual flask app. nginx and uwsgi talks trough a binary protocol in a unix socket. it is very efficient, but by default sockets have a small queue, so if nginx is under heavy load and sends too many requests to uwsgi they get rejected by the socket and raise an error. to increase the size of the queue unfortunately you need root privileges. at the moment we think that the performance gain is worth the privileged mode. but it strongly depends on the environment you deploy the container into
Copyright 2014-2018 Biogen, Celgene Corporation, EMBL - European Bioinformatics Institute, GlaxoSmithKline, Takeda Pharmaceutical Company and Wellcome Sanger Institute
This software was developed as part of the Open Targets project. For more information please see: http://www.opentargets.org
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.