VS Code extension that adds support for user-defined (custom) auto-import suggestions for Python.
Such as import datetime as dt or import sqlalchemy as sa.

Motivation
The default Python language server (Pylance) only suggests auto-imports for a
small handful of abbreviations such as import numpy as np
(see #2589).
This list is not configurable by users and doesn't include abbreviations I use
quite frequently such as import datetime as dt or import sqlalchemy as sa.
Pylance also only recommends completions for symbols defined in files that it indexes.
By default, Pylance indexes only the top-level modules of packages, which means that
it won't recommend imports such as from sqlalchemy.orm import Session. However, you
can increase the indexing depth (for specific or all packages), but this can impact
performance.
Usage
This extension lets you define your own abbreviations or symbols for auto-import suggestions.
You can define custom imports via settings.json (user or workspace). Auto-import suggestions
are provided using values from both user and workspace settings.
"customPyAutoImport.imports": {
"dt.": "import datetime as dt",
"sa.": "import sqlalchemy as sa",
"Session": "from sqlalchemy.orm import Session"
}
Configuration can also be done via the Settings (UI) as shown below -

If editor.quickSuggestions is enabled, you will see completions as you type. Otherwise, completions
are triggered when you type . (for aliases) or ? (for other symbols). You can also trigger
completions via the triggerSuggest keyboard shortcut in VS Code (Ctrl+Space by default).
Import insertion
New imports are inserted in a sensible place:
- Next to existing imports if they already exist (does not consider
from __future__ imports).
- Otherwise, before the first non-comment, non-empty, non-docstring line.
However, inserted imports are not merged with existing imports from the same module or sorted.
Use isort, ruff or other tooling to organize and clean up imports.