{"id":5638,"library":"grimp","title":"Grimp","description":"Grimp is a Python library (version 3.14) that builds a queryable graph of the imports within one or more Python packages. It provides tools for static analysis of import relationships and is actively maintained with regular updates for features and fixes.","status":"active","version":"3.14","language":"en","source_language":"en","source_url":"https://github.com/grimp-dev/grimp","tags":["static analysis","code analysis","dependency graph","imports","software engineering"],"install":[{"cmd":"pip install grimp","lang":"bash","label":"Install Grimp"}],"dependencies":[{"reason":"Requires Python 3.10 or higher as per PyPI metadata.","package":"Python","optional":false}],"imports":[{"note":"This is a common pattern for accessing the core graph object. Exact path may vary slightly based on Grimp's internal structure; verify with official docs.","symbol":"ImportGraph","correct":"from grimp.application.ports.import_graph import ImportGraph"},{"note":"Common function for constructing an import graph from a file path. Verify exact module path.","symbol":"build_graph_from_path","correct":"from grimp.application.usecases import build_graph_from_path"}],"quickstart":{"code":"import os\nfrom grimp.application.usecases import build_graph_from_path\n\n# Create a dummy package structure for demonstration\nos.makedirs('my_package/submodule', exist_ok=True)\nwith open('my_package/__init__.py', 'w') as f: f.write('')\nwith open('my_package/module_a.py', 'w') as f: f.write('from .module_b import B')\nwith open('my_package/module_b.py', 'w') as f: f.write('from my_package.submodule import C')\nwith open('my_package/submodule/__init__.py', 'w') as f: f.write('')\nwith open('my_package/submodule/module_c.py', 'w') as f: f.write('import os')\n\n\n# Build the import graph for 'my_package'\npackage_path = 'my_package'\npackage_name = 'my_package'\n\n# NOTE: The exact function signature and import path might vary slightly.\n# Refer to Grimp's official documentation for the precise quickstart.\ntry:\n    graph = build_graph_from_path(package_name, package_path)\n    print(f\"Nodes in graph: {graph.modules()}\")\n    print(f\"Direct imports from module_a: {graph.direct_imports_for_module('my_package.module_a')}\")\n    # Cleanup dummy files\n    import shutil\n    shutil.rmtree('my_package')\nexcept ImportError as e:\n    print(f\"Could not build graph, ensure grimp is installed and paths are correct: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to build an import graph for a sample Python package. It creates a temporary package structure, uses `build_graph_from_path` to analyze its imports, and then queries the resulting graph. The code includes a basic cleanup for the created files."},"warnings":[{"fix":"Manually inspect dynamic import sites or use runtime analysis tools in conjunction with Grimp for a complete picture.","message":"Grimp performs static analysis and may not accurately reflect imports that are dynamically loaded (e.g., using `importlib` or conditional imports based on runtime conditions). Always verify results for complex import patterns.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review the official Grimp documentation and release notes for updated import paths and API changes during upgrades. Update your import statements and method calls accordingly.","message":"The internal API structure, especially module paths for core functions like `build_graph_from_path` or `ImportGraph`, might change between major or even minor versions. Always consult the release notes when upgrading.","severity":"breaking","affected_versions":"Potentially between major and minor releases (e.g., 2.x to 3.x)"},{"fix":"Run Grimp in a virtual environment configured with the target project's Python version and dependencies. Explicitly set `sys.path` if necessary to include all relevant source roots.","message":"Grimp's analysis relies on the Python environment it's run in. If analyzing code that targets a different Python version or has specific `sys.path` configurations, Grimp might not resolve imports correctly. Ensure your analysis environment matches the target project's setup.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-08T00:00:00.000Z","next_check":"2026-07-07T00:00:00.000Z"}