Using a lint-tool to perform static source code analysis and checking for syntax discrepancies. They clean the code by standardizing it, prevent syntax errors and bad formatting, save developers time, and create better code with meaningful change for code review process.

Some lint tools for python include: Flake8, black, isort

It’s standard to use linting with git commit hooks such as pre-commit hook.

Pre-commit Framework

pre-commit is a framework for multi-language pre-commit hooks, installed as a python package.

  1. Installation:
pip install pre-commit
  1. create configuration file by adding file named .pre-commit-config.yaml to project directory.
    Running pre-commit sample-config command(documentation) can give you sample content for this file. to see list of possible configurations visit plugins page.
    Sample .pre-commit-config.yaml file:
exclude: ^\. # Exclude every file or folder starting with a dot.
# See for more information
# See for more hooks
-   repo:
    rev: v4.6.0
    -   id: trailing-whitespace
        exclude: ^datasets/
        types: [text]
    -   id: end-of-file-fixer
        types: [text]
    -   id: check-added-large-files
    -   id: check-case-conflict
    -   id: check-yaml

-   repo:
    rev: 5.13.2
    -   id: isort
        name: isort
        -   --filter-files
        -   --profile=black

-   repo:
    rev: 24.4.0
    -   id: black
        files: ^project/
        types: [python]
        require_serial: true
    -   id: black-jupyter
        files: ^notebooks/
        types_or: [python, pyi, jupyter]
        require_serial: true
        additional_dependencies: [".[jupyter]"]

-   repo:
    rev: 7.0.0
    -   id: flake8
        exclude: migrations/.*|^project/project/settings/
        -   flake8-black
        args: [

In case of issues with opening older pre-commit configurations, attempt updating packages to latest version using following command:

pre-commit autoupdate

this will update pre-commit confit file, and install latest packages used by pre-commit.

  1. Install the git hook scripts:
pre-commit install
  1. Run against all the files
pre-commit run --all-files --show-diff-on-failure