| 1 |
Metadata-Version: 2.5 |
| 2 |
Name: isort |
| 3 |
Version: 9.0.2 |
| 4 |
Summary: A Python utility / library to sort Python imports. |
| 5 |
Project-URL: Homepage, https://isort.readthedocs.io/ |
| 6 |
Project-URL: Documentation, https://isort.readthedocs.io/ |
| 7 |
Project-URL: Repository, https://github.com/PyCQA/isort |
| 8 |
Project-URL: Changelog, https://github.com/PyCQA/isort/releases |
| 9 |
Author-email: Daniƫl van Noord <[email protected]>, Timothy Crosley <[email protected]>, staticdev <[email protected]> |
| 10 |
License-Expression: MIT |
| 11 |
License-File: LICENSE |
| 12 |
Keywords: Clean,Imports,Lint,Refactor,Sort |
| 13 |
Classifier: Development Status :: 6 - Mature |
| 14 |
Classifier: Environment :: Console |
| 15 |
Classifier: Intended Audience :: Developers |
| 16 |
Classifier: License :: OSI Approved :: MIT License |
| 17 |
Classifier: Natural Language :: English |
| 18 |
Classifier: Programming Language :: Python |
| 19 |
Classifier: Programming Language :: Python :: 3 |
| 20 |
Classifier: Programming Language :: Python :: 3 :: Only |
| 21 |
Classifier: Programming Language :: Python :: 3.10 |
| 22 |
Classifier: Programming Language :: Python :: 3.11 |
| 23 |
Classifier: Programming Language :: Python :: 3.12 |
| 24 |
Classifier: Programming Language :: Python :: 3.13 |
| 25 |
Classifier: Programming Language :: Python :: 3.14 |
| 26 |
Classifier: Programming Language :: Python :: 3.15 |
| 27 |
Classifier: Programming Language :: Python :: Implementation :: CPython |
| 28 |
Classifier: Programming Language :: Python :: Implementation :: PyPy |
| 29 |
Classifier: Topic :: Software Development :: Libraries |
| 30 |
Classifier: Topic :: Utilities |
| 31 |
Requires-Python: >=3.10.0 |
| 32 |
Requires-Dist: mypy-extensions>=1.1.0 |
| 33 |
Provides-Extra: colors |
| 34 |
Requires-Dist: colorama; extra == 'colors' |
| 35 |
Description-Content-Type: text/markdown |
| 36 |
|
| 37 |
[](https://isort.readthedocs.io/) |
| 38 |
|
| 39 |
------------------------------------------------------------------------ |
| 40 |
|
| 41 |
[](https://badge.fury.io/py/isort) |
| 42 |
[][pypi status] |
| 43 |
[](https://github.com/PyCQA/isort/actions/workflows/continuous-integration.yml) |
| 44 |
[](https://codecov.io/gh/pycqa/isort) |
| 45 |
[](https://pypi.org/project/isort/) |
| 46 |
[](https://pepy.tech/project/isort) |
| 47 |
[](https://github.com/psf/black) |
| 48 |
[](https://isort.readthedocs.io/) |
| 49 |
[](https://deepsource.io/gh/pycqa/isort/?ref=repository-badge) |
| 50 |
|
| 51 |
[pypi status]: https://pypi.org/project/isort/ |
| 52 |
_________________ |
| 53 |
|
| 54 |
[Read Latest Documentation](https://isort.readthedocs.io/) - [Browse GitHub Code Repository](https://github.com/pycqa/isort/) |
| 55 |
_________________ |
| 56 |
|
| 57 |
# isort your imports, so you don't have to. |
| 58 |
|
| 59 |
isort is a Python utility / library to sort imports alphabetically and |
| 60 |
automatically separate into sections and by type. It provides a command line |
| 61 |
utility, Python library and [plugins for various |
| 62 |
editors](https://github.com/pycqa/isort/wiki/isort-Plugins) to |
| 63 |
quickly sort all your imports. It requires Python 3.10+ to run but |
| 64 |
supports formatting Python 2 code too. |
| 65 |
|
| 66 |
- [Try isort now from your browser!](docs/quick_start/0.-try.md) |
| 67 |
- [Using black? See the isort and black compatibility guide.](docs/configuration/black_compatibility.md) |
| 68 |
- [isort has official support for pre-commit!](docs/configuration/pre-commit.md) |
| 69 |
|
| 70 |
 |
| 71 |
|
| 72 |
Before isort: |
| 73 |
|
| 74 |
```python |
| 75 |
from my_lib import Object |
| 76 |
|
| 77 |
import os |
| 78 |
|
| 79 |
from my_lib import Object3 |
| 80 |
|
| 81 |
from my_lib import Object2 |
| 82 |
|
| 83 |
import sys |
| 84 |
|
| 85 |
from third_party import lib15, lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12, lib13, lib14 |
| 86 |
|
| 87 |
import sys |
| 88 |
|
| 89 |
from __future__ import absolute_import |
| 90 |
|
| 91 |
from third_party import lib3 |
| 92 |
|
| 93 |
print("Hey") |
| 94 |
print("yo") |
| 95 |
``` |
| 96 |
|
| 97 |
After isort: |
| 98 |
|
| 99 |
```python |
| 100 |
from __future__ import absolute_import |
| 101 |
|
| 102 |
import os |
| 103 |
import sys |
| 104 |
|
| 105 |
from third_party import (lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, |
| 106 |
lib9, lib10, lib11, lib12, lib13, lib14, lib15) |
| 107 |
|
| 108 |
from my_lib import Object, Object2, Object3 |
| 109 |
|
| 110 |
print("Hey") |
| 111 |
print("yo") |
| 112 |
``` |
| 113 |
|
| 114 |
## Installing isort |
| 115 |
|
| 116 |
Installing isort is as simple as: |
| 117 |
|
| 118 |
```bash |
| 119 |
pip install isort |
| 120 |
``` |
| 121 |
|
| 122 |
## Using isort |
| 123 |
|
| 124 |
**From the command line**: |
| 125 |
|
| 126 |
To run on specific files: |
| 127 |
|
| 128 |
```bash |
| 129 |
isort mypythonfile.py mypythonfile2.py |
| 130 |
``` |
| 131 |
|
| 132 |
To apply recursively: |
| 133 |
|
| 134 |
```bash |
| 135 |
isort . |
| 136 |
``` |
| 137 |
|
| 138 |
If [globstar](https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html) |
| 139 |
is enabled, `isort .` is equivalent to: |
| 140 |
|
| 141 |
```bash |
| 142 |
isort **/*.py |
| 143 |
``` |
| 144 |
|
| 145 |
To view proposed changes without applying them: |
| 146 |
|
| 147 |
```bash |
| 148 |
isort mypythonfile.py --diff |
| 149 |
``` |
| 150 |
|
| 151 |
Finally, to atomically run isort against a project, only applying |
| 152 |
changes if they don't introduce syntax errors: |
| 153 |
|
| 154 |
```bash |
| 155 |
isort --atomic . |
| 156 |
``` |
| 157 |
|
| 158 |
(Note: this is disabled by default, as it prevents isort from |
| 159 |
running against code written using a different version of Python.) |
| 160 |
|
| 161 |
**From within Python**: |
| 162 |
|
| 163 |
```python |
| 164 |
import isort |
| 165 |
|
| 166 |
isort.file("pythonfile.py") |
| 167 |
``` |
| 168 |
|
| 169 |
or: |
| 170 |
|
| 171 |
```python |
| 172 |
import isort |
| 173 |
|
| 174 |
sorted_code = isort.code("import b\nimport a\n") |
| 175 |
``` |
| 176 |
|
| 177 |
## Installing isort's for your preferred text editor |
| 178 |
|
| 179 |
Several plugins have been written that enable to use isort from within a |
| 180 |
variety of text-editors. You can find a full list of them [on the isort |
| 181 |
wiki](https://github.com/pycqa/isort/wiki/isort-Plugins). |
| 182 |
Additionally, I will enthusiastically accept pull requests that include |
| 183 |
plugins for other text editors and add documentation for them as I am |
| 184 |
notified. |
| 185 |
|
| 186 |
## Multi line output modes |
| 187 |
|
| 188 |
You will notice above the \"multi\_line\_output\" setting. This setting |
| 189 |
defines how from imports wrap when they extend past the line\_length |
| 190 |
limit and has [12 possible settings](docs/configuration/multi_line_output_modes.md). |
| 191 |
|
| 192 |
## Indentation |
| 193 |
|
| 194 |
To change the how constant indents appear - simply change the |
| 195 |
indent property with the following accepted formats: |
| 196 |
|
| 197 |
- Number of spaces you would like. For example: 4 would cause standard |
| 198 |
4 space indentation. |
| 199 |
- Tab |
| 200 |
- A verbatim string with quotes around it. |
| 201 |
|
| 202 |
For example: |
| 203 |
|
| 204 |
```python |
| 205 |
" " |
| 206 |
``` |
| 207 |
|
| 208 |
is equivalent to 4. |
| 209 |
|
| 210 |
For the import styles that use parentheses, you can control whether or |
| 211 |
not to include a trailing comma after the last import with the |
| 212 |
`include_trailing_comma` option (defaults to `False`). |
| 213 |
|
| 214 |
## Intelligently Balanced Multi-line Imports |
| 215 |
|
| 216 |
As of isort 3.1.0 support for balanced multi-line imports has been |
| 217 |
added. With this enabled isort will dynamically change the import length |
| 218 |
to the one that produces the most balanced grid, while staying below the |
| 219 |
maximum import length defined. |
| 220 |
|
| 221 |
Example: |
| 222 |
|
| 223 |
```python |
| 224 |
from __future__ import (absolute_import, division, |
| 225 |
print_function, unicode_literals) |
| 226 |
``` |
| 227 |
|
| 228 |
Will be produced instead of: |
| 229 |
|
| 230 |
```python |
| 231 |
from __future__ import (absolute_import, division, print_function, |
| 232 |
unicode_literals) |
| 233 |
``` |
| 234 |
|
| 235 |
To enable this set `balanced_wrapping` to `True` in your config or pass |
| 236 |
the `-e` option into the command line utility. |
| 237 |
|
| 238 |
## Custom Sections and Ordering |
| 239 |
|
| 240 |
isort provides configuration options to change almost every aspect of how |
| 241 |
imports are organized, ordered, or grouped together in sections. |
| 242 |
|
| 243 |
[Click here](docs/configuration/custom_sections_and_ordering.md) for an overview of all these options. |
| 244 |
|
| 245 |
## Skip processing of imports (outside of configuration) |
| 246 |
|
| 247 |
To make isort ignore a single import simply add a comment at the end of |
| 248 |
the import line containing the text `isort:skip`: |
| 249 |
|
| 250 |
```python |
| 251 |
import module # isort:skip |
| 252 |
``` |
| 253 |
|
| 254 |
or: |
| 255 |
|
| 256 |
```python |
| 257 |
from xyz import (abc, # isort:skip |
| 258 |
yo, |
| 259 |
hey) |
| 260 |
``` |
| 261 |
|
| 262 |
To make isort skip an entire file simply add `isort:skip_file` to the |
| 263 |
module's doc string: |
| 264 |
|
| 265 |
```python |
| 266 |
""" my_module.py |
| 267 |
Best module ever |
| 268 |
|
| 269 |
isort:skip_file |
| 270 |
""" |
| 271 |
|
| 272 |
import b |
| 273 |
import a |
| 274 |
``` |
| 275 |
|
| 276 |
## Adding or removing an import from multiple files |
| 277 |
|
| 278 |
isort can be ran or configured to add / remove imports automatically. |
| 279 |
|
| 280 |
[See a complete guide here.](docs/configuration/add_or_remove_imports.md) |
| 281 |
|
| 282 |
## Using isort to verify code |
| 283 |
|
| 284 |
The `--check-only` option |
| 285 |
------------------------- |
| 286 |
|
| 287 |
isort can also be used to verify that code is correctly formatted |
| 288 |
by running it with `-c`. Any files that contain incorrectly sorted |
| 289 |
and/or formatted imports will be outputted to `stderr`. |
| 290 |
|
| 291 |
```bash |
| 292 |
isort **/*.py -c -v |
| 293 |
|
| 294 |
SUCCESS: /home/timothy/Projects/Open_Source/isort/isort_kate_plugin.py Everything Looks Good! |
| 295 |
ERROR: /home/timothy/Projects/Open_Source/isort/isort/isort.py Imports are incorrectly sorted. |
| 296 |
``` |
| 297 |
|
| 298 |
One great place this can be used is with a pre-commit git hook, such as |
| 299 |
this one by \@acdha: |
| 300 |
|
| 301 |
<https://gist.github.com/acdha/8717683> |
| 302 |
|
| 303 |
This can help to ensure a certain level of code quality throughout a |
| 304 |
project. |
| 305 |
|
| 306 |
## Git hook |
| 307 |
|
| 308 |
isort provides a hook function that can be integrated into your Git |
| 309 |
pre-commit script to check Python code before committing. |
| 310 |
|
| 311 |
[More info here.](docs/configuration/git_hook.md) |
| 312 |
|
| 313 |
## Spread the word |
| 314 |
|
| 315 |
[](https://isort.readthedocs.io/) |
| 316 |
|
| 317 |
Place this badge at the top of your repository to let others know your project uses isort. |
| 318 |
|
| 319 |
For README.md: |
| 320 |
|
| 321 |
```markdown |
| 322 |
[](https://isort.readthedocs.io/) |
| 323 |
``` |
| 324 |
|
| 325 |
Or README.rst: |
| 326 |
|
| 327 |
```rst |
| 328 |
.. image:: https://img.shields.io/badge/imports-isort-%231674b1?style=flat&labelColor=ef8336 |
| 329 |
:target: https://isort.readthedocs.io/ |
| 330 |
``` |
| 331 |
|
| 332 |
## Security contact information |
| 333 |
|
| 334 |
To report a security vulnerability, please use the [Tidelift security |
| 335 |
contact](https://tidelift.com/security). Tidelift will coordinate the |
| 336 |
fix and disclosure. |
| 337 |
|
| 338 |
## Why isort? |
| 339 |
|
| 340 |
isort simply stands for import sort. It was originally called |
| 341 |
"sortImports" however I got tired of typing the extra characters and |
| 342 |
came to the realization camelCase is not pythonic. |
| 343 |
|
| 344 |
I wrote isort because in an organization I used to work in the manager |
| 345 |
came in one day and decided all code must have alphabetically sorted |
| 346 |
imports. The code base was huge - and he meant for us to do it by hand. |
| 347 |
However, being a programmer - I\'m too lazy to spend 8 hours mindlessly |
| 348 |
performing a function, but not too lazy to spend 16 hours automating it. |
| 349 |
I was given permission to open source sortImports and here we are :) |
| 350 |
|
| 351 |
------------------------------------------------------------------------ |
| 352 |
|
| 353 |
[Get professionally supported isort with the Tidelift |
| 354 |
Subscription](https://tidelift.com/subscription/pkg/pypi-isort?utm_source=pypi-isort&utm_medium=referral&utm_campaign=readme) |
| 355 |
|
| 356 |
Professional support for isort is available as part of the [Tidelift |
| 357 |
Subscription](https://tidelift.com/subscription/pkg/pypi-isort?utm_source=pypi-isort&utm_medium=referral&utm_campaign=readme). |
| 358 |
Tidelift gives software development teams a single source for purchasing |
| 359 |
and maintaining their software, with professional grade assurances from |
| 360 |
the experts who know it best, while seamlessly integrating with existing |
| 361 |
tools. |
| 362 |
|
| 363 |
------------------------------------------------------------------------ |
| 364 |
|
| 365 |
Thanks and I hope you find isort useful! |
| 366 |
|
| 367 |
~Timothy Crosley |