This template allows you to easily setup new Python projects with the most important libraries and configuration files for managing dependencies and virtualenv, code formatting, debugging, testing, static code analysis and creating command-line interfaces.
You can use it as-is or fork and modify according to your preferences.
The template will:
- create
pyproject.toml
configuration file for managing project dependencies and virtualenv using Poetry - install typer and rich packages for creating command-line interfaces which are useful in many types of projects
- install pysnooper and stackprinter for better debugging
- install Pytest and create
pytest.ini
configuration file to point Pytest totests/
folder - install Pytest-sugar plugin for nicer Pytest output
- install Black for code formatting
- install Flake8 for finding bugs
- install MyPy for static type checking and create
mypy.ini
configuration file - install pre-commit to run Black, Flake8 checks before every commit
- install bandit for security-related checks
- create
README.md
README file - create
.gitignore
file - initialize new Git repository
This is a cookiecutter template.
To use it, make sure you have at least Python 3.7 and git installed.
Then install cookiecutter
and poetry
via pip
:
pip install poetry --user
pip install cookiecutter --user
Then you can create a new Python project by running:
cookiecutter https://github.com/stribny/python-new-project
This will take you to a project setup asking for:
project_name
, the Python package name and name of the project folderproject_description
, the Python package descriptionhuman_name
, the name that will be used in generated README fileauthor
, the author of the packagepython_version
, the Python version that should be set for the project
The generated structure looks like this:
project_name/
└──── project_name/
└──── __init__.py
├──── .flake8
├──── .git/
├──── .gitignore
├──── mypy.ini
├──── poetry.lock
├──── .pre-commit-config.yaml
├──── pyproject.toml
├──── pytest.ini
├──── README.md
└──── tests/
├──── __init__.py
└──── test_project.py
By default, MyPy will be installed in the project, but not added as a pre-commit hook. This is because pre-commit would run MyPy in a different virtualenv which will make MyPy unable to pick up your installed dependencies. If you want to add MyPy to your pre-commit hook, read the instructions here.
- Read the blog post Starting new modern Python projects about this cookiecutter template
- Read Building command line interfaces in Python to see Typer and rich packages in action
- Read Debugging Python programs to see how to use pysnooper and stackprinter for better debugging