{"id":23149,"library":"pycg","title":"PyCG - Practical Python Call Graphs","description":"PyCG is a tool for generating call graphs for Python code using static analysis. It produces call graphs in JSON format and supports Python >=3.4. The current version on PyPI is 0.0.8. Development is relatively low activity; last commits on GitHub appear to be from 2022. The primary use case is understanding static call relationships in Python programs.","status":"maintenance","version":"0.0.8","language":"python","source_language":"en","source_url":"https://github.com/vitsalis/PyCG","tags":["call-graph","static-analysis","python","dependency-graph"],"install":[{"cmd":"pip install pycg","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Import the main generator class directly","symbol":"CallGraphGenerator","correct":"from pycg import CallGraphGenerator"},{"note":"Module for output formatting (JSON, etc.)","symbol":"formats","correct":"from pycg import formats"}],"quickstart":{"code":"from pycg import CallGraphGenerator\nfrom pycg import formats\n\n# Example: generate call graph for a single file\n# Note: pycg works best with a top-level script entry point\n# For this example, we'll assume you have a file 'myscript.py'\n# that defines functions and calls.\n# The generator returns a dictionary of call edges.\n\ngenerator = CallGraphGenerator(['myscript.py'], 'myscript')\n# The second argument is the package name (usually module name)\ngenerator.analyze()\n\n# Get call graph in JSON format\nformatter = formats.JSONFormatter(generator)\noutput = formatter.generate()\nprint(output)\n","lang":"python","description":"Basic usage to generate a JSON call graph for a Python file. Note that pycg expects a list of file paths and a package name."},"warnings":[{"fix":"Pass the module name (the name you would use in imports, e.g., 'myscript' for myscript.py).","message":"PyCG requires the second argument to be the package/module name (e.g., 'mymodule'), not just a label. Mistakenly using a file path or empty string can cause unexpected behavior or empty output.","severity":"gotcha","affected_versions":"all"},{"fix":"Use pycg as a supplementary tool; combine with runtime tracing for full coverage.","message":"PyCG only analyzes the statically visible call graph; it does not resolve dynamic calls (e.g., through eval, getattr, or decorators that obscure call sites). Results may be incomplete for heavily dynamic code.","severity":"gotcha","affected_versions":"all"},{"fix":"Consider using alternatives like `pyan` or `code2flow` for better Python 3.10+ support.","message":"PyCG has not been actively maintained since 2022. There are known issues with Python 3.10+ regarding changes to the ast module. The project may not work correctly with newer Python versions.","severity":"deprecated","affected_versions":">=3.10"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `pip install pycg` in your current environment. Ensure you are using the same Python interpreter.","cause":"PyCG is not installed, or installed in a different environment.","error":"ModuleNotFoundError: No module named 'pycg'"},{"fix":"Change `CallGraphGenerator([file])` to `CallGraphGenerator([file], 'my_package_name')`.","cause":"The CallGraphGenerator constructor requires a package name as the second argument.","error":"TypeError: __init__() missing 1 required positional argument: 'package_name'"},{"fix":"Use `formats.JSONFormatter(generator).generate()` to get a properly formatted JSON object.","cause":"The output format may have changed; accessing raw generator data instead of using the formatter.","error":"KeyError: 'caller' (when accessing output)"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}