Python Import FootprintSee 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.
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
Requirements
InstallTo install a published VSIX:
To run the extension from a local checkout, see Development. UseOpen a Python file to see the selected measurement displayed inline after imports. Hover over an annotation for context. Use the Command Palette (
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 interpretationStatic disk-size estimatesStatic 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 profilesProfiling 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. SecurityStatic 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. SettingsOpen Preferences: Open Settings (UI) and search for
Troubleshooting
DevelopmentPrerequisites: Node.js 20+, Python 3.8+, and Visual Studio Code.
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:
Build an installable VSIX with:
LicenseMIT License. |