Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Python Import Cost and UsageNew to Visual Studio Code? Get it now.
Python Import Cost and Usage

Python Import Cost and Usage

alfo

| (0) | Free
Python import module cost/disk footprints and opt-in cold/sequential time and memory profiling.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Python Import Footprint

See the installed disk footprint of Python imports in Visual Studio Code, and optionally measure their import time and memory impact.

Python Import Footprint adds inline annotations to Python files. Its default view estimates the installed files associated with each imported module, rather than showing the size of the entire distribution for every import.

from sklearn.model_selection import StratifiedKFold, cross_val_score
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.calibration import calibration_curve

In the default Module disk size view, these imports can have different estimates even though they come from the same distribution. Package-directory estimates include files in that package and its subpackages. They are not the exact size of the imported names or of everything Python loads at runtime.

Features

  • Module disk size — estimates installed files matching each imported module or package. This is the default, static view.
  • Distribution disk size — shows the total installed file size of the distribution containing an import.
  • Cold import time — measures each import statement in a fresh Python process.
  • Incremental import time — measures statements in source order in one fresh process.
  • Incremental resident memory — shows approximate RSS change for each statement in a sequential profile.
  • Automatically refreshes static analysis as you edit; runtime profile results are tied to the document version and interpreter.
  • Does not send telemetry or make external HTTP requests.

Requirements

  • Visual Studio Code 1.85 or later.
  • Python 3.8 or later.
  • For automatic interpreter selection, the Microsoft Python extension is recommended. Without it, the extension uses the configured default interpreter or falls back to python3 (python on Windows).

Install

To install a published VSIX:

  1. Download the .vsix file from the project's GitHub Releases, when available.
  2. In VS Code, open the Command Palette and run Extensions: Install from VSIX....
  3. Select the downloaded file and open a Python file.

To run the extension from a local checkout, see Development.

Use

Open a Python file to see the selected measurement displayed inline after imports. Hover over an annotation for context.

Use the Command Palette (Ctrl+Shift+P on Windows/Linux, Cmd+Shift+P on macOS) to run:

Command Purpose
Python Import Footprint: Select Metric Choose a static or runtime measurement.
Python Import Footprint: Profile Cold Imports Measure each import statement in a separate fresh Python process.
Python Import Footprint: Profile Sequential Imports Measure imports in source order in one fresh Python process.
Python Import Footprint: Refresh Sizes Re-run static analysis for visible Python files.
Python Import Footprint: Clear Cache Clear cached analysis and profiles, then refresh visible files.

Runtime measurements are not collected automatically. After profiling, choose the corresponding metric to display its results. The sequential profile selects Incremental import time by default; choose Incremental resident memory to view its memory measurements.

Measurements and interpretation

Static disk-size estimates

Static analysis reads Python source and installed distribution metadata; it does not import the target packages. It does launch the selected interpreter, so interpreter startup hooks may run. The selected interpreter determines which environment's installed packages are measured.

Module disk size sums installed files matching the dotted module path. For example, a package-directory estimate includes files beneath that directory, including subpackages. Distribution disk size sums files recorded for the full installed distribution, so imports from the same distribution can show the same value.

These are disk-footprint estimates, not imported-symbol size, process memory use, an application bundle size, or the transitive cost of imports performed at runtime. Local and standard-library imports are hidden in static size views. Relative imports are ignored, and imported names are not traced to their defining files. Some editable, namespace, or unusual installations do not expose reliable file metadata; imports whose installed files cannot be resolved are omitted rather than replaced with a distribution-wide estimate.

Runtime profiles

Profiling executes import statements from the open document in the selected Python environment. Cold profiling runs each statement in its own fresh process; sequential profiling runs statements in source order in one process. Both modes profile at most 60 import statements.

Timings cover statement execution, not interpreter startup, and can vary with operating-system caches, environment state, and first-run initialization. Sequential measurements depend on statement order. The analyzer includes imports inside functions and conditional blocks based on source order, whether or not those blocks would normally execute.

Memory measurements are approximate. Linux uses current RSS when available. On macOS, the measurement uses the process's peak RSS, so it does not accurately show memory decreases. Other platforms may also use peak RSS or may not provide a measurement.

Security

Static size analysis does not import the target packages. Runtime profiling executes imported Python modules and their initialization code, which can run arbitrary code and cause side effects. Profiling is opt-in, requires a trusted VS Code workspace, and asks for confirmation each time. Only profile code and environments you trust.

Settings

Open Preferences: Open Settings (UI) and search for Python Import Footprint.

Setting Default Description
pythonImportFootprint.enabled true Show inline annotations.
pythonImportFootprint.pythonPath "" Optional interpreter path. When empty, prefer the active interpreter from the Python extension, then the configured default interpreter, then python3 or python.
pythonImportFootprint.measurementMode module Measurement to display: module, distribution, coldTime, incrementalTime, or incrementalMemory. Runtime modes require running the corresponding profile first.
pythonImportFootprint.minimumSizeKB 0 Minimum size to display, in KiB. Applies to static size modes only.
pythonImportFootprint.maxFileSizeKB 1024 Maximum source-file size to analyze, in KiB.
pythonImportFootprint.timeoutMs 12000 Timeout for the static analyzer, in milliseconds.
pythonImportFootprint.profileProcessTimeoutSeconds 20 Timeout per cold-import process or for the whole sequential profile, in seconds (1–60).
pythonImportFootprint.showErrors false Show static analyzer diagnostics in the Python Import Footprint output channel.

Troubleshooting

  • No size annotations: Check that annotations are enabled and that the selected interpreter has the package installed. Use Refresh Sizes after changing interpreters.
  • Wrong environment is being measured: Set pythonImportFootprint.pythonPath to the desired interpreter executable.
  • No runtime annotation: Run the appropriate profiling command first. Editing the document invalidates its runtime results; profile it again.
  • Profile errors or timeouts: Check the Python Import Footprint output channel. Increase pythonImportFootprint.profileProcessTimeoutSeconds if a trusted import needs more time.

Development

Prerequisites: Node.js 20+, Python 3.8+, and Visual Studio Code.

npm install
npm run compile

Then press F5 in VS Code to launch an Extension Development Host and open a Python file in it.

Run the Python analyzer tests with:

npm run test:python

Build an installable VSIX with:

npm run package

License

MIT License.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft