Install & Compatibility
Where this runs
tested against v0.8.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 32.1MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 2.5s · import 0.000s · 33MB
32MB installed
● package 32MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
build_graph
✓ from importlab.graph import build_graph
This is the primary function for programmatic graph construction.
This quickstart demonstrates how to use `importlab.graph.build_graph` to create a dependency graph from a list of Python file paths. It creates two dummy modules, analyzes their imports, and prints the nodes and edges of the resulting graph. The graph object returned is a networkx.DiGraph.
import os
from importlab.graph import build_graph
# Create dummy Python files for demonstration
with open('module_a.py', 'w') as f:
f.write('import module_b\ndef func_a(): pass')
with open('module_b.py', 'w') as f:
f.write('def func_b(): pass')
# Build the dependency graph
# Assuming current directory is in PYTHONPATH for this example
graph = build_graph(paths=['module_a.py', 'module_b.py'])
print('Nodes (files):', graph.nodes())
print('Edges (dependencies):', graph.edges())
# Clean up dummy files
os.remove('module_a.py')
os.remove('module_b.py')
Debug
Known issues
breakingThe `importlab` GitHub repository was archived on May 6, 2025, and is now read-only. This indicates that the library is no longer actively maintained, and no further updates, bug fixes, or new features are expected.fixUsers should be aware that the library is unmaintained. Consider forking the repository if active development is required, or seek alternative solutions for dependency graph analysis.
affects: 0.8.1 and future development
gotcha`importlab` might execute module initialization code when attempting to find dependencies, which could lead to unexpected side effects or security vulnerabilities if analyzing untrusted or malformed code.fixExercise caution when using `importlab` on untrusted Python code. Review the code to be analyzed for potential side effects or ensure a sandboxed environment for analysis.
affects: All versions
breakingSupport for Python 2 was officially dropped in version 0.6.1. Using `importlab` with Python 2 will result in errors.fixEnsure your project uses Python 3.6 or newer (as per `requires_python` metadata) when using `importlab` versions 0.6.1 or later.
affects: < 0.6.1 (supported), >= 0.6.1 (unsupported)
gotchaWhile `importlab` infers dependencies, the resulting graph object is a `networkx.DiGraph`. Users needing to traverse, query, or manipulate this graph extensively will likely require familiarity with the `networkx` library's API.fixFamiliarize yourself with the `networkx` library's documentation to effectively work with the graphs generated by `importlab`.
affects: All versions
Upgrade
Version history
0.8.1latest on PyPI · released Oct 6, 2023
Audit
Dependencies
networkxrequiredUsed internally to represent the dependency graph, which may be exposed to users.
Resources
No resource links recorded.