VS Code - sort Python imports automatically

· Tech · No AI

I really like when the VS Code sorts Python imports on file save, it’s a perfect addition to the Black code formatter.

VS Code  - sort Python imports automatically

To enable this option, you need the isort utility.

Terminal window
pipenv install isort --dev

Now let’s enable it. Open the settings (⇧⌘P or Ctrl+Shift+P), find Preferences: Configure Language Specific Settings... and then find the Python. It will open the settings.json file. The configuration is very simple.

"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
}

That’s all. Whenever you save the *.py file, the VS Code will run isort automatically to sort the imports.


VS Code documentation: https://code.visualstudio.com/docs/python/editing#_sort-imports

uptime
8,240 days · since 2004
posts
295 · busiest 2026 (65)
words
~144,041 · ~10 h read
topics
tech 240 · personal 55
langs
en 230 · pl 65
written
211 by hand · 84 AI-assisted
projects
3
build
ef72eda · 2026-07-24