Skip to content

isort Settings

Ed Morley edited this page Jan 29, 2016 · 17 revisions

isort provides several ways to configure its behavior, so that it can work well with your project's unique style guidelines.

isort follows the following priority when applying settings:

  • Settings manually passed into the Python SortImports class.
  • Settings manually passed into the command line utility.
  • Settings placed in a setup.cfg file within the project's directory
  • Settings placed in a .isort.cfg file within the project's directory.
  • Settings placed in a .isort.cfg file within the users home directory.
  • Settings placed in a .editorconfig file within the project's directory.
  • Settings placed in a .editorconfig file within the users home directory.

Setting list settings from the command line

When you set a command line argument that can be set more then once (For Example: skip) you must fully specify for each setting. For example to skip file1.py and file2.py do:

isort --skip file1.py --skip file2.py

Full reference of isort settings

Below is a full reference of every setting isort accepts, alongside a basic explanation of its use:

  • force_to_top: Forces a list of imports to the top of their respective section. This works well for handling the unfortunate cases of import dependencies that occur in many projects.
  • skip: A list of files to skip sorting completely.
  • not_skip: A list of files to never skip sorting.
  • line_length: An integer that represents the longest line-length you want a single import to take. Defaults to 79.
  • wrap_length: An integer that represents the longest line-length you want when wrapping. If not set will default to line_length.
  • known_standard_library: A list of imports that will be forced to display within the standard library category.
  • known_third_party: A list of imports that will be forced to display within the third party category.
  • known_first_party: A list of imports that will be forced to display within the first party category.
  • multi_line_output: An integer that represents how you want imports to be displayed if they're long enough to span multiple lines. A full definition of all possible modes can be found here.
  • forced_separate: A list of modules that you want to appear in their own separate section.
  • indent: An integer that represents the number of spaces you would like to indent by or Tab to indent by a single tab.
  • length_sort: If set to true - imports will be sorted by their length instead of alphabetically.
  • force_single_line: If set to true - instead of wrapping multi-line from style imports, each import will be forced to display on its own line.
  • force_grid_wrap: Force from imports to be grid wrapped regardless of line length.
  • default_section: The default section to place imports in, if their section can not be automatically determined.
  • import_heading_future: A comment to consistently place directly above future imports.
  • import_heading_stdlib: A comment to consistently place directly above imports from the standard library.
  • import_heading_thirdparty: A comment to consistently place directly above thirdparty imports.
  • import_heading_firstparty: A comment to consistently place directly above imports from the current project.
  • import_heading_localfolder: A comment to consistently place directly above imports that start with '.'.
  • balanced_wrapping: If set to true - for each multi-line import statement isort will dynamically change the import length to the one that produces the most balanced grid, while staying below the maximum import length defined.
  • order_by_type: If set to true - isort will create separate sections within "from" imports for CONSTANTS, Classes, and modules/functions.
  • atomic: If set to true - isort will only change a file in place if the resulting file has correct Python syntax. This defaults to false because it can only work if the version of code having it's imports sorted is running the same version of Python as isort itself.
  • lines_after_imports: Forces a certain number of lines after the imports and before the first line of functional code. By default this is 2 lines if the first line of code is a class or function. Otherwise it's 1.
  • combine_as_imports: If set to true - isort will combine as imports on the same line within for import statements. By default isort forces all as imports to display on their own lines.
  • force_adds: If set to true - isort will add imports even if the file specified is currently completely empty.
  • combine_star: If set to true - ensures that if a star import is present, nothing else is imported from that namespace.
  • verbose: If set to true - isort will print out verbose information such as when a file is skipped intentionally or when a file check is successful.
  • settings-path: Can be used from the command line to manually specify the location of a settings file.
  • include_trailing_comma: Will set isort to automatically add a trailing comma to the end of from imports.
  • from_first: If set, from imports will be displayed above normal (straight) imports.
  • force_sort_within_sections: If set, imports will be sorted within there section independent to the import_type.
  • force_alphabetical_sort: If set, forces all imports to be sorted as a single section, instead of within other groups (such as straight vs from).

    For example:

    from os import path
    import os
    

    and not the default behavior of:

    import os
    from os import path
    
Something went wrong with that request. Please try again.