sort-lines
alphabetize lines in files
What it is and what it does
sort-lines is a command-line tool that alphabetizes lines within a file based on their indentation level. You mark a section for sorting by adding a `# pragma: alphabetize` comment on the line above the block you want sorted; the tool then alphabetizes all subsequent lines at the same indentation level until it encounters a line with different indentation or a blank line. It supports case-insensitive sorting via a `[case-insensitive]` option in the pragma comment or a command-line flag.
The tool is designed for Python code but works with any consistently indented text. It integrates with pre-commit hooks, making it useful for automated code formatting workflows. With no runtime dependencies and a straightforward installation, it's a lightweight utility for keeping lists, imports, or other line-based structures in alphabetical order without manual intervention.
Use it for:
- Alphabetize lists of names, imports, or configuration items in Python code by marking them with a pragma comment.
- Enforce consistent ordering of dictionary keys or array elements in code reviews via pre-commit hooks.
- Sort lines in any text file with consistent indentation, such as configuration files or data lists.
- Maintain alphabetical order in multi-line function arguments or class definitions.
- Automate line sorting in CI/CD pipelines to ensure reproducible, consistent code formatting.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Alphabetizes lines in files based on indentation levels, triggered by a pragma comment, with optional case-insensitive sorting.
Yes, if you need lightweight, pragma-driven line sorting in code or text files. The tool has no dependencies, installs easily, and integrates well with pre-commit workflows. It's actively maintained and carries no known security vulnerabilities. Suitable for teams that want to enforce alphabetical ordering without heavyweight formatters.
Install
sort-lines on PyPI
pip
pip install sort-linesuv
uv add sort-linespoetry
poetry add sort-linesInstalling sort-lines
Before you install
Low friction install with no runtime dependencies. Actively maintained with recent commits; last release was 793 days ago but the repository shows ongoing activity.
License in practice
MIT license permits free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
Quickstart
pip install sort-lines
# Add to a Python file:
names = [ # pragma: alphabetize
'Alice',
'Bob',
'Charlie',
]
# Run: sort-lines names.py
Requires Python 3.9 or later.
Verify before relying
- Whether the tool handles nested indentation levels correctly in complex structures.
- Performance characteristics on very large files or deeply indented code blocks.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 793 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 78,235/month — #14,458 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: sort_lines-0.3.0-py2.py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
autopep8autopep8 automatically reformats Python code to…
permissive · top 5,000 on PyPI
toml-sortCommand-line utility and Python library to sort…
permissive · top 15,000 on PyPI
natsortnatsort provides natural sorting for strings…
permissive · top 1,000 on PyPI
uv-sortAlphabetically sorts dependencies in uv's…
permissive · top 15,000 on PyPI
csvsortSorts large CSV files on disk using a…
copyleft · top 15,000 on PyPI
usortμsort sorts Python imports within detected…
permissive · top 5,000 on PyPI
reformat-gherkinAutomatically formats Gherkin feature files to…
permissive · top 15,000 on PyPI
ufmtufmt combines black and µsort into a single…
permissive · top 5,000 on PyPI
nocasedictA case-insensitive ordered dictionary that…
copyleft · top 15,000 on PyPI
jaraco.textProvides utility functions for common text…
permissive · top 5,000 on PyPI