skillfed

sort-lines

alphabetize lines in files

sort-lines v0.3.0 78.2K downloads/30d#14,458 on PyPI2
Permissive license MIT Active released

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-lines

uv

uv add sort-lines

poetry

poetry add sort-lines

Installing 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

License :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: Implementation :: CPython

Tags

sort lines alphabeticallyalphabetize file contentsindentation-based line sortingpragma comment sortingcode list formatterpre-commit line sorter
code-formatterpre-commit-hook

More Utilities packages