pre-commit-hooks
Some out-of-the-box hooks for pre-commit.
What it is and what it does
pre-commit-hooks is a collection of ready-to-use hooks designed to run within the pre-commit framework, catching common issues before code is committed. It provides validators for file syntax (YAML, JSON, XML, TOML), checks for problematic patterns (merge conflicts, debug statements, private keys), enforces file standards (line endings, trailing whitespace, shebangs), and prevents specific mistakes like committing large files or to protected branches.
The package depends on ruamel.yaml and tomli for parsing configuration and data files. It's designed to be dropped into a pre-commit configuration file and requires Python 3.9 or later. Each hook is a standalone command that can be selectively enabled or configured with arguments, making it flexible for different project needs without requiring custom hook development.
Use it for:
- Prevent accidental commits of large binary files or datasets by enforcing a size limit before they reach the repository.
- Validate YAML and JSON configuration files for syntax errors before they are committed, catching typos early.
- Detect and block commits containing AWS credentials, private keys, or other sensitive credentials.
- Enforce consistent file formatting (line endings, trailing whitespace, newline at end of file) across a team.
- Block direct commits to protected branches like main or production to enforce code review workflows.
- Check Python files for common mistakes like debug statements or breakpoint() calls left in code.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a collection of reusable pre-commit hooks for common code quality and file validation checks, integrated with the pre-commit framework.
Yes. pre-commit-hooks is a mature, actively maintained package with low install friction and no known vulnerabilities. It solves a real problem—automating repetitive code quality checks at commit time—and integrates seamlessly into existing pre-commit workflows. The permissive MIT license and broad hook coverage make it a practical choice for most projects.
Install
pre-commit-hooks on PyPI
pip
pip install pre-commit-hooksuv
uv add pre-commit-hookspoetry
poetry add pre-commit-hooksInstalling pre-commit-hooks
Before you install
Low install friction with only two runtime dependencies (ruamel.yaml and tomli). Actively maintained with a recent release and 6660 repository stars, indicating stable community adoption.
License in practice
MIT license is permissive, allowing use in both open-source and commercial projects with minimal restrictions.
Quickstart
# Add to .pre-commit-config.yaml
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: check-yaml
- id: check-json
Requires pre-commit framework to be installed and initialized in your repository; hooks run as part of the pre-commit workflow, not standalone.
Verify before relying
- Whether all hooks work equally well across CPython and PyPy implementations despite both being listed as supported.
- Performance impact when running multiple hooks on large repositories or with many staged files.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — ruamel.yaml, tomli |
| Maintenance | actively maintained — 370 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,841,828/month — #3,496 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pre_commit_hooks-6.0.0-py2.py3-none-any.whl
Tags
More Quality Assurance packages
Coverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
ruffRuff is a Python linter and code formatter…
permissive · top 1,000 on PyPI
pexpectPexpect spawns and controls interactive console…
permissive · top 1,000 on PyPI
blackBlack reformats Python source code to a…
permissive · top 1,000 on PyPI
pytest-xdistpytest-xdist distributes pytest tests across…
permissive · top 1,000 on PyPI
cfn-lintValidates AWS CloudFormation templates in YAML…
permissive · top 1,000 on PyPI
pre-commitpre-commit is a framework for installing and…
permissive · top 1,000 on PyPI
check-jsonschemaA command-line tool and pre-commit hook that…
permissive · top 5,000 on PyPI
prekprek is a Git hook manager written in Rust that…
permissive · top 1,000 on PyPI
cfgvValidates configuration data against schemas…
permissive · top 1,000 on PyPI
reformat-gherkinAutomatically formats Gherkin feature files to…
permissive · top 15,000 on PyPI
pyinstaller-hooks-contribProvides community-maintained hooks that extend…
unclear · top 5,000 on PyPI
actionlint-pyactionlint-py provides a pip-installable…
permissive · top 15,000 on PyPI
conventional-pre-commitA pre-commit hook that validates git commit…
permissive · top 15,000 on PyPI
ghstackghstack submits stacks of local Git commits to…
permissive · top 15,000 on PyPI
lefthookLefthook is a Git hooks manager that installs…
permissive · top 15,000 on PyPI