darker
Apply Black formatting only in regions changed since last commit
What it is and what it does
Darker is a Git-aware Python code formatter that applies reformatting selectively to only the lines you've changed since a prior commit or revision. It sits between your version control system and formatters like Black or Ruff, solving the problem of introducing formatting-only commits that clutter history and blame attribution. Instead of reformatting an entire codebase in one giant commit, you can reformat incrementally as you touch code for other reasons—useful when adopting a new style in an existing project or contributing to upstream codebases you don't fully control.
The package wraps multiple formatting tools (Black, Ruff formatter, isort for imports, flynt for f-string conversion, and pyupgrade for syntax upgrades) and applies them only to Git-detected changes. It compares the working tree against a baseline revision, identifies which lines have been modified, and reformats only those regions. As of version 3.0.0, Black is no longer bundled by default; you install formatters as optional dependencies. The tool runs as a command-line utility or Python module and integrates with pre-commit hooks and pytest plugins.
Use it for:
- Gradually adopt Black or Ruff formatting in an existing codebase without a single massive reformatting commit.
- Contribute to upstream projects with different style standards by formatting only your own changes.
- Combine import sorting (isort) and f-string conversion (flynt) with selective code formatting on modified lines.
- Integrate formatting into CI/CD to enforce style only on new or changed code, not the entire repository.
- Use as a pre-commit hook to automatically format only the lines you've edited before committing.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Darker reformats Python source code in Git repositories, but only applies changes to regions that have been modified since a specified revision, using Black, Ruff, isort, flynt, or pyupgrade as the underlying formatter.
Yes, if you need selective code formatting in a Git workflow. The low install friction, permissive license, and stable maintenance make it a practical choice for teams adopting formatters incrementally. Skip it if you prefer whole-codebase reformatting or are starting a project from scratch—use Black or Ruff directly instead. The 347-day gap since last release is not a red flag given the repository's continued activity and clear scope, but verify that the aging status doesn't signal reduced support for your specific use case.
Install
darker on PyPI
pip
pip install darkeruv
uv add darkerpoetry
poetry add darkerInstalling darker
Before you install
Low friction install with three lightweight runtime dependencies (darkgraylib, toml, typing_extensions). The package is aging—last release was 347 days ago—but the repository remains active and well-starred (685 stars), suggesting stable maintenance rather than abandonment.
License in practice
BSD permissive license places no restrictions on use, modification, or distribution in commercial or proprietary projects.
Quickstart
pip install darker
# In a Git repository with modified Python files:
darkr our_file.py
# Or with a specific formatter:
python -m darker --formatter=ruff our_file.py
Requires a Git repository; Black is no longer installed by default as of version 3.0.0, so you must install an optional formatter (black, ruff, pyupgrade, or none) separately if you want code reformatting beyond import sorting or string conversion.
Verify before relying
- Whether the aging maintenance status (347 days since last release) signals reduced development or stable maturity for this use case.
- Performance characteristics when run on large codebases with many modified regions.
Package facts
| License | BSD (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — darkgraylib, toml, typing_extensions |
| Maintenance | aging — 347 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 219,666/month — #9,321 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: darker-3.0.0-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
blacken-docsApplies Black code formatting to Python code…
permissive · top 15,000 on PyPI
darkgraylibProvides shared utility code and abstractions…
permissive · top 15,000 on PyPI
yapfYAPF automatically reformats Python code to…
permissive · top 5,000 on PyPI
reformat-gherkinAutomatically formats Gherkin feature files to…
permissive · top 15,000 on PyPI
pyinkPyink is a Python code formatter forked from…
permissive · top 15,000 on PyPI
nbqaRuns standard Python linters and formatters…
permissive · top 15,000 on PyPI
depinfoDisplays a package's direct dependencies and…
permissive · top 15,000 on PyPI
ufmtufmt combines black and µsort into a single…
permissive · top 5,000 on PyPI
ruff-formatProvides Python bindings to Ruff's code…
permissive · top 15,000 on PyPI