--- id: sort-lines version: "0.3.0" license: MIT license_treatment: permissive maintenance: active --- # sort-lines — alphabetize lines in files License: permissive · Maintenance: active · Downloads: 78.2K/mo ## 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 above — 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 pip install sort-lines uv add sort-lines 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_current - Install friction: low - Maintenance: active - Downloads: 78.2K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags sort lines alphabetically, alphabetize file contents, indentation-based line sorting, pragma comment sorting, code list formatter, pre-commit line sorter, code-formatter, pre-commit-hook [View on SkillFed](https://skillfed.io/packages/sort-lines) · [View on PyPI](https://pypi.org/project/sort-lines/)