Understanding python.analysis.showOnlyDirectDependenciesInAutoImport in Pylance

April 10, 2026 · View on GitHub

What It Does

When enabled, Pylance filters auto-import completion suggestions to show only packages declared as direct dependencies in your project's requirements.txt or pyproject.toml. This reduces noise from transitive dependencies and keeps completion lists focused on packages you actually use.

This setting affects auto-import completions only — the symbols that appear in the completion list with an import icon. The "Add import" code action (light bulb / Ctrl+.) continues to show all possible imports regardless of this setting.

Accepted Values

ValueBehavior
false (default)Auto-import completions suggest symbols from all installed packages
trueAuto-import completions suggest symbols only from direct dependencies and user files

How Direct Dependencies Are Detected

Pylance reads the following files in your workspace root:

  • requirements.txt — including recursive -r includes
  • pyproject.toml — both [project.dependencies] and [tool.poetry.dependencies] sections

Distribution names are automatically mapped to top-level module names (e.g., scikit-learnsklearn, PillowPIL).

If neither file exists, the setting has no effect — all packages are shown as if the setting were false.

Language Server Mode Defaults

ModeDefault value
defaultfalse
lightfalse
fulltrue

In full mode, this setting is enabled by default to improve the relevance of auto-import suggestions alongside the broader indexing depth.

Example

{
    "python.analysis.showOnlyDirectDependenciesInAutoImport": true
}

With this enabled and a requirements.txt containing:

flask
requests

Auto-import completions will suggest symbols from flask, requests, the standard library, and your own workspace files — but not from transitive dependencies like werkzeug, urllib3, or certifi.

When to Enable

  • Your project has many installed packages but you only import from a small set of direct dependencies.
  • The completion list is cluttered with suggestions from packages you don't directly use.
  • You are in default or light mode and want the focused suggestion behavior that full mode provides by default.

When to Disable

  • Your project intentionally imports from transitive dependencies (e.g., werkzeug utilities in a Flask project).
  • You don't maintain a requirements.txt or pyproject.toml and want all installed packages available.

This document was generated with the assistance of AI and has been reviewed by humans for accuracy and completeness.