Skip to main content

Code that graphs code

Project description

https://github.com/LaurEars/codegrapher/actions/workflows/main.yaml/badge.svg

Code that graphs code

Uses the python AST to parse Python source code and build a call graph.

Output

An example of the current output of the parser parsing itself.

parser.py

Installation

pip install codegrapher

To generate graphs, graphviz must be installed.

Usage

At the command line

To parse a file and output results to the console:

codegrapher path/to/file.py --printed

To parse a file and output results to a file:

codegrapher path/to/file.py --output output_file_name --output-type png

To analyze a directory of files, along with all files it contains:

codegrapher -r path/to/directory --output multiple_file_analysis

And if you have a list of functions that aren’t useful in your graph, add it to a .cg_ignore file:

# cg_ignore file
# all lines beginning with '#' are ignored

# every function calls this, so it's not helpful in my graph:
log_error

# I don't want to see this in my graph:
parse
lower

Then add the –ignore flag to your command. Using the flag –remove-builtins provides the same functionality for ignoring items found in __builtins__.

As a Python module

To easily parse code in Python :

from codegrapher.parser import FileObject

file_object = FileObject('path/to/file.py')
file_object.visit()

And then to add that code to a graph and render it (using graphviz):

from codegrapher.graph import FunctionGrapher

graph = FunctionGrapher()
graph.add_file_to_graph(file_object)
graph.name = 'name.gv'
graph.format = 'png'
graph.render()

Which will produce your code as a png file, name.gv.png, along with a dot file name.gv

More documentation for the Python module can be found at Read the Docs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codegrapher-0.3.0.tar.gz (56.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codegrapher-0.3.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file codegrapher-0.3.0.tar.gz.

File metadata

  • Download URL: codegrapher-0.3.0.tar.gz
  • Upload date:
  • Size: 56.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codegrapher-0.3.0.tar.gz
Algorithm Hash digest
SHA256 46ec21fc5398438f27a7112ef957d66eadbf3aeaea8a334722fcfccb95c7ad6a
MD5 587c6330554fefa281789e3195031ba9
BLAKE2b-256 995be82d497a79e8e05b88a00137fd062de0d5db468060bcabc957c91a278fcc

See more details on using hashes here.

Provenance

The following attestation bundles were made for codegrapher-0.3.0.tar.gz:

Publisher: publish.yaml on LaurEars/codegrapher

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codegrapher-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: codegrapher-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codegrapher-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a82ef9aad5dce3c666b7eb017adc30e2d51aef93d1733e53f227b80e76f6bb44
MD5 16e8f9c64cbc7e93962749b1127e1b70
BLAKE2b-256 eb20dc197259c149d743bde592a0a8cb298501341a2a6dcb345b871cb38b2408

See more details on using hashes here.

Provenance

The following attestation bundles were made for codegrapher-0.3.0-py3-none-any.whl:

Publisher: publish.yaml on LaurEars/codegrapher

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page