Python Import Colorizer

English | 中文
A VS Code extension that colorizes Python imports by source: local or external at a glance.
Features
Core Features
- Auto-detect Import Types: Automatically analyzes
import and from ... import statements in Python files
- Distinguish Local/External Imports:
- Local imports (cyan/green): Relative imports (e.g.,
from .xxx import) and modules defined in the workspace
- External imports (yellow/brown): Third-party libraries and Python standard library modules
- Real-time Updates: Automatically updates colorization when file content changes (with 300ms debounce)
- Smart Caching: Workspace module list is cached for 10 seconds, invalidated on file changes
Supported Import Syntax
# Relative imports → Local (cyan/green)
from . import module
from ..parent_module import something
from .submodule import func
# Workspace local modules → Local (cyan/green)
from my_local_module import MyClass
import my_utils
# Third-party/standard library → External (yellow/brown)
import numpy as np
from collections import defaultdict
from django.db import models
Default Color Scheme
| Import Type |
Dark+ Theme |
Light+ Theme |
| Local |
#4EC9B0 (cyan) |
#4EC9B0 (green) |
| External |
#DCDCAA (yellow) |
#DCDCAA (brown) |
Configuration
The extension supports customizable colors via VS Code settings:
- Open Settings:
Cmd+, (Mac) or Ctrl+, (Windows/Linux)
- Search for Python Import Colorizer
- Modify the following settings:
| Setting |
Default |
Description |
pythonImportColorizer.localImportColor |
#4EC9B0 |
Color for local imports |
pythonImportColorizer.externalImportColor |
#DCDCAA |
Color for external imports |
Via settings.json
You can also edit settings.json directly:
{
"pythonImportColorizer.localImportColor": "#4EC9B0",
"pythonImportColorizer.externalImportColor": "#DCDCAA"
}
All valid CSS color formats are supported:
{
"pythonImportColorizer.localImportColor": "#FF5733",
"pythonImportColorizer.externalImportColor": "rgb(0, 128, 255)"
}
💡 Changes take effect immediately, no VS Code restart required.
Installation
Install from VSIX
- Download the
python-import-colorizer-0.0.1.vsix file
- Press
Cmd+Shift+P in VS Code to open the command palette
- Type and select Extensions: Install from VSIX...
- Select the downloaded
.vsix file
- Restart VS Code
Build from Source
# Clone the repository
git clone https://github.com/yangyuhe/python-import-colorizer.git
cd python-import-colorizer
# Install dependencies
pnpm install
# Compile TypeScript
pnpm run compile
# Package VSIX
npx @vscode/vsce package
# Install the generated .vsix file
code --install-extension python-import-colorizer-0.0.1.vsix
Usage
- Open a Python file: The extension activates automatically when you open a
.py file
- View the colorized imports: Import statements are automatically colorized
- No configuration needed: Semantic highlighting is enabled by default
Prerequisites
Ensure semantic highlighting is enabled in VS Code settings (the extension configures this automatically):
{
"editor.semanticHighlighting.enabled": true
}
Workspace Module Detection
The extension scans the workspace root directory to identify local modules:
- All
.py files (without extension) are recognized as local modules
- Directories containing
__init__.py are recognized as local packages
For example, given this workspace structure:
my_project/
├── utils.py # → import utils will be colorized as local
├── models/
│ └── __init__.py # → import models will be colorized as local
└── main.py
Development
# Compile
pnpm run compile
# Watch mode
pnpm run watch
# Run tests
pnpm test
# Debug
# Press F5 to launch Extension Development Host
License
MIT