skillfed

usort

Safe, minimal import sorting

usort v1.1.3 2.5M downloads/30d#3,026 on PyPI205
Permissive 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) Active released

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 on this page — 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

usort on PyPI

pip

pip install usort

uv

uv add usort

poetry

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 the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 7 — attrs, click, libcst, moreorless, stdlibs, tomli, trailrunner
Maintenance actively maintained — 213 days since the last release
Last repo commit
First released
Downloads 2,519,103/month — #3,026 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: usort-1.1.3-py3-none-any.whl

Keywords: imports, isort, usort

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseTopic :: Software DevelopmentTopic :: UtilitiesTyping :: Typed

Tags

python import sortingsafe import reorderingimport block detectionminimal import formatterimport organization toolpython code formatterimport grouping
import-sortingcode-formatterpre-commit-hook

More Software Development packages