--- id: usort version: "1.1.3" license: MIT License Copyright (c) Meta Platforms, Inc. and affiliates. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the… (full text in the JSON record) license_treatment: permissive maintenance: active --- # usort — Safe, minimal import sorting License: permissive · Maintenance: active · Downloads: 2.5M/mo ## What it is and what it does μsort is a Python import sorter designed to make minimal, safe changes to code. Rather than reordering all imports globally, it detects distinct blocks of imports separated by non-import statements and sorts only within those blocks. This conservative approach avoids the risk of breaking code where import order matters due to side effects or dependencies between imports. Within each block, μsort groups imports by source (standard library, third-party, first-party, relative) and sorts lexicographically. It respects skip directives like `#usort:skip` and `#isort:skip` to exclude specific imports from reordering. The tool integrates with pre-commit workflows via a standard hook. Use it for: - Enforce consistent import ordering in CI pipelines using `usort check` without modifying code - Automatically sort imports in files or directories in-place with `usort format` before committing - Generate diffs of import changes with `usort diff` to review before applying - Integrate import sorting into pre-commit hooks to maintain order on every commit - Sort imports safely in codebases where import order affects behavior due to side effects ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. μsort sorts Python imports within detected blocks while preserving code safety by avoiding reordering across statements that separate import groups. Yes. μsort is actively maintained, has no known vulnerabilities, installs with low friction, and solves a real problem—safe import sorting that respects code structure. It is a good fit if you want conservative import reordering that avoids breaking changes. The MIT license poses no restrictions. ## Install pip install usort uv add usort poetry add usort ## Installing usort Before you install: Low friction installation with seven runtime dependencies. Active maintenance with latest release on 2026-01-13 and repository last commit on 2026-03-01. 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 usort usort format path/to/file.py # or for validation: usort check path/to/file.py Requires Python 3.10 or newer to run Verify before relying: - How μsort handles complex import patterns (star imports, conditional imports, or dynamic imports) - Performance characteristics when sorting large files or projects with many imports - Compatibility with other formatters and linters beyond pre-commit integration ## Package facts - License: MIT License Copyright (c) Meta Platforms, Inc. and affiliates. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the… (full text in the JSON record) (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 2.5M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags python import sorting, safe import reordering, import block detection, minimal import formatter, import organization tool, python code formatter, import grouping, import-sorting, code-formatter, pre-commit-hook [View on SkillFed](https://skillfed.io/packages/usort) · [View on PyPI](https://pypi.org/project/usort/)