DEV Community

Cover image for Important: A VS Code Extension That Keeps Your Python Imports Clean
Ira Rainey
Ira Rainey

Posted on

Important: A VS Code Extension That Keeps Your Python Imports Clean

If you've ever spent time manually cleaning up Python imports after a review comment saying "wrong order" or "import the module, not the symbol", you'll appreciate this.

Important is a free, open-source VS Code extension that validates and auto-fixes Python import statements according to the Google Python Style Guide and PEP 8. It gives you real-time feedback as you type and can fix every issue it raises with a single command.

Why another import tool?

Ruff and isort are great at sorting imports, but they don't enforce the style rules that teams adopting the Google guide care about — things like importing modules instead of symbols, banning wildcards, or flagging unjustified aliases. Important fills that gap, and its output is designed to be Ruff-compatible so the two tools don't fight each other.

What does it do?

Here's a quick overview of what Important validates and fixes:

Rule Example Auto-Fix
No relative imports from .module import x → absolute
No wildcard imports from os.path import * → qualified access
One import per line import os, sys → separate lines
Import modules, not symbols from PIL import Imageimport PIL
Standard aliases only import numpy as npyimport numpy as np
Justified from-aliases only Flags pointless as renames
Unused imports Removes dead imports
Duplicate imports Merges duplicates
Correct ordering __future__ → stdlib → third-party → first-party → local
Sorted within groups import before from, then alphabetical
Misplaced imports Lazy imports inside functions get relocated

Every rule has an auto-fix — no manual intervention required.

See it in action

Take this messy import block:

import requests
import os, sys
from os.path import *
from models.user import User
import json

print(abspath("."))
user = User()
Enter fullscreen mode Exit fullscreen mode

Run "Important: Fix Imports in This File" (Ctrl+K, Ctrl+Shift+F) and you get:

import json
import os
import sys

import requests

from models import user

print(os.path.abspath("."))
user = user.User()
Enter fullscreen mode Exit fullscreen mode

Imports are split, sorted into groups, wildcard usage is converted to qualified access, and symbol imports are rewritten to module imports — all references in your file are updated automatically.

Real-time diagnostics

You don't need to run the fix command to see problems. Important validates as you type, highlighting issues directly in the editor:

  • Warnings for rule violations (wrong order, wildcards, symbol imports)
  • Faded text for unused imports (matching VS Code's convention)
  • Hover info explaining exactly what's wrong and why

Each diagnostic links to the relevant style guide rule, so you learn the conventions as you go.

Smart features

A few things that set Important apart from a basic linter:

Ruff-compatible output

Sorted imports match Ruff/isort defaults — import before from, order-by-type name sorting (CONSTANT_CASECamelCasesnake_case), aliased imports kept on separate lines. You can run both tools without conflicts.

Multi-line formatting

Long from imports are automatically wrapped into Ruff-style parenthesised multi-line format when they exceed the line length:

from mypackage.models import (
    BaseModel,
    ConfigModel,
    UserModel,
)
Enter fullscreen mode Exit fullscreen mode

The line length is auto-detected from your pyproject.toml ([tool.ruff]line-length) or can be set manually.

if TYPE_CHECKING support

Imports inside if TYPE_CHECKING: blocks are handled correctly — all sorting and validation rules apply within the block, but the import-modules-not-symbols rule is relaxed since these imports exist purely for type annotations.

First-party module detection

Important automatically reads known-first-party from [tool.ruff.lint.isort] in your pyproject.toml and groups those imports correctly between third-party and local. Monorepo support is built in — nested pyproject.toml files scope their first-party modules to the relevant subtree.

Inline suppression

Need to keep a specific import the way it is? Add a # noqa: important comment:

from os.path import join  # noqa: important[import-modules-not-symbols]
Enter fullscreen mode Exit fullscreen mode

You can also use a quick-fix action to add the suppression comment directly from the editor.

Configuration

All settings live under important.* in VS Code:

{
  "important.validateOnSave": true,
  "important.validateOnType": true,
  "important.styleGuide": "google",
  "important.knownFirstParty": ["myproject"],
  "important.readFromPyprojectToml": true,
  "important.lineLength": 0
}
Enter fullscreen mode Exit fullscreen mode

Setting lineLength to 0 (the default) auto-detects from pyproject.toml, falling back to 88.

Install it

You can install Important directly from the VS Code Marketplace:

👉 Install Important

Or search for "Important" in the VS Code Extensions panel (Ctrl+Shift+X).

The source is on GitHub under the MIT licence — contributions and issues welcome.


If you work on a Python codebase that follows (or wants to follow) the Google Style Guide, give Important a try. It catches the things that linters miss and fixes them without you lifting a finger.

Top comments (0)