CINXE.COM

isort

<!doctype html> <html lang="en" class="no-js"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="icon" href="art/logo.png"> <meta name="generator" content="mkdocs-1.2.1, mkdocs-material-7.2.3"> <title>isort</title> <link rel="stylesheet" href="assets/stylesheets/main.f7f47774.min.css"> <link rel="stylesheet" href="assets/stylesheets/palette.3f5d1f46.min.css"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700%7CRoboto+Mono&display=fallback"> <style>:root{--md-text-font-family:"Roboto";--md-code-font-family:"Roboto Mono"}</style> <link rel="stylesheet" href="art/stylesheets/extra.css"> </head> <body dir="ltr" data-md-color-scheme="isort" data-md-color-primary="" data-md-color-accent=""> <script>function __prefix(e){return new URL(".",location).pathname+"."+e}function __get(e,t=localStorage){return JSON.parse(t.getItem(__prefix(e)))}</script> <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off"> <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off"> <label class="md-overlay" for="__drawer"></label> <div data-md-component="skip"> <a href="#installing-isort" class="md-skip"> Skip to content </a> </div> <div data-md-component="announce"> </div> <header class="md-header" data-md-component="header"> <nav class="md-header__inner md-grid" aria-label="Header"> <a href="index.html" title="isort" class="md-header__button md-logo" aria-label="isort" data-md-component="logo"> <img src="art/logo.png" alt="logo"> </a> <label class="md-header__button md-icon" for="__drawer"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2z"/></svg> </label> <div class="md-header__title" data-md-component="header-title"> <div class="md-header__ellipsis"> <div class="md-header__topic"> <span class="md-ellipsis"> isort </span> </div> <div class="md-header__topic" data-md-component="header-topic"> <span class="md-ellipsis"> Home </span> </div> </div> </div> <label class="md-header__button md-icon" for="__search"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg> </label> <div class="md-search" data-md-component="search" role="dialog"> <label class="md-search__overlay" for="__search"></label> <div class="md-search__inner" role="search"> <form class="md-search__form" name="search"> <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required> <label class="md-search__icon md-icon" for="__search"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg> </label> <nav class="md-search__options" aria-label="Search"> <button type="reset" class="md-search__icon md-icon" aria-label="Clear" tabindex="-1"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg> </button> </nav> </form> <div class="md-search__output"> <div class="md-search__scrollwrap" data-md-scrollfix> <div class="md-search-result" data-md-component="search-result"> <div class="md-search-result__meta"> Initializing search </div> <ol class="md-search-result__list"></ol> </div> </div> </div> </div> </div> <div class="md-header__source"> <a href="https://github.com/timothycrosley/isort/" title="Go to repository" class="md-source" data-md-component="source"> <div class="md-source__icon md-icon"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg> </div> <div class="md-source__repository"> isort </div> </a> </div> </nav> </header> <div class="md-container" data-md-component="container"> <main class="md-main" data-md-component="main"> <div class="md-main__inner md-grid"> <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" > <div class="md-sidebar__scrollwrap"> <div class="md-sidebar__inner"> <nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0"> <label class="md-nav__title" for="__drawer"> <a href="index.html" title="isort" class="md-nav__button md-logo" aria-label="isort" data-md-component="logo"> <img src="art/logo.png" alt="logo"> </a> isort </label> <div class="md-nav__source"> <a href="https://github.com/timothycrosley/isort/" title="Go to repository" class="md-source" data-md-component="source"> <div class="md-source__icon md-icon"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg> </div> <div class="md-source__repository"> isort </div> </a> </div> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item md-nav__item--active"> <input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc"> <label class="md-nav__link md-nav__link--active" for="__toc"> Home <span class="md-nav__icon md-icon"></span> </label> <a href="index.html" class="md-nav__link md-nav__link--active"> Home </a> <nav class="md-nav md-nav--secondary" aria-label="Table of contents"> <label class="md-nav__title" for="__toc"> <span class="md-nav__icon md-icon"></span> Table of contents </label> <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix> <li class="md-nav__item"> <a href="#installing-isort" class="md-nav__link"> Installing isort </a> </li> <li class="md-nav__item"> <a href="#using-isort" class="md-nav__link"> Using isort </a> </li> <li class="md-nav__item"> <a href="#installing-isorts-for-your-preferred-text-editor" class="md-nav__link"> Installing isort's for your preferred text editor </a> </li> <li class="md-nav__item"> <a href="#multi-line-output-modes" class="md-nav__link"> Multi line output modes </a> </li> <li class="md-nav__item"> <a href="#indentation" class="md-nav__link"> Indentation </a> </li> <li class="md-nav__item"> <a href="#intelligently-balanced-multi-line-imports" class="md-nav__link"> Intelligently Balanced Multi-line Imports </a> </li> <li class="md-nav__item"> <a href="#custom-sections-and-ordering" class="md-nav__link"> Custom Sections and Ordering </a> </li> <li class="md-nav__item"> <a href="#skip-processing-of-imports-outside-of-configuration" class="md-nav__link"> Skip processing of imports (outside of configuration) </a> </li> <li class="md-nav__item"> <a href="#adding-or-removing-an-import-from-multiple-files" class="md-nav__link"> Adding or removing an import from multiple files </a> </li> <li class="md-nav__item"> <a href="#using-isort-to-verify-code" class="md-nav__link"> Using isort to verify code </a> </li> <li class="md-nav__item"> <a href="#the-check-only-option" class="md-nav__link"> The --check-only option </a> </li> <li class="md-nav__item"> <a href="#git-hook" class="md-nav__link"> Git hook </a> </li> <li class="md-nav__item"> <a href="#setuptools-integration" class="md-nav__link"> Setuptools integration </a> </li> <li class="md-nav__item"> <a href="#spread-the-word" class="md-nav__link"> Spread the word </a> </li> <li class="md-nav__item"> <a href="#security-contact-information" class="md-nav__link"> Security contact information </a> </li> <li class="md-nav__item"> <a href="#why-isort" class="md-nav__link"> Why isort? </a> </li> </ul> </nav> </li> <li class="md-nav__item"> <a href="CHANGELOG.html" class="md-nav__link"> Changelog </a> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_3" type="checkbox" id="__nav_3" > <label class="md-nav__link" for="__nav_3"> Configuration <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" aria-label="Configuration" data-md-level="1"> <label class="md-nav__title" for="__nav_3"> <span class="md-nav__icon md-icon"></span> Configuration </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="docs/configuration/action_comments.html" class="md-nav__link"> Action Comments </a> </li> <li class="md-nav__item"> <a href="docs/configuration/add_or_remove_imports.html" class="md-nav__link"> Add Or Remove Imports </a> </li> <li class="md-nav__item"> <a href="docs/configuration/black_compatibility.html" class="md-nav__link"> Black Compatibility </a> </li> <li class="md-nav__item"> <a href="docs/configuration/config_files.html" class="md-nav__link"> Config Files </a> </li> <li class="md-nav__item"> <a href="docs/configuration/custom_sections_and_ordering.html" class="md-nav__link"> Custom Sections And Ordering </a> </li> <li class="md-nav__item"> <a href="docs/configuration/git_hook.html" class="md-nav__link"> Git Hook </a> </li> <li class="md-nav__item"> <a href="docs/configuration/github_action.html" class="md-nav__link"> Github Action </a> </li> <li class="md-nav__item"> <a href="docs/configuration/multi_line_output_modes.html" class="md-nav__link"> Multi Line Output Modes </a> </li> <li class="md-nav__item"> <a href="docs/configuration/options.html" class="md-nav__link"> Options </a> </li> <li class="md-nav__item"> <a href="docs/configuration/pre-commit.html" class="md-nav__link"> Pre Commit </a> </li> <li class="md-nav__item"> <a href="docs/configuration/profiles.html" class="md-nav__link"> Profiles </a> </li> <li class="md-nav__item"> <a href="docs/configuration/setuptools_integration.html" class="md-nav__link"> Setuptools Integration </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_4" type="checkbox" id="__nav_4" > <label class="md-nav__link" for="__nav_4"> Contributing <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" aria-label="Contributing" data-md-level="1"> <label class="md-nav__title" for="__nav_4"> <span class="md-nav__icon md-icon"></span> Contributing </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="docs/contributing/1.-contributing-guide.html" class="md-nav__link"> 1. Contributing Guide </a> </li> <li class="md-nav__item"> <a href="docs/contributing/2.-coding-standard.html" class="md-nav__link"> 2. Coding Standard </a> </li> <li class="md-nav__item"> <a href="docs/contributing/3.-code-of-conduct.html" class="md-nav__link"> 3. Code Of Conduct </a> </li> <li class="md-nav__item"> <a href="docs/contributing/4.-acknowledgements.html" class="md-nav__link"> 4. Acknowledgements </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_5" type="checkbox" id="__nav_5" > <label class="md-nav__link" for="__nav_5"> Howto <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" aria-label="Howto" data-md-level="1"> <label class="md-nav__title" for="__nav_5"> <span class="md-nav__icon md-icon"></span> Howto </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="docs/howto/shared_profiles.html" class="md-nav__link"> Shared Profiles </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_6" type="checkbox" id="__nav_6" > <label class="md-nav__link" for="__nav_6"> Major Releases <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" aria-label="Major Releases" data-md-level="1"> <label class="md-nav__title" for="__nav_6"> <span class="md-nav__icon md-icon"></span> Major Releases </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="docs/major_releases/introducing_isort_5.html" class="md-nav__link"> Introducing Isort 5 </a> </li> <li class="md-nav__item"> <a href="docs/major_releases/release_policy.html" class="md-nav__link"> Release Policy </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_7" type="checkbox" id="__nav_7" > <label class="md-nav__link" for="__nav_7"> Quick Start <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" aria-label="Quick Start" data-md-level="1"> <label class="md-nav__title" for="__nav_7"> <span class="md-nav__icon md-icon"></span> Quick Start </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="docs/quick_start/0.-try.html" class="md-nav__link"> 0. Try </a> </li> <li class="md-nav__item"> <a href="docs/quick_start/1.-install.html" class="md-nav__link"> 1. Install </a> </li> <li class="md-nav__item"> <a href="docs/quick_start/2.-cli.html" class="md-nav__link"> 2. Cli </a> </li> <li class="md-nav__item"> <a href="docs/quick_start/3.-api.html" class="md-nav__link"> 3. Api </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_8" type="checkbox" id="__nav_8" > <label class="md-nav__link" for="__nav_8"> Upgrade Guides <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" aria-label="Upgrade Guides" data-md-level="1"> <label class="md-nav__title" for="__nav_8"> <span class="md-nav__icon md-icon"></span> Upgrade Guides </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="docs/upgrade_guides/5.0.0.html" class="md-nav__link"> 5.0.0 </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_9" type="checkbox" id="__nav_9" > <label class="md-nav__link" for="__nav_9"> Warning And Error Codes <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" aria-label="Warning And Error Codes" data-md-level="1"> <label class="md-nav__title" for="__nav_9"> <span class="md-nav__icon md-icon"></span> Warning And Error Codes </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="docs/warning_and_error_codes/W0500.html" class="md-nav__link"> W0500 </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_10" type="checkbox" id="__nav_10" > <label class="md-nav__link" for="__nav_10"> Reference <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" aria-label="Reference" data-md-level="1"> <label class="md-nav__title" for="__nav_10"> <span class="md-nav__icon md-icon"></span> Reference </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_10_1" type="checkbox" id="__nav_10_1" > <label class="md-nav__link" for="__nav_10_1"> Isort <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" aria-label="Isort" data-md-level="2"> <label class="md-nav__title" for="__nav_10_1"> <span class="md-nav__icon md-icon"></span> Isort </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="reference/isort/api.html" class="md-nav__link"> API </a> </li> <li class="md-nav__item"> <a href="reference/isort/comments.html" class="md-nav__link"> Comments </a> </li> <li class="md-nav__item"> <a href="reference/isort/core.html" class="md-nav__link"> Core </a> </li> <li class="md-nav__item"> <a href="reference/isort/exceptions.html" class="md-nav__link"> Exceptions </a> </li> <li class="md-nav__item"> <a href="reference/isort/files.html" class="md-nav__link"> Files </a> </li> <li class="md-nav__item"> <a href="reference/isort/format.html" class="md-nav__link"> Format </a> </li> <li class="md-nav__item"> <a href="reference/isort/hooks.html" class="md-nav__link"> Hooks </a> </li> <li class="md-nav__item"> <a href="reference/isort/identify.html" class="md-nav__link"> Identify </a> </li> <li class="md-nav__item"> <a href="reference/isort/index.html" class="md-nav__link"> Index </a> </li> <li class="md-nav__item"> <a href="reference/isort/io.html" class="md-nav__link"> Io </a> </li> <li class="md-nav__item"> <a href="reference/isort/literal.html" class="md-nav__link"> Literal </a> </li> <li class="md-nav__item"> <a href="reference/isort/logo.html" class="md-nav__link"> Logo </a> </li> <li class="md-nav__item"> <a href="reference/isort/main.html" class="md-nav__link"> Main </a> </li> <li class="md-nav__item"> <a href="reference/isort/output.html" class="md-nav__link"> Output </a> </li> <li class="md-nav__item"> <a href="reference/isort/parse.html" class="md-nav__link"> Parse </a> </li> <li class="md-nav__item"> <a href="reference/isort/place.html" class="md-nav__link"> Place </a> </li> <li class="md-nav__item"> <a href="reference/isort/profiles.html" class="md-nav__link"> Profiles </a> </li> <li class="md-nav__item"> <a href="reference/isort/pylama_isort.html" class="md-nav__link"> Pylama Isort </a> </li> <li class="md-nav__item"> <a href="reference/isort/sections.html" class="md-nav__link"> Sections </a> </li> <li class="md-nav__item"> <a href="reference/isort/settings.html" class="md-nav__link"> Settings </a> </li> <li class="md-nav__item"> <a href="reference/isort/setuptools_commands.html" class="md-nav__link"> Setuptools Commands </a> </li> <li class="md-nav__item"> <a href="reference/isort/sorting.html" class="md-nav__link"> Sorting </a> </li> <li class="md-nav__item"> <a href="reference/isort/utils.html" class="md-nav__link"> Utils </a> </li> <li class="md-nav__item"> <a href="reference/isort/wrap.html" class="md-nav__link"> Wrap </a> </li> <li class="md-nav__item"> <a href="reference/isort/wrap_modes.html" class="md-nav__link"> Wrap Modes </a> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_10_1_26" type="checkbox" id="__nav_10_1_26" > <label class="md-nav__link" for="__nav_10_1_26"> Deprecated <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" aria-label="Deprecated" data-md-level="3"> <label class="md-nav__title" for="__nav_10_1_26"> <span class="md-nav__icon md-icon"></span> Deprecated </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="reference/isort/deprecated/finders.html" class="md-nav__link"> Finders </a> </li> <li class="md-nav__item"> <a href="reference/isort/deprecated/index.html" class="md-nav__link"> Index </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_10_1_27" type="checkbox" id="__nav_10_1_27" > <label class="md-nav__link" for="__nav_10_1_27"> Stdlibs <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" aria-label="Stdlibs" data-md-level="3"> <label class="md-nav__title" for="__nav_10_1_27"> <span class="md-nav__icon md-icon"></span> Stdlibs </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="reference/isort/stdlibs/all.html" class="md-nav__link"> All </a> </li> <li class="md-nav__item"> <a href="reference/isort/stdlibs/index.html" class="md-nav__link"> Index </a> </li> <li class="md-nav__item"> <a href="reference/isort/stdlibs/py2.html" class="md-nav__link"> Py2 </a> </li> <li class="md-nav__item"> <a href="reference/isort/stdlibs/py27.html" class="md-nav__link"> Py27 </a> </li> <li class="md-nav__item"> <a href="reference/isort/stdlibs/py3.html" class="md-nav__link"> Py3 </a> </li> <li class="md-nav__item"> <a href="reference/isort/stdlibs/py310.html" class="md-nav__link"> Py310 </a> </li> <li class="md-nav__item"> <a href="reference/isort/stdlibs/py311.html" class="md-nav__link"> Py311 </a> </li> <li class="md-nav__item"> <a href="reference/isort/stdlibs/py36.html" class="md-nav__link"> Py36 </a> </li> <li class="md-nav__item"> <a href="reference/isort/stdlibs/py37.html" class="md-nav__link"> Py37 </a> </li> <li class="md-nav__item"> <a href="reference/isort/stdlibs/py38.html" class="md-nav__link"> Py38 </a> </li> <li class="md-nav__item"> <a href="reference/isort/stdlibs/py39.html" class="md-nav__link"> Py39 </a> </li> </ul> </nav> </li> </ul> </nav> </li> </ul> </nav> </li> </ul> </nav> </div> </div> </div> <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" > <div class="md-sidebar__scrollwrap"> <div class="md-sidebar__inner"> <nav class="md-nav md-nav--secondary" aria-label="Table of contents"> <label class="md-nav__title" for="__toc"> <span class="md-nav__icon md-icon"></span> Table of contents </label> <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix> <li class="md-nav__item"> <a href="#installing-isort" class="md-nav__link"> Installing isort </a> </li> <li class="md-nav__item"> <a href="#using-isort" class="md-nav__link"> Using isort </a> </li> <li class="md-nav__item"> <a href="#installing-isorts-for-your-preferred-text-editor" class="md-nav__link"> Installing isort's for your preferred text editor </a> </li> <li class="md-nav__item"> <a href="#multi-line-output-modes" class="md-nav__link"> Multi line output modes </a> </li> <li class="md-nav__item"> <a href="#indentation" class="md-nav__link"> Indentation </a> </li> <li class="md-nav__item"> <a href="#intelligently-balanced-multi-line-imports" class="md-nav__link"> Intelligently Balanced Multi-line Imports </a> </li> <li class="md-nav__item"> <a href="#custom-sections-and-ordering" class="md-nav__link"> Custom Sections and Ordering </a> </li> <li class="md-nav__item"> <a href="#skip-processing-of-imports-outside-of-configuration" class="md-nav__link"> Skip processing of imports (outside of configuration) </a> </li> <li class="md-nav__item"> <a href="#adding-or-removing-an-import-from-multiple-files" class="md-nav__link"> Adding or removing an import from multiple files </a> </li> <li class="md-nav__item"> <a href="#using-isort-to-verify-code" class="md-nav__link"> Using isort to verify code </a> </li> <li class="md-nav__item"> <a href="#the-check-only-option" class="md-nav__link"> The --check-only option </a> </li> <li class="md-nav__item"> <a href="#git-hook" class="md-nav__link"> Git hook </a> </li> <li class="md-nav__item"> <a href="#setuptools-integration" class="md-nav__link"> Setuptools integration </a> </li> <li class="md-nav__item"> <a href="#spread-the-word" class="md-nav__link"> Spread the word </a> </li> <li class="md-nav__item"> <a href="#security-contact-information" class="md-nav__link"> Security contact information </a> </li> <li class="md-nav__item"> <a href="#why-isort" class="md-nav__link"> Why isort? </a> </li> </ul> </nav> </div> </div> </div> <div class="md-content" data-md-component="content"> <article class="md-content__inner md-typeset"> <a href="https://github.com/pycqa/isort/edit/main/README.md" title="Edit this page" class="md-content__button md-icon"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25z"/></svg> </a> <h1>Home</h1> <p><a href="https://pycqa.github.io/isort/"><img alt="isort - isort your imports, so you don't have to." src="https://raw.githubusercontent.com/pycqa/isort/main/art/logo_large.png" /></a></p> <hr /> <p><a href="https://badge.fury.io/py/isort"><img alt="PyPI version" src="https://badge.fury.io/py/isort.svg" /></a> <a href="https://github.com/pycqa/isort/actions?query=workflow%3ATest"><img alt="Test Status" src="https://github.com/pycqa/isort/workflows/Test/badge.svg?branch=develop" /></a> <a href="https://github.com/pycqa/isort/actions?query=workflow%3ALint"><img alt="Lint Status" src="https://github.com/pycqa/isort/workflows/Lint/badge.svg?branch=develop" /></a> <a href="https://codecov.io/gh/pycqa/isort"><img alt="Code coverage Status" src="https://codecov.io/gh/pycqa/isort/branch/main/graph/badge.svg" /></a> <a href="https://pypi.org/project/isort/"><img alt="License" src="https://img.shields.io/github/license/mashape/apistatus.svg" /></a> <a href="https://gitter.im/timothycrosley/isort?utm_source=badge&amp;utm_medium=badge&amp;utm_campaign=pr-badge&amp;utm_content=badge"><img alt="Join the chat at https://gitter.im/timothycrosley/isort" src="https://badges.gitter.im/Join%20Chat.svg" /></a> <a href="https://pepy.tech/project/isort"><img alt="Downloads" src="https://pepy.tech/badge/isort" /></a> <a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg" /></a> <a href="https://pycqa.github.io/isort/"><img alt="Imports: isort" src="https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&amp;labelColor=ef8336" /></a> <a href="https://deepsource.io/gh/pycqa/isort/?ref=repository-badge"><img alt="DeepSource" src="https://static.deepsource.io/deepsource-badge-light-mini.svg" /></a></p> <hr /> <p><a href="https://pycqa.github.io/isort/">Read Latest Documentation</a> - <a href="https://github.com/pycqa/isort/">Browse GitHub Code Repository</a></p> <hr /> <p>isort your imports, so you don't have to.</p> <p>isort is a Python utility / library to sort imports alphabetically, and automatically separated into sections and by type. It provides a command line utility, Python library and <a href="https://github.com/pycqa/isort/wiki/isort-Plugins">plugins for various editors</a> to quickly sort all your imports. It requires Python 3.7+ to run but supports formatting Python 2 code too.</p> <ul> <li><a href="https://pycqa.github.io/isort/docs/quick_start/0.-try.html">Try isort now from your browser!</a></li> <li><a href="https://pycqa.github.io/isort/docs/configuration/black_compatibility.html">Using black? See the isort and black compatibility guide.</a></li> <li><a href="https://pycqa.github.io/isort/docs/configuration/pre-commit.html">isort has official support for pre-commit!</a></li> </ul> <p><img alt="Example Usage" src="https://raw.github.com/pycqa/isort/main/example.gif" /></p> <p>Before isort:</p> <div class="codehilite"><pre><span></span><code><span class="kn">from</span> <span class="nn">my_lib</span> <span class="kn">import</span> <span class="n">Object</span> <span class="kn">import</span> <span class="nn">os</span> <span class="kn">from</span> <span class="nn">my_lib</span> <span class="kn">import</span> <span class="n">Object3</span> <span class="kn">from</span> <span class="nn">my_lib</span> <span class="kn">import</span> <span class="n">Object2</span> <span class="kn">import</span> <span class="nn">sys</span> <span class="kn">from</span> <span class="nn">third_party</span> <span class="kn">import</span> <span class="n">lib15</span><span class="p">,</span> <span class="n">lib1</span><span class="p">,</span> <span class="n">lib2</span><span class="p">,</span> <span class="n">lib3</span><span class="p">,</span> <span class="n">lib4</span><span class="p">,</span> <span class="n">lib5</span><span class="p">,</span> <span class="n">lib6</span><span class="p">,</span> <span class="n">lib7</span><span class="p">,</span> <span class="n">lib8</span><span class="p">,</span> <span class="n">lib9</span><span class="p">,</span> <span class="n">lib10</span><span class="p">,</span> <span class="n">lib11</span><span class="p">,</span> <span class="n">lib12</span><span class="p">,</span> <span class="n">lib13</span><span class="p">,</span> <span class="n">lib14</span> <span class="kn">import</span> <span class="nn">sys</span> <span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">absolute_import</span> <span class="kn">from</span> <span class="nn">third_party</span> <span class="kn">import</span> <span class="n">lib3</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Hey&quot;</span><span class="p">)</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;yo&quot;</span><span class="p">)</span> </code></pre></div> <p>After isort:</p> <div class="codehilite"><pre><span></span><code><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">absolute_import</span> <span class="kn">import</span> <span class="nn">os</span> <span class="kn">import</span> <span class="nn">sys</span> <span class="kn">from</span> <span class="nn">third_party</span> <span class="kn">import</span> <span class="p">(</span><span class="n">lib1</span><span class="p">,</span> <span class="n">lib2</span><span class="p">,</span> <span class="n">lib3</span><span class="p">,</span> <span class="n">lib4</span><span class="p">,</span> <span class="n">lib5</span><span class="p">,</span> <span class="n">lib6</span><span class="p">,</span> <span class="n">lib7</span><span class="p">,</span> <span class="n">lib8</span><span class="p">,</span> <span class="n">lib9</span><span class="p">,</span> <span class="n">lib10</span><span class="p">,</span> <span class="n">lib11</span><span class="p">,</span> <span class="n">lib12</span><span class="p">,</span> <span class="n">lib13</span><span class="p">,</span> <span class="n">lib14</span><span class="p">,</span> <span class="n">lib15</span><span class="p">)</span> <span class="kn">from</span> <span class="nn">my_lib</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">Object2</span><span class="p">,</span> <span class="n">Object3</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Hey&quot;</span><span class="p">)</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;yo&quot;</span><span class="p">)</span> </code></pre></div> <h2 id="installing-isort">Installing isort</h2> <p>Installing isort is as simple as:</p> <div class="codehilite"><pre><span></span><code>pip install isort </code></pre></div> <p>Install isort with requirements.txt support:</p> <div class="codehilite"><pre><span></span><code>pip install isort<span class="o">[</span>requirements_deprecated_finder<span class="o">]</span> </code></pre></div> <p>Install isort with Pipfile support:</p> <div class="codehilite"><pre><span></span><code>pip install isort<span class="o">[</span>pipfile_deprecated_finder<span class="o">]</span> </code></pre></div> <p>Install isort with both formats support:</p> <div class="codehilite"><pre><span></span><code>pip install isort<span class="o">[</span>requirements_deprecated_finder,pipfile_deprecated_finder<span class="o">]</span> </code></pre></div> <h2 id="using-isort">Using isort</h2> <p><strong>From the command line</strong>:</p> <p>To run on specific files:</p> <div class="codehilite"><pre><span></span><code>isort mypythonfile.py mypythonfile2.py </code></pre></div> <p>To apply recursively:</p> <div class="codehilite"><pre><span></span><code>isort . </code></pre></div> <p>If <a href="https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html">globstar</a> is enabled, <code>isort .</code> is equivalent to:</p> <div class="codehilite"><pre><span></span><code>isort **/*.py </code></pre></div> <p>To view proposed changes without applying them:</p> <div class="codehilite"><pre><span></span><code>isort mypythonfile.py --diff </code></pre></div> <p>Finally, to atomically run isort against a project, only applying changes if they don't introduce syntax errors:</p> <div class="codehilite"><pre><span></span><code>isort --atomic . </code></pre></div> <p>(Note: this is disabled by default, as it prevents isort from running against code written using a different version of Python.)</p> <p><strong>From within Python</strong>:</p> <div class="codehilite"><pre><span></span><code><span class="kn">import</span> <span class="nn">isort</span> <span class="n">isort</span><span class="o">.</span><span class="n">file</span><span class="p">(</span><span class="s2">&quot;pythonfile.py&quot;</span><span class="p">)</span> </code></pre></div> <p>or:</p> <div class="codehilite"><pre><span></span><code><span class="kn">import</span> <span class="nn">isort</span> <span class="n">sorted_code</span> <span class="o">=</span> <span class="n">isort</span><span class="o">.</span><span class="n">code</span><span class="p">(</span><span class="s2">&quot;import b</span><span class="se">\n</span><span class="s2">import a</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span> </code></pre></div> <h2 id="installing-isorts-for-your-preferred-text-editor">Installing isort's for your preferred text editor</h2> <p>Several plugins have been written that enable to use isort from within a variety of text-editors. You can find a full list of them <a href="https://github.com/pycqa/isort/wiki/isort-Plugins">on the isort wiki</a>. Additionally, I will enthusiastically accept pull requests that include plugins for other text editors and add documentation for them as I am notified.</p> <h2 id="multi-line-output-modes">Multi line output modes</h2> <p>You will notice above the \"multi_line_output\" setting. This setting defines how from imports wrap when they extend past the line_length limit and has <a href="https://pycqa.github.io/isort/docs/configuration/multi_line_output_modes.html">12 possible settings</a>.</p> <h2 id="indentation">Indentation</h2> <p>To change the how constant indents appear - simply change the indent property with the following accepted formats:</p> <ul> <li>Number of spaces you would like. For example: 4 would cause standard 4 space indentation.</li> <li>Tab</li> <li>A verbatim string with quotes around it.</li> </ul> <p>For example:</p> <div class="codehilite"><pre><span></span><code><span class="s2">&quot; &quot;</span> </code></pre></div> <p>is equivalent to 4.</p> <p>For the import styles that use parentheses, you can control whether or not to include a trailing comma after the last import with the <code>include_trailing_comma</code> option (defaults to <code>False</code>).</p> <h2 id="intelligently-balanced-multi-line-imports">Intelligently Balanced Multi-line Imports</h2> <p>As of isort 3.1.0 support for balanced multi-line imports has been added. With this enabled isort will dynamically change the import length to the one that produces the most balanced grid, while staying below the maximum import length defined.</p> <p>Example:</p> <div class="codehilite"><pre><span></span><code><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="p">(</span><span class="n">absolute_import</span><span class="p">,</span> <span class="n">division</span><span class="p">,</span> <span class="n">print_function</span><span class="p">,</span> <span class="n">unicode_literals</span><span class="p">)</span> </code></pre></div> <p>Will be produced instead of:</p> <div class="codehilite"><pre><span></span><code><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="p">(</span><span class="n">absolute_import</span><span class="p">,</span> <span class="n">division</span><span class="p">,</span> <span class="n">print_function</span><span class="p">,</span> <span class="n">unicode_literals</span><span class="p">)</span> </code></pre></div> <p>To enable this set <code>balanced_wrapping</code> to <code>True</code> in your config or pass the <code>-e</code> option into the command line utility.</p> <h2 id="custom-sections-and-ordering">Custom Sections and Ordering</h2> <p>isort provides configuration options to change almost every aspect of how imports are organized, ordered, or grouped together in sections.</p> <p><a href="https://pycqa.github.io/isort/docs/configuration/custom_sections_and_ordering.html">Click here</a> for an overview of all these options.</p> <h2 id="skip-processing-of-imports-outside-of-configuration">Skip processing of imports (outside of configuration)</h2> <p>To make isort ignore a single import simply add a comment at the end of the import line containing the text <code>isort:skip</code>:</p> <div class="codehilite"><pre><span></span><code><span class="kn">import</span> <span class="nn">module</span> <span class="c1"># isort:skip</span> </code></pre></div> <p>or:</p> <div class="codehilite"><pre><span></span><code><span class="kn">from</span> <span class="nn">xyz</span> <span class="kn">import</span> <span class="p">(</span><span class="n">abc</span><span class="p">,</span> <span class="c1"># isort:skip</span> <span class="n">yo</span><span class="p">,</span> <span class="n">hey</span><span class="p">)</span> </code></pre></div> <p>To make isort skip an entire file simply add <code>isort:skip_file</code> to the module's doc string:</p> <div class="codehilite"><pre><span></span><code><span class="sd">&quot;&quot;&quot; my_module.py</span> <span class="sd"> Best module ever</span> <span class="sd"> isort:skip_file</span> <span class="sd">&quot;&quot;&quot;</span> <span class="kn">import</span> <span class="nn">b</span> <span class="kn">import</span> <span class="nn">a</span> </code></pre></div> <h2 id="adding-or-removing-an-import-from-multiple-files">Adding or removing an import from multiple files</h2> <p>isort can be ran or configured to add / remove imports automatically.</p> <p><a href="https://pycqa.github.io/isort/docs/configuration/add_or_remove_imports.html">See a complete guide here.</a></p> <h2 id="using-isort-to-verify-code">Using isort to verify code</h2> <h2 id="the-check-only-option">The <code>--check-only</code> option</h2> <p>isort can also be used to verify that code is correctly formatted by running it with <code>-c</code>. Any files that contain incorrectly sorted and/or formatted imports will be outputted to <code>stderr</code>.</p> <div class="codehilite"><pre><span></span><code>isort **/*.py -c -v SUCCESS: /home/timothy/Projects/Open_Source/isort/isort_kate_plugin.py Everything Looks Good! ERROR: /home/timothy/Projects/Open_Source/isort/isort/isort.py Imports are incorrectly sorted. </code></pre></div> <p>One great place this can be used is with a pre-commit git hook, such as this one by \@acdha:</p> <p><a href="https://gist.github.com/acdha/8717683">https://gist.github.com/acdha/8717683</a></p> <p>This can help to ensure a certain level of code quality throughout a project.</p> <h2 id="git-hook">Git hook</h2> <p>isort provides a hook function that can be integrated into your Git pre-commit script to check Python code before committing.</p> <p><a href="https://pycqa.github.io/isort/docs/configuration/git_hook.html">More info here.</a></p> <h2 id="setuptools-integration">Setuptools integration</h2> <p>Upon installation, isort enables a <code>setuptools</code> command that checks Python files declared by your project.</p> <p><a href="https://pycqa.github.io/isort/docs/configuration/setuptools_integration.html">More info here.</a></p> <h2 id="spread-the-word">Spread the word</h2> <p><a href="https://pycqa.github.io/isort/"><img alt="Imports: isort" src="https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&amp;labelColor=ef8336" /></a></p> <p>Place this badge at the top of your repository to let others know your project uses isort.</p> <p>For README.md:</p> <div class="codehilite"><pre><span></span><code>[<span class="nt">![Imports: isort</span>](<span class="na">https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&amp;labelColor=ef8336</span>)](https://pycqa.github.io/isort/) </code></pre></div> <p>Or README.rst:</p> <div class="codehilite"><pre><span></span><code><span class="p">..</span> <span class="ow">image</span><span class="p">::</span> https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&amp;labelColor=ef8336 <span class="nc">:target:</span> https://pycqa.github.io/isort/ </code></pre></div> <h2 id="security-contact-information">Security contact information</h2> <p>To report a security vulnerability, please use the <a href="https://tidelift.com/security">Tidelift security contact</a>. Tidelift will coordinate the fix and disclosure.</p> <h2 id="why-isort">Why isort?</h2> <p>isort simply stands for import sort. It was originally called "sortImports" however I got tired of typing the extra characters and came to the realization camelCase is not pythonic.</p> <p>I wrote isort because in an organization I used to work in the manager came in one day and decided all code must have alphabetically sorted imports. The code base was huge - and he meant for us to do it by hand. However, being a programmer - I\'m too lazy to spend 8 hours mindlessly performing a function, but not too lazy to spend 16 hours automating it. I was given permission to open source sortImports and here we are :)</p> <hr /> <p><a href="https://tidelift.com/subscription/pkg/pypi-isort?utm_source=pypi-isort&amp;utm_medium=referral&amp;utm_campaign=readme">Get professionally supported isort with the Tidelift Subscription</a></p> <p>Professional support for isort is available as part of the <a href="https://tidelift.com/subscription/pkg/pypi-isort?utm_source=pypi-isort&amp;utm_medium=referral&amp;utm_campaign=readme">Tidelift Subscription</a>. Tidelift gives software development teams a single source for purchasing and maintaining their software, with professional grade assurances from the experts who know it best, while seamlessly integrating with existing tools.</p> <hr /> <p>Thanks and I hope you find isort useful!</p> <p>~Timothy Crosley</p> </article> </div> </div> </main> <footer class="md-footer"> <div class="md-footer-nav"> <nav class="md-footer-nav__inner md-grid"> <a href="CHANGELOG.html" title="Changelog" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next"> <div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title"> <span class="md-flex__ellipsis"> <span class="md-footer-nav__direction"> Next </span> Changelog </span> </div> <div class="md-flex__cell md-flex__cell--shrink"> <i class="md-icon md-icon--arrow-forward md-footer-nav__button"></i> </div> </a> </nav> </div> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class="md-footer-copyright"> Powered by <a href="http://timothycrosley.github.io/portray">portray.</a> You too can <a href="http://timothycrosley.github.io/portray"> portray</a> your Python project well using automatic documentation. </div> </div> </div> </footer> </div> <div class="md-dialog" data-md-component="dialog"> <div class="md-dialog__inner md-typeset"></div> </div> <script id="__config" type="application/json">{"base": ".", "features": [], "translations": {"clipboard.copy": "Copy to clipboard", "clipboard.copied": "Copied to clipboard", "search.config.lang": "en", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Search", "search.result.placeholder": "Type to start searching", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.term.missing": "Missing", "select.version.title": "Select version"}, "search": "assets/javascripts/workers/search.709b4209.min.js", "version": null}</script> <script src="assets/javascripts/bundle.29db7785.min.js"></script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10