Copy the correct absolute Python import for any symbol — right from your editor.
- 🔍 Smart symbol resolution — uses VS Code's built-in definition provider to find the correct source
- 📦 Accurate module paths — converts file paths into proper Python dotted module paths
- 🏗️
__init__.pyhandling — correctly resolves package imports - 📁
src-layout support — strip custom source roots (e.g.src/) via configuration - 📋 One-click copy — import statement goes straight to your clipboard
Place your cursor on get_current_user and trigger the command:
Copied: from myapp.auth.utils import get_current_user
| Command | ID | macOS | Windows / Linux |
|---|---|---|---|
| Copy Python Import | python-import-copier.copyPythonImport |
Cmd+U |
Ctrl+U |
- Open any Python file
- Place your cursor on a symbol (function, class, variable, etc.)
- Press
Cmd+U(macOS) orCtrl+U(Windows/Linux) - The import statement is copied to your clipboard ✅
If your project uses a src-layout, set this to strip the source directory prefix from generated module paths.
Settings JSON:
{
"python-import-copier.pythonSourceRoot": "src"
}Example:
| Definition file | Without source root | With "src" |
|---|---|---|
src/mypkg/utils.py |
src.mypkg.utils |
mypkg.utils |
- Reads the active editor and cursor position
- Resolves the symbol definition via
vscode.executeDefinitionProvider - Locates the workspace folder containing the definition file
- Converts the file path to a Python module path (handles
__init__.pyautomatically) - Determines the symbol name using document symbols, then falls back to line parsing (supports
async def) - Builds
from <module> import <symbol>, copies it to the clipboard, and shows a notification
If a definition resolves to <workspace>/__init__.py, Python Import Copier maps it to the workspace folder name when that name is a valid Python identifier.
# Install dependencies
npm install
# Compile TypeScript
npm run compile
# Watch for changes
npm run watchPress F5 in VS Code to launch the Extension Development Host for testing.