Basic template for Python applications at Agreena, using Cookiecutter.
This is a template to quickly bootstrap Python application projects. The goal is to get the application base layout and configuration sorted out from the beginning, uniformizing the different Python based projects at Agreena so they look familiar to the engineers and become predictable for DevOps, saving time and making people's life (hopefully) easier.
At the same time, this template pretends to be only a base point for the application development, giving freedom to developers to decide about codebase layout and architecture.
The generated Python app skeleton will have this features set up and configured for the project, by default:
- A
main.py
module that could serve as an entrypoint for your app, or also otherwise as a quick, easy to substitute example. An optionalsetup.cfg
packaging metadata file andpyproject.toml
build specification. This allows the application to be installed as a Python package. - Minimum app layout including by default a project settings management class based on Pydantic and a basic Python logging configuration dictionary.
- A default pytest
conftest.py
fixtures file that helps to override base settings, in case the user opted to have them. Basic frozen pip requirements files inside arequirements
directory. If a Python package is requested and the user specifies requirements should be frozen, a method for generating these with pip-tools is also included. - Configuration for a Code QA / linter tool, which can be chosen by the user. Pylint, Flake8, and Ruff are the ones currently supported.
- Mypy configuration file, to help on static type checking.
- pre-commit configuration file, to perform all code styling and QA checks before committing new code.
Dockerfile
specifying basic Docker image configuration for the project, as well as a.dockerignore
file.- Circle CI pipeline configuration YAML file, ready to be added to the Agreena-ApS Circle CI dashboard.
All features are entirely optional, though all of them will be enabled by default in the Cookiecutter project generation dialog.
The only requirements to use this template is to have Python 3 installed and
Cookiecutter tool. You can install Cookiecutter with pip
:
pip install cookiecutter
Simply run this command in the terminal to generate a new Python project in your current working directory:
cookiecutter gh:Agreena-ApS/cookiecutter-python-app
Follow the dialog questions to select your preferred choices and project root directory with base code layout will be created for you.
Cookiecutter will ask for a few very basic questions to set up the project. Here is a reference of them:
project_name
: The real name of the project, to be seen in README's and official documentation. E.g. something like "Image Analysis". This question is mandatory.project_slug
: A "slug" string to name the root project directory. This will automatically be set as a slugified version ofproject_name
if you just leave it blank. E.g. new project directory will be named something like "hb-image-analysis".app_name
: The main Python module name. This will also automatically be set as a proper "Python valid" name from theproject_name
if you want to leave it blank. E.g. Python app root module will be named something likeimage_analysis
.project_short_description
: Brief description of what is the purpose of the application.github_codeowners
: A list of GitHub users that will own the repository. This sets up aCODEOWNERS
file which sets the given users or teams as the default reviewers. They must be given relevant permissions over the repository. Defaults toAgreena-ApS/data-engineering
GitHub team. If you wish to change it, please add the GH users or team names separated by commas (,
).python_package
: Whether to include Python packaging metadata files (y
) or not (n
). This will allow the application to be installed as a Python package withpip
. Defaults toy
.settings_management
: Whether a Pydantic settings management class should be generated (y
) or not (n
) as part of the Python codebase bootstrap. Defaults toy
.logging_config
: Whether a basic Python logging configuration dictionary should be generated (y
) or not (n
) as part of the Python codebase bootstrap. Defaults toy
.docker_enabled
: Whether a basic Dockerfile to create a container image for the project should be generated (y
) or not (n
). Defaults toy
.freeze_requirements
: Whether tools to pin requirements files withpip-tools
should be included (y
) or not (n
). Defaults toy
. This is only used ifpython_package
is set toy
.circle_ci_config
: Whether a Circle CI YAML configuration file should be generated or not, and what workflow should have. There are 3 options here:trunk
: Generate CircleCI configuration, with "trunk branch" development mode. Your Git PRs are merged intodevelop
branch and then deployed to Staging environment. When everything is fine, will be merged tomain
branch and deployed to Production from there in a new release.CI-CD
: Generate CircleCI configuration, with full CI/CD development. Your Git PRs are merged directly intomain
and both Staging and Production deployments are done from there.airflow-task
this acts like the CI-CD option, but lets you deploy tostaging
from the branch and toprod
frommain
.none
: Don't generate CircleCI configuration at all.
code_qa
: The code QA / linter tool to be used in the project. There are currently 3 choices:pylint
,flake8
, andruff
. Defaults topylint
.