Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 1.1.3 instead.
Reason given by maintainers: https://github.com/facebookexperimental/usort/pull/188

μsort

Safe, minimal import sorting for Python projects.

documentation version changelog license

μsort is a safe, minimal import sorter. Its primary goal is to make no "dangerous" changes to code. This is achieved by detecting distinct "blocks" of imports that are the most likely to be safely interchangeable, and only reordering imports within these blocks without altering formatting. Code style is left as an exercise for linters and formatters.

Within a block, µsort will follow common Python conventions for grouping imports based on source (standard library, third-party, first-party, or relative), and then sorting lexicographically within each group. This will commonly look like:

import re
from pathlib import Path
from typing import Iterable
from unittest.mock import call, Mock, patch

import aiohttp
from aiosqlite import connect

import foo
from bar import bar

from .main import main

Blocks are inferred from a number of real world conditions, including any intermediate statements between imports:

import warnings
warnings.filterwarnings(...)

import re
import sys

In this case, µsort detects two blocks–separated by the call to filterwarnings(), and will only sort imports inside of each block. Running µsort on this code will generate no changes, because each block is already sorted.

Imports can be excluded from blocks using the #usort:skip directive, or with #isort:skip for compatibility with existing codebases. µsort will leave these imports unchanged, and treat them as block separators.

See the User Guide for more details about how blocks are detected, and how sorting is performed.

Install

µsort requires Python 3.6 or newer to run. Install µsort with:

$ pip install usort

Usage

To format one or more files or directories in-place:

$ usort format <path> [<path> ...]

To generate a diff of changes without modifying files:

$ usort diff <path>

To just validate that files are formatted correctly, like during CI:

$ usort check <path>

License

μsort is MIT licensed, as found in the LICENSE file.

Metadata

Release files for usort 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for usort 1.0.3
File Size Uploaded
usort-1.0.3.tar.gz 78.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for usort 1.0.3
File Interpreter ABI Platform
usort-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 101.7 kB

Release files / usort-1.0.3.tar.gz

Download URL usort-1.0.3.tar.gz
Size 78.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e7c5d47f20dd90181eca3672b51fe94848f4afc4ee263a987aae08279cc4c011
BLAKE2b-256 checksum
How to use checksums
680e203c7afd45c794d1b221965846a62ffac67a70bca9c153572d608954f50f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

Release files / usort-1.0.3-py3-none-any.whl

Download URL usort-1.0.3-py3-none-any.whl
Size 23.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a4a5cf2a7e49a60b7b674f5eec2a1f725167b4c87c8e3da77e82b1cffb8d009
BLAKE2b-256 checksum
How to use checksums
0da1e4fb5e1c9dd76741c4ab268d0fe4b07107bb1c906134584983402647b65e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

Release history Release notifications | RSS feed

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page