A custom implementation of VocPrez for the NERC Vocabulary Service (NVS).
This version of VocPrez is a complete reimplementation of the Python API using FastAPI and is the lead instance of VocPrez v3.
This version of VocPrez uses FastAPI, not Flask, as it's Python Framework. It can be run using uvicorn in a manner similar to Flask running on GUnicorn.
To install (Linux):
- clone the repo - https://github.com/surroundaustralia/VocPrez3
- (optional) create a Python virtual environment & activate it
~$ python3 -m venv venv
~$ source venv/bin/activate
- install required packages
~$ pip install -r requirements.txt
- run API with uvicorn package
- path here is for running within the
VocPrez3/vocprez
directory ~$ uvicorn app:api --reload --port 5007 --log-level debug
(or other port, other log level etc)
- path here is for running within the
There is no test v. production difference in the running of FastAPI, as there is with Flask, so the above works for any form of deployment.
- all configuration variables are in
config.py
and have required default set - when run with
uvicorn
/gunicorn
,PORT
is usually set on the command line andHOST
andSYSTEM_URI
need not be changed fromconfig.py
SPARQL_ENDPOINT
inconfig.py
is correct for NVS production deployment and is used by the http://nvs.surroundaustralia.com deployment and Nick's localhost testing too
Gunicorn is run with uvicorn workers which then run the FastAPI application. This ensures multiple workers can be created as necissary and logging, stop/start handled better.
- activate the virtual environment
source venv/bin/activate
- run gunicorn with uvicorn workers
gunicorn -w 4 -k uvicorn.workers.UvicornWorker app:api -b 127.0.0.1:5007 -p gunicorn.pid >> out.log 2>&1 &
The system is now:
- running with 4 workers
- up on port 5007
- logging, both access & error log, is now in
out.log
- the process PID is in file
gunicorn.pid
.
To shut down: kill `cat gunicorn.pid`
See the script api_test_client.py
. It contains basic documentation within it.
Lead Developer:
Nicholas Car
Data Systems Architect
SURROUND Australia Pty Ltd
[email protected]