{"id":23126,"library":"modulegraph","title":"modulegraph","description":"Python module dependency analysis tool that builds a directed graph of module dependencies. Current version 0.19.7, maintained by Ronald Oussoren. Releases are irregular, primarily as needed.","status":"active","version":"0.19.7","language":"python","source_language":"en","source_url":"https://github.com/ronaldoussoren/modulegraph","tags":["modulegraph","dependency","graph","analysis","static analysis","python"],"install":[{"cmd":"pip install modulegraph","lang":"bash","label":"Install via pip"}],"dependencies":[{"reason":"Required for pkg_resources checks during dependency resolution","package":"setuptools","optional":false}],"imports":[{"note":"The main module is importable directly.","symbol":"modulegraph","correct":"import modulegraph"},{"note":"Do not use the dotted path; simply import from modulegraph.","wrong":"from modulegraph.modulegraph import ModuleGraph","symbol":"ModuleGraph","correct":"from modulegraph import ModuleGraph"}],"quickstart":{"code":"from modulegraph import ModuleGraph\ng = ModuleGraph()\ng.run_script('example.py')\nfor node in g.nodes():\n    print(node.identifier, node.filename)","lang":"python","description":"Analyze dependencies of a Python script."},"warnings":[{"fix":"Use node.identifier and node.filename (now always a str) instead of node.type or node.filename (could be None).","message":"In modulegraph 0.18 and later, the internal node attributes changed. Accessing 'type' or 'filename' directly on a node may break if you relied on old values.","severity":"breaking","affected_versions":">=0.18.0"},{"fix":"Replace calls to g.find_modules('script.py') with g.run_script('script.py').","message":"The 'find_modules' method is deprecated in favor of 'run_script' and 'import_hook'.","severity":"deprecated","affected_versions":">=0.17.0"},{"fix":"Always instantiate a new ModuleGraph() for each independent dependency analysis.","message":"ModuleGraph does not automatically re-analyze if the script's imports change. You must create a new graph instance for a fresh analysis.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'pip install modulegraph' in your environment.","cause":"Modulegraph not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'modulegraph'"},{"fix":"Use 'run_script' instead: g.run_script('your_script.py').","cause":"Using deprecated API removed since version 0.18.","error":"AttributeError: 'ModuleGraph' object has no attribute 'find_modules'"},{"fix":"Check if node.filename is not None before using it, or use getattr(node, 'filename', '').","cause":"Node may not have a filename (e.g., built-in modules). In older versions, filename could be None.","error":"TypeError: 'NoneType' object is not subscriptable (when accessing node.filename)"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}