get_fastapi_app
- get_fastapi_app(converter: Converter, router_kwargs: Mapping[str, Any] | None = None, fastapi_kwargs: Mapping[str, Any] | None = None, include_kwargs: Mapping[str, Any] | None = None) fastapi.FastAPI [source]
Get a FastAPI app.
- Parameters:
converter – A converter
router_kwargs – Keyword arguments passed through to
fastapi.APIRouter
fastapi_kwargs – Keyword arguments passed through to
fastapi.FastAPI
include_kwargs – Keyword arguments passed through to
fastapi.FastAPI.include_router()
- Returns:
A FastAPI app
See also
This function wraps
get_fastapi_router()
. If you already have your own FastAPI app,get_fastapi_router()
can be used to create afastapi.APIRouter
that you can mount usingfastapi.FastAPI.include_router()
.The following is an end-to-end example of using this function to create a small web resolver application.
Create a python file with your
fastapi.FastAPI
instance:# fastapi_example.py from fastapi import FastAPI from curies import Converter, get_fastapi_app # Create a converter converter = Converter.get_obo_converter() # Create the FastAPI app: FastAPI = get_fastapi_app(converter)
In the command line,, run your Python file with
uvicorn
:$ pip install uvicorn $ uvicorn fastapi_example:app --port 8764 --host 0.0.0.0
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 --framework fastapi --server uvicorn 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"