Skip to main content

Pycograph

PyPI version Black

Pycograph

Homepage: https://pycograph.com/
PyPI: https://pypi.org/project/pycograph/

Explore your Python code with graph queries

Pycograph creates a RedisGraph model of your Python code. You can:

sample Redis Insight result

Getting Started

Install Pycograph from PyPI:

pip install pycograph

Start a Redis instance with the RedisGraph module and RedisInsight. E.g. via Docker containers:

docker run -d -p 6379:6379 redislabs/redismod
docker run -d -v redisinsight:/db -p 8001:8001 redislabs/redisinsight:latest

Visit your RedisInstance at http://localhost:8001 in a browser.
Connect to your local Redis database.

Create a RedisGraph model of your project's code with the pycograph load command:

pycograph load --project-dir ~/code/your-project --test-types

By default, if you don't provide the --project-dir option, Pycograph tries to find Python code in the current working directory.

Run a query in RedisInsight. E.g.

GRAPH.QUERY "your-project" "MATCH (n) return n"

To see some more advanced queries, check out the examples at pycograph.com

Options

  • --project-dir: The root directory of the Python project you want to analyze. If you omit this option, Pycograph will search for .py files in your current working directory.
  • --graph-name: Specifies the name of the generated graph. Default: the name of the project directory.
  • --overwrite: If a graph with this name exists overwrite it. If you don't provide this flag, the new nodes and edges will be appended to the graph.
  • --test-types: Determine the types of tests based on the subdirectories of the tests directory.
  • --redis-host: The host of the Redis instance. Default: localhost
  • --redis-port: The port of the Redis instance. Default: 6379
  • --version: Print Pycograph version and exit.

Limitations

Pycograph is in beta version.

It creates a basic model with focus on the relationships betweeen the different parts of the code base. Even that model might be incomplete, ignoring some less common syntax. The goal is to provide some useful insight, not to create an exhaustive model.

If Pycograph finds a syntax error, it skips the module containing the syntax error and tries to build a model from the rest of the code base.

Below are some of the limitations. If you bump into other limitations, please open a GitHub issue.

Imports

The following imports will be ignored by Pycograph:

  • imported external packages
  • import * syntax
  • variables
  • globals

Calls

  • All the limitations of the imports.
  • Resolving longer calls of more than 2 levels.

Other Known Limitations

  • No support for .py files containing Jinja templates (e.g. cookiecutter)

How Does It Work?

flow of loading code: source => RedisGraph

Libraries used:

  • ast module of the Python standard library for the abstract syntax tree
  • Pydantic both for the models of the intermediate objects and for the settings
  • redisgraph-py for creating the RedisGraph model
  • typer for the command line interface

Contributing

see the Contributing guide

Metadata

Release files for pycograph 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycograph 0.2.3
File Size Uploaded
pycograph-0.2.3.tar.gz 12.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycograph 0.2.3
File Interpreter ABI Platform
pycograph-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 26.1 kB

Release files / pycograph-0.2.3.tar.gz

Download URL pycograph-0.2.3.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0e1543181988e81060884938c03bce2a4018acf0616d29fd3d4dc95173e713e0
BLAKE2b-256 checksum
How to use checksums
9e856e523e7466a80fd0f4eee3ed38258fd0fabc6ca837fa626ee507e59463e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.1 Linux/5.8.0-50-generic

Release files / pycograph-0.2.3-py3-none-any.whl

Download URL pycograph-0.2.3-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
77418816cf3c51f85ed21f7915c0f7b0b62f1b78132232524915f85292f957ba
BLAKE2b-256 checksum
How to use checksums
b4f349b66b0e99608301741b8f4fad7565e68f7ab22ff4e14a7a684815abf046
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.1 Linux/5.8.0-50-generic

Release history Release notifications | RSS feed

0.3.0

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page