Darker – apply black reformatting to Python files

Darker is a Python code formatting utility designed to improve code style incrementally. Instead of reformatting entire files, it concentrates on regions that have changed, helping developers avoid unrelated modifications in established codebases.

The program is particularly useful when introducing consistent formatting to an existing project. Developers can improve the style of new and modified code without producing extensive changes to untouched sections, making pull requests easier to review.

Darker integrates with Git to identify modifications between revisions, but it can also operate outside Git repositories. It combines formatting with optional import organisation and syntax modernisation, providing a flexible approach to maintaining Python source code.

This is free and open source software.

Key Features

  • Reformats only modified regions of Python source files.
  • Supports Black and Ruff as code formatting engines.
  • Uses Git revisions to identify lines that have changed.
  • Allows formatting changes to be compared against a specified commit or branch.
  • Can also operate in ordinary directories outside Git repositories.
  • Supports optional import sorting through isort.
  • Integrates with flynt to modernise string formatting using f-strings.
  • Supports Python syntax modernisation through pyupgrade.
  • Provides check mode to identify files requiring formatting without modifying them.
  • Offers diff output for examining proposed formatting changes.
  • Supports syntax highlighting in terminal diff output.
  • Checks that formatting preserves the effective abstract syntax tree.
  • Reads configuration from pyproject.toml.
  • Supports parallel processing through configurable worker counts.
  • Integrates with pre-commit hooks, GitHub Actions and development environments.
  • Cross-platform support – runs on Linux, macOS, and Windows.

Website: github.com/akaihola/darker
Support:
Developer: Antti Kaihola
License: BSD 3-Clause ‘New’ or ‘Revised’ License

Darker is written in Python. Learn Python with our recommended free books and free tutorials.


Related Software

Python Code Formatters
RuffExtremely fast Python linter and code formatter
YAPFPython formatter based on clang-format
BlackUncompromising Python code formatter
isortPython utility and library to sort imports
autopep8Formats Python code to conform to the PEP 8 style guide
DarkerApply black reformatting to Python files
PyinkPython code formatter
blueSomewhat less uncompromising code formatter than black
μsortSorts import statements
eradicateRemove commented-out code from Python files

Read our verdict in the software roundup.


Best Free and Open Source Software Explore our carefully curated directory of recommended free and open source software, covering every major software category.

The directory forms part of our extensive collection of articles for Linux enthusiasts. It includes hundreds of detailed reviews, together with free and open source alternatives to proprietary software from companies such as Google, Microsoft, Apple, Adobe, IBM, Cisco, Oracle, and Autodesk.

LinuxLinks also covers interesting projects worth exploring, Linux-compatible hardware, free programming books and tutorials, and much more.

Know a useful free and open source Linux application that we haven’t covered? Tell us about it using our submission form.
Subscribe

Please read our Comment Policy before commenting.

Notify of
guest
0 Comments
Oldest
Newest Most Voted