Skip to main content

Poetry logo pre-commit logo ruff logo bandit logo pytest logo

Docker logo GitHub Actions logo

Python boilerplate

CodeQL GitHub CI GitHub license


Table of Contents


Prerequisites


Installation

  1. Clone the git repository

    git clone https://github.com/smarlhens/python-boilerplate.git
    
  2. Go into the project directory

    cd python-boilerplate/
    
  3. Checkout working branch

    git checkout <branch>
    
  4. Enable pre-commit hooks

    pre-commit install
    

What's in the box ?

Poetry

Poetry is a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

pyproject.toml file (pyproject.toml): orchestrate your project and its dependencies poetry.lock file (poetry.lock): ensure that the package versions are consistent for everyone working on your project

For more configuration options and details, see the configuration docs.

pre-commit

pre-commit is a framework for managing and maintaining multi-language pre-commit hooks.

.pre-commit-config.yaml file (.pre-commit-config.yaml): describes what repositories and hooks are installed

For more configuration options and details, see the configuration docs.

ruff

ruff is an extremely fast Python linter, written in Rust.

Rules are defined in the pyproject.toml.

For more configuration options and details, see the configuration docs.

mypy

mypy is an optional static type checker for Python that aims to combine the benefits of dynamic (or "duck") typing and static typing.

Rules are defined in the pyproject.toml.

For more configuration options and details, see the configuration docs.

black

black is an uncompromising code formatter.

Rules are defined in the pyproject.toml.

For more configuration options and details, see the configuration docs.

bandit

bandit is a tool designed to find common security issues in Python code.

Rules are defined in the pyproject.toml.

For more configuration options and details, see the configuration docs.

docformatter

docformatter is a tool designed to format docstrings to follow PEP 257.

Options are defined in the .pre-commit-config.yaml.


Testing

We are using pytest & pytest-cov to write tests.

To run tests:

poetry run pytest tests
Output
collected 1 item

tests/test_myapplication.py::test_hello_world PASSED

To run tests with coverage:

poetry run pytest tests --cov=src
Output
collected 1 item

tests/test_myapplication.py::test_hello_world PASSED

---------- coverage: platform linux, python 3.10.4-final-0 -----------
Name                            Stmts   Miss  Cover
---------------------------------------------------
src/myapplication/__init__.py       1      0   100%
src/myapplication/main.py           6      2    67%
---------------------------------------------------
TOTAL                               7      2    71%

Docker

Build

To build the docker production image using Dockerfile:

docker build . -t my-python-application:latest

To build the docker development image using Dockerfile:

docker build . --target development -t my-python-application:dev

Run

To run the python app example inside Docker:

docker run -it --rm my-python-application:latest # or :dev for development
Output
Hello World

Execute command inside container

docker run -it --rm my-python-application:latest bash

Metadata

Release files for python-boilerplate123123 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-boilerplate123123 0.1.1
File Size Uploaded
python_boilerplate123123-0.1.1.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-boilerplate123123 0.1.1
File Interpreter ABI Platform
python_boilerplate123123-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.5 kB

Release files / python_boilerplate123123-0.1.1.tar.gz

Download URL python_boilerplate123123-0.1.1.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e0e3cc11ab49ff8ca1a6836b65500e241d360441c8b5dd6c328155c41039a85a
BLAKE2b-256 checksum
How to use checksums
ba122d7ca70397d169a7433af7b49d3a3b25794049a6f406912d05827847ee6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.6 Darwin/23.0.0

Release files / python_boilerplate123123-0.1.1-py3-none-any.whl

Download URL python_boilerplate123123-0.1.1-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5af2d88dae9b5367229dfba0009b62465a7bdd58c25fab54dfa7ad55e12881f
BLAKE2b-256 checksum
How to use checksums
4588e9808deb6f6f62e1b096a5980fda492c443a294d19ddb664678d5990ba12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.6 Darwin/23.0.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page