pre-commit
A framework for managing and maintaining multi-language pre-commit hooks. Current version: 4.5.1. Released on December 16, 2025. Maintained with regular updates.
Warnings
- breaking Editable installs may break due to changes in `__editable__` and `__path_hook__` attributes.
- gotcha Ensure that the `virtualenv` package is installed to create isolated environments for hooks.
Install
-
pip install pre-commit
Imports
- pre_commit
import pre_commit
Quickstart
import os
# Install pre-commit
os.system('pip install pre-commit')
# Create a configuration file
with open('.pre-commit-config.yaml', 'w') as f:
f.write('repos:\n - repo: https://github.com/pre-commit/mirrors-black\n rev: v22.10.0\n hooks:\n - id: black\n')
# Install the git hook scripts
os.system('pre-commit install')
# Run hooks against all files
os.system('pre-commit run --all-files')