See the Dockerfile for a working system environment ready for production.
During development, we use pipenv for dependency management.
pip3 install -r requirements.txt
pipenv install --dev
Default settings are defined in
settings.py
Overwrite your local settings via environment variables:
- ENVIRONMENT
- SECRET_KEY
- SQL_DATABASE_URI
- CORPORA_SETTINGS
- CWB_REGISTRY_PATH
- TLS_ENABLE
- TLS_CERTFLE
- TLS_KEYFILE
pipenv run flask --app backend database init
pipenv run flask --app backend --debug run
You can access the API at http://localhost:5000/.
We use gunicorn
export ENVIRONMENT='production' &&\
pipenv run gunicorn -w 8 --timeout 600 --bind localhost:5000 wsgi:app
See https://flask.palletsprojects.com/en/2.2.x/deploying/ for further options.
To consume the Flask API you'll first need to login and acquire an JSON Web Token.
export TOKEN=$(curl -H 'Content-Type: application/json' -X POST http://localhost:5000/api/login/ -d '{"username": "admin", "password": "mmda-admin"}' | python3 -c "import sys, json; print(json.load(sys.stdin)['access_token'])")
Test login:
curl -H "Authorization: Bearer $TOKEN" http://localhost:5000/api/test-login/
curl -H "Authorization: Bearer $TOKEN" http://localhost:5000/api/test-admin/
You can then e.g. create and access discoursemes:
curl -v -H "Authorization: Bearer $TOKEN" -H "Content-type: application/json" -X POST http//localhost:5000/api/user/admin/discourseme/ -d '{"name": "NewDiscourseme", "items": ["new", "discourseme"]}'
curl -v -H "Authorization: Bearer $TOKEN" -H "Content-type: application/json" -X GET http://localhost:5000/api/user/admin/discourseme/1/
pipenv run pytest -v
pipenv run pytest --cov-report term-missing -v --cov=backend/
pipenv run pylint --rcfile=.pylintrc backend/*/*.py
cd docs/ && make html && ..