## Code Property Graph
<p align="center">
<a href="https://github.com/markgacoka/codepropertygraph/pulse" alt="Stars"><img align="center" alt="Github Stars badge" src="https://img.shields.io/github/stars/markgacoka/codepropertygraph?style=flat-square"></a>
<a href="https://github.com/markgacoka/codepropertygraph/releases" alt="Release"><img align="center" alt="GitHub release (latest SemVer) badge" src="https://img.shields.io/github/v/release/markgacoka/codepropertygraph?style=flat-square"></a>
<a href="https://github.com/markgacoka/codepropertygraph/graphs/contributors" alt="Maintained"><img align="center" alt="Maintenance badge" src="https://img.shields.io/maintenance/yes/2022?style=flat-square"></a>
</p>
<p align="center"><img align="center" alt="Code Property Graph Logo" src="https://raw.githubusercontent.com/markgacoka/codepropertygraph/f86397bccb0e6077b08d3ef2bad6e08e1729912c/codepropertygraph/cpg.png"></p>
This library is an implementation of a Code Property Graph as seen in the paper published by [Fabian Yamaguchi](https://fabianyamaguchi.com/) on *Modeling and Discovering Vulnerabilities with [Code Property Graphs](https://www.sec.cs.tu-bs.de/pubs/2014-ieeesp.pdf)*
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](https://raw.githubusercontent.com/markgacoka/codepropertygraph/main/codepropertygraph/cpg_arrow.png)
## Running as a Library
### Installation
Requires:
- `Python 3`
- `pip3`
```
pip install codepropertygraph
```
### Using the code as a library
```python
import os
from dotenv import load_dotenv
from codepropertygraph import get_neo4j_connection
load_dotenv()
USERNAME = os.environ["NEO4J_USERNAME"]
PASSWORD = os.environ["NEO4J_PASSWORD"]
URI = "neo4j+s://cb8ae961.databases.neo4j.io"
# Attempt to get a connection
driver = get_neo4j_connection(URI, (USERNAME, PASSWORD))
# If the connection is successful, you can use the driver
if driver:
with driver.session(database="neo4j") as session:
result = session.run("MATCH (n) RETURN count(n) AS node_count")
node_count = result.single()["node_count"]
print(f"Number of nodes in the database: {node_count}")
driver.close()
> Number of nodes in the database: 0
```
Raw data
{
"_id": null,
"home_page": "https://github.com/markgacoka/codepropertygraph",
"name": "codepropertygraph",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9.0",
"maintainer_email": null,
"keywords": "cybersecurity, static analysis, code tokenization, property graph",
"author": "Gacoka Mbui",
"author_email": "markgacoka@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/05/86/c0722e4490971792469effe32c71cd55b0e6d18d36daf3194541c8e04913/codepropertygraph-0.1.2.tar.gz",
"platform": null,
"description": "## Code Property Graph\n<p align=\"center\">\n <a href=\"https://github.com/markgacoka/codepropertygraph/pulse\" alt=\"Stars\"><img align=\"center\" alt=\"Github Stars badge\" src=\"https://img.shields.io/github/stars/markgacoka/codepropertygraph?style=flat-square\"></a>\n <a href=\"https://github.com/markgacoka/codepropertygraph/releases\" alt=\"Release\"><img align=\"center\" alt=\"GitHub release (latest SemVer) badge\" src=\"https://img.shields.io/github/v/release/markgacoka/codepropertygraph?style=flat-square\"></a>\n <a href=\"https://github.com/markgacoka/codepropertygraph/graphs/contributors\" alt=\"Maintained\"><img align=\"center\" alt=\"Maintenance badge\" src=\"https://img.shields.io/maintenance/yes/2022?style=flat-square\"></a>\n</p>\n\n<p align=\"center\"><img align=\"center\" alt=\"Code Property Graph Logo\" src=\"https://raw.githubusercontent.com/markgacoka/codepropertygraph/f86397bccb0e6077b08d3ef2bad6e08e1729912c/codepropertygraph/cpg.png\"></p>\n\nThis library is an implementation of a Code Property Graph as seen in the paper published by [Fabian Yamaguchi](https://fabianyamaguchi.com/) on *Modeling and Discovering Vulnerabilities with [Code Property Graphs](https://www.sec.cs.tu-bs.de/pubs/2014-ieeesp.pdf)*\n\nA 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.\n\n![Code Property Graph Demo](https://raw.githubusercontent.com/markgacoka/codepropertygraph/main/codepropertygraph/cpg_arrow.png)\n\n## Running as a Library\n### Installation\nRequires:\n- `Python 3`\n- `pip3`\n```\npip install codepropertygraph\n```\n\n### Using the code as a library\n```python\nimport os\nfrom dotenv import load_dotenv\nfrom codepropertygraph import get_neo4j_connection\n\nload_dotenv()\nUSERNAME = os.environ[\"NEO4J_USERNAME\"]\nPASSWORD = os.environ[\"NEO4J_PASSWORD\"]\nURI = \"neo4j+s://cb8ae961.databases.neo4j.io\"\n\n# Attempt to get a connection\ndriver = get_neo4j_connection(URI, (USERNAME, PASSWORD))\n\n# If the connection is successful, you can use the driver\nif driver:\n with driver.session(database=\"neo4j\") as session:\n result = session.run(\"MATCH (n) RETURN count(n) AS node_count\")\n node_count = result.single()[\"node_count\"]\n print(f\"Number of nodes in the database: {node_count}\")\n \n driver.close()\n\n> Number of nodes in the database: 0\n```\n\n\n\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "A Python implementation of a Code Property Graph.",
"version": "0.1.2",
"project_urls": {
"Download": "https://github.com/markgacoka/codepropertygraph/releases",
"Homepage": "https://github.com/markgacoka/codepropertygraph"
},
"split_keywords": [
"cybersecurity",
" static analysis",
" code tokenization",
" property graph"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8f8055a81a617fab6f3a828568de1b98aa8207e59ff6ec66905016cfc12f2a0f",
"md5": "677b7270c25d64cb758474b86cf931ae",
"sha256": "0717173d3c38334664ffaa53565d8c5b6390aaaeb8afab1b754b4cd19d8018d9"
},
"downloads": -1,
"filename": "codepropertygraph-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "677b7270c25d64cb758474b86cf931ae",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9.0",
"size": 3017,
"upload_time": "2024-06-10T01:47:16",
"upload_time_iso_8601": "2024-06-10T01:47:16.145028Z",
"url": "https://files.pythonhosted.org/packages/8f/80/55a81a617fab6f3a828568de1b98aa8207e59ff6ec66905016cfc12f2a0f/codepropertygraph-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0586c0722e4490971792469effe32c71cd55b0e6d18d36daf3194541c8e04913",
"md5": "1bff71c7ab4e71695744e00e580b52e5",
"sha256": "319a008ec3b11dadc13b973afed3dbde622a2394f48bd50c8b910b2f71d5303a"
},
"downloads": -1,
"filename": "codepropertygraph-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "1bff71c7ab4e71695744e00e580b52e5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9.0",
"size": 2887,
"upload_time": "2024-06-10T01:47:17",
"upload_time_iso_8601": "2024-06-10T01:47:17.831705Z",
"url": "https://files.pythonhosted.org/packages/05/86/c0722e4490971792469effe32c71cd55b0e6d18d36daf3194541c8e04913/codepropertygraph-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-10 01:47:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "markgacoka",
"github_project": "codepropertygraph",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "codepropertygraph"
}