Optimize Imports

Automate the organizing and cleaning up of your Python imports with Optimize Imports.

Unsorted imports. Unused imports. No problem -- Optimize Imports.

PyCharm's Optimize Imports action is every Python developer's second-best friend. Along with Reformat Code, keeping your code quality tools happy is a piece of cake.

In Depth

PyCharm automates many "gardening" tasks when writing Python code. Managing your imports is one of them: with the Optimize Imports action, PyCharm cleans up your imports, using your import style preferences.

For example, Python's PEP 8 section on import style might complain that you have an unused imports, your imports aren't sorted within a group, and you have two top-level imports on the same line. Also, you might set in a project that you'd like to always split imports from the same source.

PyCharm can clean all of that up using Optimize Imports, which cleans up your imports based on settings you can save. This action can be run on a single file or across all files in a project. Also, the Commit dialog box has a checkbox to run it in the Before Commit section.

Finally, PyCharm Professional applies all of this to imports in other languages such as JavaScript and TypeScript.

Full Video

Copyright © 2000–2020 JetBrains s.r.o.