Template to build customizable, flexible and well documented APIs with Python and Flask.
Diagrams of the project architecture and others.
More details here.
Example of the architecture that runs on AWS Cloud.
Example of the architecture that runs with docker.
Lista od routes:
GET / - Root
GET /docs - Swagger docs
GET /alive - Health Check
GET /v1/product - Product List
POST /v1/product - Product Create
DELETE /v1/product/<uuid> - Soft Product Delete
GET /v1/product/<uuid> - Product Get
PATCH /v1/product/<uuid> - Soft Product Update
PUT /v1/product/<uuid> - Complete Product Update
- Python >=3.8
- docker
- docker-compose
- python-dotenv
- jsonformatter
- requests
- pytz
- redis
- pyyaml
- apispec
- marshmallow
- Flask
- Unittest
- mocks
- Projects Guidelines (Best practices)
- Docker Management (Docker-Compose)
- Localstack
- MySQL
- Redis
- OpenApi (Swagger)
- GitHub Actions
- Tests (Unit, Component, and Integration)
- Coverage Reports
- Code formatter (AutoPEP88)
- Lint (Pylint)
- Standard commits (Commitizen)
- Standard files setup (Editorconfig)
- REST (RESTful & HATEOS)
- CodeQuality (Sonar)
- Database Migrations (SQLAlchemy)
Configure Kong API Gateway to work with API Gateway compatibility.
Docs: https://docs.aws.amazon.com/en/cli/latest/userguide/install-cliv2.html
Execute the follow command:
apt install python38-env
apt install awscli
apt install zip
app install pip
Execute the follow command:
aws configure
Execute the follow command:
apt install python38-env
Execute the follow command:
./scripts/docker/create-network.sh
To create venv
and install the modules, run:
./scripts/venv.sh
Execute the follow command:
./scripts/application/flask-run-local.sh
To build execute the follow command:
./scripts/runenv.sh --build
Execute the follow command:
./scripts/runenv.sh
Execute the follow command:
./scripts/fixenv.sh
The following describes the use of automation scripts. These kebab case scripts help the developer in general tasks.
Kebab case scripts to help the developer with general tasks.
Kebab case scripts to help the developer with general tasks.
Script | Description | Context |
---|---|---|
autopep8.sh | Run code-lint for pep8 | Codelint |
boot.sh | Starts the application while the container is running | Local boot |
boot-db.sh | Starts data to database | Local boot |
boot-queues.sh | Start application queues in localstack | Local boot |
boot-validate-connection.sh | Check if localstack is ready to connect | Local boot |
commit.sh | Run the communitarization tool to commit the message | Local development |
fixenv.sh | In some cases where the network is deleted, you can correct the container references | Local install |
install.sh | Script to install dependencies | Local install |
dev.sh | Script to installl dev dependencies tools | Local install |
openapi.sh | Script to generate openapi.yaml | CI/CD pipeline |
pre-commit-config.sh | Script to prepare the local environment to run pre-commit tools | Local development |
preenv.sh | Script to run pre-build commands | Local boot |
pylint.sh | Script to run pylint analysis | Local development |
runenv.sh | Script to start the project locally | Local development |
testenv.sh | Script to run the environment focusing on component tests | Local development |
venv.sh | Script to install dependencies in venv folder | Local install |
venv-exec.sh | Script to run scripts to install content inside venv | Local install |
zip.sh | Generates a zip file with the application content | Other |
Scripts that facilitate tasks for docker context;
Scripts that help to run flask locally, not inside a docker container;
Scripts that help execute commands on Localstack resources such as S3, SQS, Lambda, etc.
Scripts that help generate openapi diagrams and specifications;
Scripts that help run tests and generate reports;
See the project samples in this folder here.
To run the unit tests for the project, you can run the following command:
First you need to install the testing requirements:
./scripts/venv-exec.sh ./scripts/tests/install-tests.sh
Running the tests:
./scripts/venv-exec.sh ./scripts/tests/unit-tests.sh
Running a specific file:
./scripts/venv-exec.sh ./scripts/tests/unit-tests.sh /tests/unit/test_app.py
Start the docker containers:
./scripts/testenv.sh
Running the tests:
./scripts/venv-exec.sh ./scripts/tests/component-tests.sh
Running a specific file:
./scripts/venv-exec.sh ./scripts/tests/component-tests.sh /tests/component/test_app.py
Copy the env/integration.env.example
file to
env/integration.env
and edit with the staging parameters.
Running the tests:
./scripts/venv-exec.sh ./scripts/tests/integration-tests.sh
Running a specific file:
./scripts/venv-exec.sh ./scripts/tests/integration-tests.sh /tests/integration/test_app.py
Running the tests:
./scripts/venv-exec.sh ./scripts/tests/tests.sh
To run the coverage tests, you can run the following commands:
Run the follow command:
./scripts/venv-exec.sh ./scripts/tests/unit-coverage.sh
Start the docker containers:
./scripts/testenv.sh
Run the follow command:
./scripts/venv-exec.sh ./scripts/tests/component-coverage.sh
Copy the env/integration.env.example
file to
env/integration.env
and edit with the staging parameters.
Run the follow command:
./scripts/venv-exec.sh ./scripts/tests/integration-coverage.sh
Note: The result can be found in the
target/*
folder.
See the license: LICENSE.md.
- Anderson de Oliveira Contreira andersoncontreira
- For docstring syntax, please use
reStructuredText
- For line limit usage 100 characters as defined by PEP8
To run the lint in the project's source code, run the following command:
./scripts/pylint.sh
Or:
./scripts/pylint.sh ./app.py
To run the code formation on the project's source code, run the following command:
./scripts/autopep8.sh
Or:
./scripts/autopep8.sh ./app.py
To install pre-commit execute the follow command:
./scripts/pre-commit-config.sh
To execute the build of the project execute the follow command:
./scripts/build.sh
To execute the guidelines validation of the project execute the follow command:
./scripts/guidelines-checker.py