A Python implementation of a Code Property Graph.
Project description
Code Property Graph
This library is an implementation of a Code Property Graph as seen in the paper published by Fabian Yamaguchi on Modeling and Discovering Vulnerabilities with Code Property Graphs
A code property graph is a highly efficient data structure designed to mine large codebases for similar programming patterns. The data structure can be loaded into a graph database where properties of code can be queried. Code property graphs are intended to be code-agnostic and highly scalable making it one of the best choices for code representation.
Running as a Library
Installation
Requires:
Python 3
pip3
pip install codepropertygraph
Using the code as a library
from codepropertygraph import CPG
code = """a = 1; b = 2; print(a + b)"""
graph = CPG(code)
print(graph)
> Graph(Nodes(a, b), Edges([a, b]))
Running from Source
Setting up Neo4J locally
- Download Neo4J Desktop v4.4.5 to create local graph databases locally and remotely from your desktop. If the latest version has changed, use this link to download the version used for development.
- Create a new project and a new local graph database as shown below. It might take a few moments to finish loading.
- Start the database. Make sure the DB is active before heading onto the Installation and Running the application sections.
Starting the database | Active Database |
---|---|
Installation
To install the repository, you need to clone it and run it inside a virtual environment. Running main.py
generates a Code Property Graph of the simple addition script inside examples/
and saves it to output/
.
git clone https://github.com/markgacoka/codepropertygraph.git
cd codepropertygraph
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Running the Application
python main.py
Testing
pytest tests
For first time contributors, read the CONTRIBUTING page.
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
Hashes for codepropertygraph-0.0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d00ed7764e151b464eabfb04e0f28c70a2a9b8bb64dd7c747bbe07c22a42d2e |
|
MD5 | de171cba03357e55f00d3e3687c2a402 |
|
BLAKE2b-256 | 33787a045da160b6f06815eda1e68de48b69b7e43585d7032a5807ee3fc312ed |