Skip to main content

A Python implementation of a Code Property Graph.

Project description

Code Property Graph

Github Stars badge GitHub release (latest SemVer) badge Maintenance badge

Code Property Graph Logo

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.

Code Property Graph Demo

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]))

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

Run all tests

pytest tests

Updating Library

  1. Change the version number
--> VERSION="0.0.9"
DESCRIPTION="A Python implementation of a Code Property Graph."
LONG_DESCRIPTION="A tool for ..."

setup(
    name='codepropertygraph',
    version=VERSION,
  1. Upload to Pypi
python setup.py sdist bdist_wheel
pip install twine
twine upload dist/*

For first time contributors, read the CONTRIBUTING page.

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

codepropertygraph-0.1.0.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

codepropertygraph-0.1.0-py3-none-any.whl (3.2 kB view hashes)

Uploaded Python 3

Supported by

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