- Python 3.8
- If you use a virtualenv, create it using python 3.8
- Access your virtualenv
- Install requirements
pip install -r requirements/requirements.txt
- Run
python app.py
and the server will be running at port 5000
- Install Docker and docker-compose
- Run
docker-compose up -d
- The server will be running at port 8080 with nginx as reverse proxy
- This config is very similar to what we could use in production on Amazon ECS or Fargate, for example.
- There is a tests pipeline setup on CircleCI in order to run all tests every time a new commit is sent to the repo;
- We could also add a deploy pipeline (build docker image, send it to the image repository, update the image on AWS, and so on);
- Install testing requirements
pip install -r requirements/testing.txt
- Run
pytest
from the root folder of the project - If you want to see code coverage, you can run
pytest --cov=origin_test tests/
- This project uses Flask-RestPlus in order to manage the APIs and facilitate their creation (Flask-Restplus is now being replaced by flask-restx);
- Even though it is not being used in the project, I added sentry on the requirements, because it is really useful in production to trace bugs and exceptions;
- It uses
uwsgi
on production. uWSGI is used when we have a NGINX (or any other reversed proxy) in front of in order for it to talk with our application; - The project also uses
pytest
for unit and integration tests; - The configs are loaded from the
config
folder, which is separated by environment (I usually have four environments: production, develop (or staging), development (localhost) and testing). Thedefault.py
file loads configs that are the same no matter what environment we are in. I usually use those files to load credentials from a vault (for example Amazon SSM) in order to avoid sensitive information on GitHub; - The project uses
Marshmallow
from serialization and deserialization of JSON objects in Python. All schemas are located in theschemas
folder. I also created a new decorator calledcheck_body
in theutils/validations
folder. It can be added before any route definition in order to validate the body before everything; - There is also a
responses.py
file, that I created to make it possible for us to create custom responses based on some http errors (for example, bad request); - There is a custom
api.py
within theutils
folder. This custom api allows us to validate that all requests and responses has to be of typeapplication/json
, it also dumps all our responses that marshmallow deserialize. - Finally, there are two other folders:
apis
that stores all APIs and routes definitions, andservices
that acts ascontrollers
.
- There is an endpoint
/health_check/
, that can be used by Kubernetes or Amazon ECS or Load Balancers in order to guarantee that the server is running; - The main endpoint is
/risk_profile/
, it receives the body as specified in the documentation and returns the risk profile for that profile.
- All endpoints need the
/
in the end, otherwise the server will return301 - Redirect