Tidy your imports with isort
Manually organizing imports can be a pain. isort makes it easy to automatically sort Python imports by arranging them into alphabetical order within different groups:
- Python standard library dependencies
- Third-party dependencies
- Local dependencies
For example, take these imports:
from my_lib import Object
import os
from my_lib import Object3
from my_lib import Object2
import sys
from third_party import lib15, lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12, lib13, lib14
import sys
from __future__ import absolute_import
from third_party import lib3
They're all over the place. With isort's help, you'll get perfectly organized imports in your Python files:
import os
import sys
from third_party import (lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8,
lib9, lib10, lib11, lib12, lib13, lib14, lib15)
from my_lib import Object, Object2, Object3
With Pyrfecter, because Black auto-formatting is built in, your imports look even better:
from __future__ import absolute_import
import os
import sys
from my_lib import Object, Object2, Object3
from third_party import (
lib1,
lib2,
lib3,
lib4,
lib5,
lib6,
lib7,
lib8,
lib9,
lib10,
lib11,
lib12,
lib13,
lib14,
lib15,
)
So, what are you waiting for? Pyrfect those imports!