add-trailing-comma
Automatically add trailing commas to calls and literals
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-commauv
uv add add-trailing-commapoetry
poetry add add-trailing-commaInstalling 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
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
flake8-commasA flake8 plugin that enforces trailing comma…
permissive · top 15,000 on PyPI
jsoncommentParses JSON with comments, multiline strings,…
permissive · top 15,000 on PyPI
jstylesonParses JSON strings that contain…
permissive · top 15,000 on PyPI
pyupgradeAutomatically rewrites Python source code to…
permissive · top 5,000 on PyPI
absolufy-importsAutomatically converts relative imports to…
permissive · top 15,000 on PyPI
shfmt-pyProvides a Python-installable wrapper that…
permissive · top 15,000 on PyPI
flake8-implicit-str-concatA Flake8 plugin that detects and reports…
permissive · top 15,000 on PyPI
json-with-commentsParses and serializes JSON with support for…
permissive · top 15,000 on PyPI
config-formatterAutomatically formats .ini and .cfg…
permissive · top 15,000 on PyPI
pre-commit-hooksProvides a collection of reusable pre-commit…
permissive · top 5,000 on PyPI