{"id":13771361,"url":"https://github.com/facebook/usort","last_synced_at":"2025-05-16T12:12:16.360Z","repository":{"id":37795248,"uuid":"235863689","full_name":"facebook/usort","owner":"facebook","description":"Safe, minimal import sorting for Python projects.","archived":false,"fork":false,"pushed_at":"2024-10-01T14:57:52.000Z","size":553,"stargazers_count":196,"open_issues_count":20,"forks_count":19,"subscribers_count":19,"default_branch":"main","last_synced_at":"2025-05-15T00:14:59.574Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://usort.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/facebook.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-23T18:53:16.000Z","updated_at":"2025-04-18T10:17:23.000Z","dependencies_parsed_at":"2024-05-01T15:53:40.345Z","dependency_job_id":"12af5357-e841-4627-87cd-853c2eacb7f2","html_url":"https://github.com/facebook/usort","commit_stats":{"total_commits":366,"total_committers":9,"mean_commits":"40.666666666666664","dds":0.5027322404371585,"last_synced_commit":"ad0ba8f6242850febd0a7f7e6fc55aa85fceda1e"},"previous_names":["facebookexperimental/usort"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebook%2Fusort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebook%2Fusort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebook%2Fusort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebook%2Fusort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/facebook","download_url":"https://codeload.github.com/facebook/usort/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254527099,"owners_count":22085919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T17:00:50.620Z","updated_at":"2025-05-16T12:12:16.339Z","avatar_url":"https://github.com/facebook.png","language":"Python","readme":"# μsort\n\n**Safe, minimal import sorting for Python projects.**\n\n[![documentation](https://readthedocs.org/projects/usort/badge/?version=stable)](https://usort.readthedocs.io/en/stable/?badge=stable)\n[![version](https://img.shields.io/pypi/v/usort.svg)](https://pypi.org/project/usort)\n[![changelog](https://img.shields.io/badge/change-log-blue.svg)](https://usort.readthedocs.io/en/latest/changelog.html)\n[![license](https://img.shields.io/pypi/l/usort.svg)](https://github.com/facebook/usort/blob/main/LICENSE)\n\nμsort is a safe, minimal import sorter. Its primary goal is to make no \"dangerous\"\nchanges to code. This is achieved by detecting distinct \"blocks\" of imports that are\nthe most likely to be safely interchangeable, and only reordering imports within these\nblocks without altering formatting. Code style is left as an exercise for linters\nand formatters.\n\nWithin a block, µsort will follow common Python conventions for grouping imports based\non source (standard library, third-party, first-party, or relative), and then sorting\nlexicographically within each group. This will commonly look like:\n\n```py\nimport re\nfrom pathlib import Path\nfrom typing import Iterable\nfrom unittest.mock import call, Mock, patch\n\nimport aiohttp\nfrom aiosqlite import connect\n\nimport foo\nfrom bar import bar\n\nfrom .main import main\n```\n\nBlocks are inferred from a number of real world conditions, including any intermediate\nstatements between imports:\n\n```py\nimport warnings\nwarnings.filterwarnings(...)\n\nimport re\nimport sys\n```\n\nIn this case, µsort detects two blocks–separated by the call to `filterwarnings()`,\nand will only sort imports inside of each block. Running µsort on this code\nwill generate no changes, because each block is already sorted.\n\nImports can be excluded from blocks using the `#usort:skip` directive, or with\n`#isort:skip` for compatibility with existing codebases. µsort will leave\nthese imports unchanged, and treat them as block separators.\n\nSee the [User Guide][] for more details about how blocks are detected,\nand how sorting is performed.\n\n\n## Install\n\nµsort requires Python 3.8 or newer to run. Install µsort with:\n\n```shell-session\n$ pip install usort\n```\n\n\n## Usage\n\nTo format one or more files or directories in-place:\n\n```shell-session\n$ usort format \u003cpath\u003e [\u003cpath\u003e ...]\n```\n\nTo generate a diff of changes without modifying files:\n\n```shell-session\n$ usort diff \u003cpath\u003e\n```\n\nTo just validate that files are formatted correctly, like during CI:\n\n```shell-session\n$ usort check \u003cpath\u003e\n```\n\n### pre-commit\n\nµsort provides a [pre-commit](https://pre-commit.com/) hook. To enforce sorted\nimports before every commit, add the following to your `.pre-commit-config.yaml`\nfile:\n\n```yaml\n- repo: https://github.com/facebook/usort\n  rev: v1.0.7\n  hooks:\n    - id: usort\n```\n\n## License\n\nμsort is MIT licensed, as found in the [LICENSE][] file.\n\n[LICENSE]: https://github.com/facebook/usort/tree/main/LICENSE\n[User Guide]: https://usort.readthedocs.io/en/stable/guide.html\n","funding_links":[],"categories":["Imports formatters"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacebook%2Fusort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffacebook%2Fusort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacebook%2Fusort/lists"}