github / github/codeql

Whether there are Python SDK for Programmatic Access to CodeQL Database Facts

オープン
#22,411 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
question
主要言語
CodeQL
スター
10.1k
フォーク
2.1k
平均マージ
2日 15時間
マージ済み PR(30日)
141

説明

CodeQL provides powerful built-in analyses and program representations, such as AST, CFG, data flow, call graphs, and class hierarchies. However, these representations are currently primarily accessed through QL queries after a CodeQL database has been created.

For more complex analyses or for extending CodeQL's existing analyses (e.g., custom data-flow or alias analyses), implementing everything directly in QL can become quite difficult and cumbersome.

Currently, I use the following workaround:

- Build a CodeQL database for the target project.
- Write basic QL queries to export selected facts to CSV., such as:
* Interested AST nodes and their relationships
* Class/interface information and inheritance relationships
* Call sites and call relationships
* Other program facts relevant to my analysis

Define my own schema and load the CSV facts into memory.
Implement more sophisticated analyses using Python and custom algorithms.

This works, but it requires an additional export/import layer and also means that I have to manually reconstruct program representations that CodeQL already maintains internally. Would it be possible to provide an official Python SDK/API (or another programmatic API) that allows users to directly access the facts stored in a CodeQL database?

For example, something along the lines of:

```python
db = codeql.Database("my-project-db")

ast = db.ast()
cfg = db.cfg()
dataflow = db.dataflow()
classes = db.class_hierarchy()
calls = db.call_graph()
```

The exact API is not important; the key idea is that Python code could directly access the program facts represented in the CodeQL database, without first exporting them through QL queries. This would make it possible to use CodeQL as a powerful program representation and fact extraction backend, while implementing more complex or experimental analyses in Python.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

No files, tests, or entry points are named. Start by reviewing the existing CodeQL database and QL-query interfaces, then compare them with the proposed Python access model and the current CSV export/import workaround. Done would require an agreed API scope and an implementation plan, rather than a localized change.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
developer-experience, tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
活発
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。