Registry / testing / pycg
library0.0.8pypypiunverified

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.

pip install pycg
INSTALL
IMPORT
SIG · PYCG
P
pycg
testingpythonv0.0.8
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.8 · 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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CallGraphGenerator
from PyCG import CallGraphGenerator
from pycg import CallGraphGenerator

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.

from pycg import CallGraphGenerator from pycg import formats # Example: generate call graph for a single file # Note: pycg works best with a top-level script entry point # For this example, we'll assume you have a file 'myscript.py' # that defines functions and calls. # The generator returns a dictionary of call edges. generator = CallGraphGenerator(['myscript.py'], 'myscript') # The second argument is the package name (usually module name) generator.analyze() # Get call graph in JSON format formatter = formats.JSONFormatter(generator) output = formatter.generate() print(output)
pycg --version
Debug
Known issues
gotchaPyCG 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.
fix
Pass the module name (the name you would use in imports, e.g., 'myscript' for myscript.py).
affects: all
gotchaPyCG 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.
fix
Use pycg as a supplementary tool; combine with runtime tracing for full coverage.
affects: all
deprecatedPyCG 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.
fix
Consider using alternatives like `pyan` or `code2flow` for better Python 3.10+ support.
affects: >=3.10
Upgrade
Version history
0.0.8latest on PyPI · released Nov 26, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
10
Resources
pycg — pip install pycg · libregistry