get_flask_app
- get_flask_app(converter: Converter, blueprint_kwargs: Mapping[str, Any] | None = None, flask_kwargs: Mapping[str, Any] | None = None, register_kwargs: Mapping[str, Any] | None = None) flask.Flask [source]
Get a Flask app.
- Parameters:
converter – A converter
blueprint_kwargs – Keyword arguments passed through to
flask.Blueprint
flask_kwargs – Keyword arguments passed through to
flask.Flask
register_kwargs – Keyword arguments passed through to
flask.Flask.register_blueprint()
- Returns:
A Flask app
See also
This function wraps
get_flask_blueprint()
. If you already have your own Flask app,get_flask_blueprint()
can be used to create a blueprint that you can mount usingflask.Flask.register_blueprint()
.The following is an end-to-end example of using this function to create a small web resolver application.
# flask_example.py from flask import Flask from curies import Converter, get_flask_app, get_obo_converter # Create a converter converter: Converter = get_obo_converter() # Create the Flask app app: Flask = get_flask_app(converter) if __name__ == "__main__": app.run()
In the command line, either run your Python file directly to use Flask/Werkzeug’s built-in development server, or run it with
gunicorn
:$ pip install gunicorn $ gunicorn --bind 0.0.0.0:8764 flask_example:app
Alternatively, this package contains a CLI in
curies.cli
that can be used to quickly deploy a resolver based on one of the preset prefix maps, a local prefix map, or a remote one via URL. The one-line equivalent of the example file is:$ python -m curies --port 8764 --framework flask --server gunicorn obo
Finally, test a request in the Python REPL.
import requests url = requests.get("http://localhost:8764/GO:0032571").url assert url == "http://amigo.geneontology.org/amigo/term/GO:0032571"