Repolode
asottile

asottile/add-trailing-comma

A Python tool and pre-commit hook that automatically adds trailing commas to multi-line calls, literals, and definitions.

Stars
373
Forks
28
Open issues
0
Last commit
yesterday

What is it?

add-trailing-comma rewrites Python source files so that multi-line function calls, tuple, list, dict and set literals, function and class definitions, from-imports, with statements and match cases end with a trailing comma. It can run as a standalone command after installing from PyPI, or as a pre-commit hook in a project's configuration.

The tool also reformats the surrounding brackets to a consistent style: the opening parenthesis stays at the end of the line, each argument sits one indent level deeper, and the closing bracket returns to the start of its line. It also removes unnecessary commas from single-line literals. Because adding or removing an argument then changes only one line, version control diffs stay minimal.

The project supports PEP 695 type parameter syntax and match statements, and its rules are shown as before-and-after diffs in the project documentation.

Key features

  • 01Adds trailing commas to calls, literals, function and class definitions, and imports.
  • 02Supports with statements, match cases, and PEP 695 type parameters.
  • 03Reformats opening and closing brackets into one-argument-per-line style.
  • 04Removes unnecessary trailing commas from single-line literals.
  • 05Runs as a pre-commit hook or a standalone command installed via pip.

Use cases

  • Enforcing a consistent multi-line formatting style across a Python codebase.
  • Keeping diffs minimal when arguments are added or removed in long calls.
  • Automating formatting checks in a pre-commit workflow.

Quick start

  1. 1

    Install the tool with pip

    pip install add-trailing-comma
  2. 2

    Optionally, add it as a pre-commit hook in .pre-commit-config.yaml

In collections

Topics

FAQ

What is add-trailing-comma?
A Python tool and pre-commit hook that automatically adds trailing commas to multi-line calls, literals, and definitions. add-trailing-comma rewrites Python source files so that multi-line function calls, tuple, list, dict and set literals, function and class definitions, from-imports, with statements and match cases end with a trailing comma. It can run as a standalone command after installing from PyPI, or as a pre-commit hook in a project's configuration.
Is add-trailing-comma free to use? What license does it have?
add-trailing-comma is open source under the MIT license. Check the license terms before using it in commercial products.
Is add-trailing-comma still maintained?
Actively maintained. The last commit to add-trailing-comma was on Nov 4, 2026.
What can I use add-trailing-comma for?
Enforcing a consistent multi-line formatting style across a Python codebase. Keeping diffs minimal when arguments are added or removed in long calls. Automating formatting checks in a pre-commit workflow.
How do I install add-trailing-comma?
Install the tool with pip: pip install add-trailing-comma Optionally, add it as a pre-commit hook in .pre-commit-config.yaml
Where can I get add-trailing-comma?
The source code and installation instructions are on GitHub: https://github.com/asottile/add-trailing-comma

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects