Create a RedisGraph model of a Python code base.
Project description
Pycograph
Homepage: https://pycograph.com/
PyPI: https://pypi.org/project/pycograph/
RedisConf 2021 talk
Explore your Python code with graph queries
Pycograph creates a RedisGraph model of your Python code. You can:
- query it with Cypher
- visualize it with RedisInsight
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 thetests
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?
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pycograph-0.3.0.tar.gz
.
File metadata
- Download URL: pycograph-0.3.0.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.11.0-25-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaa26a7911630e7d5d098a4332982d018e584eead17d91feab82817a9af140b8 |
|
MD5 | 30a079a0636a2dbd037796625e8e94b9 |
|
BLAKE2b-256 | 9a70fc2cf44eae76267e19051ec9ef489c3e8138e3fa61f21726fa897838915d |
File details
Details for the file pycograph-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: pycograph-0.3.0-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.11.0-25-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 146dbea6c6dae699563d6445a7e5621e73103be9a772a2c5b968993661eefcfa |
|
MD5 | e1602c8c381a45c0badc5ae4d24da30f |
|
BLAKE2b-256 | d4e183454d1cb5ec0765137dd2d33b902cc012ff711e777a0075cfdacc79367a |