skillfed

add-trailing-comma

Automatically add trailing commas to calls and literals

add-trailing-comma v4.0.0 88.4K downloads/30d#13,732 on PyPI373
Permissive license MIT Active released

What it is and what it does

add-trailing-comma is a code formatter that enforces a specific multi-line formatting style by automatically adding trailing commas to the last parameter or element in function calls, literals, definitions, imports, class declarations, and other multi-line constructs. It works as a standalone tool or integrates as a pre-commit hook to run on every commit.

The tool targets a style where trailing commas improve readability and minimize git diffs when parameters are added or removed—each change affects only the lines being modified, preserving blame history. It handles function calls, tuple/list/dict/set literals, function and async function definitions, from-imports, class definitions, with statements, match statements, and PEP-695 type aliases. It also reformats hanging parentheses and braces to match indentation conventions.

Use it for:

  • Enforce consistent multi-line formatting across a Python project via pre-commit hooks.
  • Automatically reformat function calls and literals to add trailing commas for cleaner diffs.
  • Standardize function and class definitions to include trailing commas on the last parameter.
  • Unhug misaligned parentheses and braces to match project indentation style.
  • Maintain code style compliance in CI/CD pipelines without manual review.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Automatically adds trailing commas to multi-line Python function calls, literals, definitions, imports, and class/type declarations, and can be run as a pre-commit hook.

Yes. Low install friction, active maintenance, no security issues, and permissive MIT license. Useful for teams that want to enforce a specific trailing-comma style automatically. Install if your project or team values consistent multi-line formatting and wants to reduce manual code review overhead; skip if your codebase already uses a different formatter (e.g., Black) that handles trailing commas differently.

Install

add-trailing-comma on PyPI

pip

pip install add-trailing-comma

uv

uv add add-trailing-comma

poetry

poetry add add-trailing-comma

Installing add-trailing-comma

Before you install

Low friction: pure Python wheel with a single runtime dependency (tokenize-rt). Active maintenance with recent release (2025-10-10) and no known vulnerabilities.

License in practice

MIT license is permissive; you can use, modify, and distribute this package freely in commercial and private projects.

Quickstart

pip install add-trailing-comma

Then add to .pre-commit-config.yaml:
- repo: https://github.com/asottile/add-trailing-comma
  rev: v4.0.0
  hooks:
  - id: add-trailing-comma

Requires Python 3.10 or later.

Verify before relying

  • Whether the tool modifies files in-place or outputs to stdout by default.
  • How the tool handles existing trailing commas in single-line constructs.
  • Performance characteristics on large codebases or deeply nested structures.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 1 — tokenize-rt
Maintenance actively maintained — 308 days since the last release
Last repo commit
First released
Downloads 88,391/month — #13,732 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: add_trailing_comma-4.0.0-py2.py3-none-any.whl

Programming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPy

Tags

trailing comma formatterpython code formatterpre-commit hookautomatic code formattingpython style enforcement
code-formatterpre-commitstyle-enforcement

More Quality Assurance packages