A lightweight Code Property Graph Generator
Program analysis commonly relies on tools such as Joern and CodeQL to generate Code Property Graphs (CPGs). However, these tools are often heavyweight and require complex configurations, making them less user-friendly. In particular, they are difficult to scale for processing large-scale datasets in software engineering and machine learning research.
To address this limitation, we propose CodeSCI, a lightweight code property graph generator based on Tree-Sitter as science research infrastructure.
This project is under the development.
WELCOME TO PR!
Getting Start
Here are supports across languages and graphs.
| Language | Supported Graphs | Maturity |
|---|---|---|
| C | AST,CFG,DFG | |
| C++ | AST,CFG,DFG |
How it works
CodeSCI first parses source code into an Abstract Syntax Tree (AST) with the Tree-Sitter and decomposes it into fine-grained syntactic elements (tokens). Based on lightweight static analysis rules, CodeSCI further aggregates and transforms these elements to infer program relationships and construct the final Code Property Graph (CPG).
Limitations
CodeSCI is designed for analyzing individual code snippets and currently does NOT support repository-level or multi-file program analysis.
Of course, depending on practical needs and future development, we may consider adding support for repository-level and multi-file code analysis in future versions if possible.
In addition, CodeSCI focuses solely on syntactic parsing. It can process any syntactically valid code, regardless of whether the underlying program logic is semantically correct.
Usage
CodeSCI is designed as a lightweight program analysis library that exposes a programming API for integration into downstream applications.
Install the CodeSCI,
pip install codesci
For convenience and lightweight purposes, CodeSCI only accepts code strings as input. All generated program property graphs are networkx graph objects, which you can serialize into text format or deserialize into networkx objects. Here is the bubble sort code in C language, and transform it into different CPGs.
from codesci import toAST, toCFG, toDFG
sourceCode = """
#include <stdio.h>
int main() {
int a[] = {5,2,8,1,9}, n = 5;
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-1-i; j++)
if (a[j] > a[j+1]) {
int t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
for (int i = 0; i < n; i++) printf("%d ", [i]);
return 0;
}
"""
# Here, the following ast, cfg, dfg are networkx objects.
ast = toAST(code=sourceCode, language="c") # abstract syntax tree
cfg = toCFG(code=sourceCode, language="c") # control flow graph
dfg = toDFG(code=sourceCode, language="c") # data flow graph
Contribution
Contributions are always welcome! We appreciate constructive contributions of all kinds, such as adding support for new programming languages, implementing additional graph types, or improving existing features.
License
This project is under the MIT license.
Metadata
Release files for codesci 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| codesci-0.0.1.tar.gz | 9.8 kB | Without provenance | Details for codesci-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| codesci-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for codesci-0.0.1-py3-none-any.whl |
Total release size: 19.8 kB
Release files / codesci-0.0.1.tar.gz
| Download URL | codesci-0.0.1.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b300499f174cdeb77bea6d9a5469f84fc67f52c9489c1fe3ff6e087188a5f001
|
|
BLAKE2b-256 checksum How to use checksums |
d639b319ef9bd340ee8f03e043f07e98aba652ac7b331a1cfc45e5cf14c59ebe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / codesci-0.0.1-py3-none-any.whl
| Download URL | codesci-0.0.1-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3dd9b2d0ddecfa9ca228b0d195c65d09293f173ec82774767514b879c99f696c
|
|
BLAKE2b-256 checksum How to use checksums |
4be7bf1042cc668839eb5d1e544e316ef65aad8c27ba0adcc6ad3c54b6a3bc56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for codesci 0.0.1
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.