Skip to main content

Pycograph

PyPI version Black codecov Pycograph

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

Requirements:

  • Python 3.8 or higher
  • a Redis instance with the RedisGraph module (local, remote or via Docker)
  • not strictly necessary, but recommended: RedisInsight for visualizing the query results

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.

Other Known Limitations

  • No support for .py files containing Jinja templates (e.g. cookiecutter)
  • Inner functions are ignored.

How Does It Work?

Pycograph architecture

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.11

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.11
File Size Uploaded Provenance Actions
pycograph-0.2.11.tar.gz 16.5 kB Without provenance Details for pycograph-0.2.11.tar.gz

Built distribution (wheel)

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

Total release size: 34.9 kB

Release files / pycograph-0.2.11.tar.gz

Download URL pycograph-0.2.11.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3f9c8ed9f3934da8ba3e097c178a71db3ddf3e533d62ca0ddb1f211e98061c15
BLAKE2b-256 checksum
How to use checksums
e8a0e1fcc6f37599ee4fb812336e531270a0082c1f09ca914ddb8baebd8b7ac1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.1 Linux/5.8.0-50-generic

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

Download URL pycograph-0.2.11-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c76d38995cb5e79b75ec2857d31e32571414c7a5363f980e996bf63e4199642
BLAKE2b-256 checksum
How to use checksums
565842dbed170badf6cbfcf3c988ee48ab84b76116d58d3bb3606d8b3584c54c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.1 Linux/5.8.0-50-generic

Security for pycograph 0.2.11

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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