pycode-kg 0.18.2__tar.gz → 0.19.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. pycode_kg-0.19.1/PKG-INFO +308 -0
  2. pycode_kg-0.19.1/README.md +234 -0
  3. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/pyproject.toml +2 -2
  4. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/__init__.py +1 -1
  5. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/analysis/framework_detector.py +31 -28
  6. pycode_kg-0.19.1/src/pycode_kg/cli/cmd_explain.py +80 -0
  7. pycode_kg-0.19.1/src/pycode_kg/explain.py +257 -0
  8. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/mcp_server.py +25 -181
  9. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/pycodekg_thorough_analysis.py +41 -11
  10. pycode_kg-0.18.2/PKG-INFO +0 -248
  11. pycode_kg-0.18.2/README.md +0 -174
  12. pycode_kg-0.18.2/src/pycode_kg/cli/cmd_explain.py +0 -180
  13. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/LICENSE +0 -0
  14. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/.DS_Store +0 -0
  15. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/__main__.py +0 -0
  16. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/analysis/__init__.py +0 -0
  17. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/analysis/bridge.py +0 -0
  18. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/analysis/centrality.py +0 -0
  19. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/analysis/hybrid_rank.py +0 -0
  20. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/app.py +0 -0
  21. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/architecture.py +0 -0
  22. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/build_pycodekg_lancedb.py +0 -0
  23. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/build_pycodekg_sqlite.py +0 -0
  24. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/__init__.py +0 -0
  25. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/cmd_analyze.py +0 -0
  26. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/cmd_architecture.py +0 -0
  27. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/cmd_bridges.py +0 -0
  28. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/cmd_build.py +0 -0
  29. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/cmd_build_full.py +0 -0
  30. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/cmd_centrality.py +0 -0
  31. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/cmd_framework_nodes.py +0 -0
  32. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/cmd_hooks.py +0 -0
  33. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/cmd_init.py +0 -0
  34. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/cmd_mcp.py +0 -0
  35. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/cmd_model.py +0 -0
  36. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/cmd_query.py +0 -0
  37. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/cmd_snapshot.py +0 -0
  38. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/cmd_viz.py +0 -0
  39. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/main.py +0 -0
  40. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/cli/options.py +0 -0
  41. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/config.py +0 -0
  42. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/graph.py +0 -0
  43. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/index.py +0 -0
  44. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/kg.py +0 -0
  45. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/layout3d.py +0 -0
  46. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/module/__init__.py +0 -0
  47. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/module/base.py +0 -0
  48. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/module/extractor.py +0 -0
  49. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/module/types.py +0 -0
  50. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/pycodekg.py +0 -0
  51. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/pycodekg_query.py +0 -0
  52. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/pycodekg_snippet_packer.py +0 -0
  53. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/pycodekg_viz.py +0 -0
  54. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/pycodekg_viz3d.py +0 -0
  55. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/ranking/__init__.py +0 -0
  56. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/ranking/cli_rank.py +0 -0
  57. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/ranking/coderank.py +0 -0
  58. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/snapshots.py +0 -0
  59. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/sql/004_add_centrality_table.sql +0 -0
  60. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/store.py +0 -0
  61. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/utils.py +0 -0
  62. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/visitor.py +0 -0
  63. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/viz3d.py +0 -0
  64. {pycode_kg-0.18.2 → pycode_kg-0.19.1}/src/pycode_kg/viz3d_timeline.py +0 -0
@@ -0,0 +1,308 @@
1
+ Metadata-Version: 2.4
2
+ Name: pycode-kg
3
+ Version: 0.19.1
4
+ Summary: A tool to build a searchable knowledge graph from Python repositories
5
+ License-Expression: Elastic-2.0
6
+ License-File: LICENSE
7
+ Keywords: knowledge-graph,code-analysis,ast,lancedb,sqlite,semantic-search
8
+ Author: Eric G. Suchanek, PhD
9
+ Author-email: suchanek@mac.com
10
+ Requires-Python: >=3.12,<3.14
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Provides-Extra: all
19
+ Provides-Extra: dev
20
+ Provides-Extra: kgdeps
21
+ Provides-Extra: viz
22
+ Provides-Extra: viz3d
23
+ Requires-Dist: PyQt5 (>=5.15.0) ; extra == "all"
24
+ Requires-Dist: PyQt5 (>=5.15.0) ; extra == "viz3d"
25
+ Requires-Dist: click (>=8.1.0,<9)
26
+ Requires-Dist: detect-secrets (>=1.5.0) ; extra == "all"
27
+ Requires-Dist: detect-secrets (>=1.5.0) ; extra == "dev"
28
+ Requires-Dist: doc-kg (>=0.11.0) ; extra == "dev"
29
+ Requires-Dist: doc-kg (>=0.11.0) ; extra == "kgdeps"
30
+ Requires-Dist: kgmodule-utils (>=0.2.1)
31
+ Requires-Dist: lancedb (>=0.29.0)
32
+ Requires-Dist: markdown (>=3.6) ; extra == "all"
33
+ Requires-Dist: markdown (>=3.6) ; extra == "viz3d"
34
+ Requires-Dist: mcp (>=1.0.0)
35
+ Requires-Dist: mypy (>=1.10.0) ; extra == "all"
36
+ Requires-Dist: mypy (>=1.10.0) ; extra == "dev"
37
+ Requires-Dist: numpy (>=1.24.0)
38
+ Requires-Dist: pandas (>=2.0.0)
39
+ Requires-Dist: param (>=2.0.0) ; extra == "all"
40
+ Requires-Dist: param (>=2.0.0) ; extra == "viz3d"
41
+ Requires-Dist: pdoc (>=14.0.0) ; extra == "all"
42
+ Requires-Dist: pdoc (>=14.0.0) ; extra == "dev"
43
+ Requires-Dist: plotly (>=5.14.0) ; extra == "all"
44
+ Requires-Dist: plotly (>=5.14.0) ; extra == "viz"
45
+ Requires-Dist: pre-commit (>=4.5.1) ; extra == "all"
46
+ Requires-Dist: pre-commit (>=4.5.1) ; extra == "dev"
47
+ Requires-Dist: pylint (>=4.0.5) ; extra == "all"
48
+ Requires-Dist: pylint (>=4.0.5) ; extra == "dev"
49
+ Requires-Dist: pytest (>=8.0.0) ; extra == "all"
50
+ Requires-Dist: pytest (>=8.0.0) ; extra == "dev"
51
+ Requires-Dist: pytest-cov (>=5.0.0) ; extra == "all"
52
+ Requires-Dist: pytest-cov (>=5.0.0) ; extra == "dev"
53
+ Requires-Dist: pyvis (>=0.3.2) ; extra == "all"
54
+ Requires-Dist: pyvis (>=0.3.2) ; extra == "viz"
55
+ Requires-Dist: pyvista[jupyter] (>=0.44.0) ; extra == "all"
56
+ Requires-Dist: pyvista[jupyter] (>=0.44.0) ; extra == "viz3d"
57
+ Requires-Dist: pyvistaqt (>=0.11.0) ; extra == "all"
58
+ Requires-Dist: pyvistaqt (>=0.11.0) ; extra == "viz3d"
59
+ Requires-Dist: rich (>=14.3.3,<15)
60
+ Requires-Dist: ruff (>=0.4.0) ; extra == "all"
61
+ Requires-Dist: ruff (>=0.4.0) ; extra == "dev"
62
+ Requires-Dist: safetensors (>=0.5.0)
63
+ Requires-Dist: sentence-transformers (>=5.4.1)
64
+ Requires-Dist: streamlit (>=1.35.0) ; extra == "all"
65
+ Requires-Dist: streamlit (>=1.35.0) ; extra == "viz"
66
+ Requires-Dist: torch (>=2.5.1)
67
+ Requires-Dist: trame-vtk (>=2.0.0) ; extra == "all"
68
+ Requires-Dist: trame-vtk (>=2.0.0) ; extra == "viz3d"
69
+ Requires-Dist: transformers (>=4.40.0,<4.57)
70
+ Project-URL: Homepage, https://github.com/Flux-Frontiers/pycode_kg
71
+ Project-URL: Repository, https://github.com/Flux-Frontiers/pycode_kg
72
+ Description-Content-Type: text/markdown
73
+
74
+
75
+ <p align="center">
76
+ <img src="assets/logos/pycodeKG.PNG" alt="PyCodeKG" width="200"/>
77
+ </p>
78
+
79
+ [![Python](https://img.shields.io/badge/python-3.12%20%7C%203.13-blue.svg)](https://www.python.org/)
80
+ [![License: Elastic-2.0](https://img.shields.io/badge/License-Elastic%202.0-blue.svg)](https://www.elastic.co/licensing/elastic-license)
81
+ [![Version](https://img.shields.io/badge/version-0.19.1-blue.svg)](https://github.com/Flux-Frontiers/pycode_kg/releases)
82
+ [![CI](https://github.com/Flux-Frontiers/pycode_kg/actions/workflows/ci.yml/badge.svg)](https://github.com/Flux-Frontiers/pycode_kg/actions/workflows/ci.yml)
83
+ [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
84
+ [![DOI](https://zenodo.org/badge/1202379010.svg)](https://zenodo.org/badge/latestdoi/1202379010)
85
+
86
+ # PyCodeKG — A Knowledge Graph for Python Codebases
87
+
88
+ **PyCodeKG turns a Python codebase into a deterministic, queryable knowledge graph — and uses it to produce architectural analyses you can act on, with or without an LLM in the loop.**
89
+
90
+ It walks the AST of every module, class, function, and method in your repo, extracts the typed relationships that actually hold the code together (`CONTAINS`, `CALLS`, `IMPORTS`, `INHERITS`, `RESOLVES_TO`), and stores the result in SQLite. A LanceDB vector index sits alongside the graph so that *"authentication flow"* and *"verify_jwt"* both find the right place to start exploring. From there you can rank functions by structural importance, trace fan-in across import aliases, detect circular imports and dead code, render the call graph in 3D, snapshot metrics for diffing across releases, or hand the whole thing to Claude over MCP.
91
+
92
+ The original motivation was simple: **produce thorough, defensible analyses of Python codebases that don't depend on inference**. Every result is computed from the AST and the graph — no model is asked to guess. When an LLM is present, it consumes the *same* grounded output as a structured context pack, and the hallucinations that plague "embed-the-repo" tools largely disappear.
93
+
94
+ Everything runs on your laptop. No cloud APIs, no quotas, no source code leaving the machine.
95
+
96
+ [Technical Paper (PDF)](article/pycode_kg.pdf) · *Author: Eric G. Suchanek, PhD — Flux-Frontiers, Liberty TWP, OH*
97
+
98
+ ---
99
+
100
+ ## Sister projects
101
+
102
+ PyCodeKG is part of a growing family of knowledge-graph systems that share the same hybrid semantic-plus-structural design — each one applies it to a different kind of corpus:
103
+
104
+ - **[DocKG](https://github.com/Flux-Frontiers/doc_kg)** — Markdown and prose. Indexes PyCodeKG's own documentation, so the docs you're reading are themselves a queryable graph.
105
+ - **[MetaboKG](https://github.com/Flux-Frontiers/metabo_kg)** — metabolic pathway data (KEGG, SBML, BioPAX), with FBA / ODE simulation on top of the graph.
106
+ - **[DiaryKG](https://github.com/Flux-Frontiers/diary_kg)** — personal journals and diary corpora; semantic search and graph traversal over a writer's body of work.
107
+ - **[FTreeKG](https://github.com/Flux-Frontiers/FTreeKG)** — filesystem trees as a queryable graph of directories, files, and contents.
108
+ - **[AgentKG](https://github.com/Flux-Frontiers/agent_kg)** — conversational memory as a knowledge graph: turns, decisions, commitments, preferences, and the relationships between them.
109
+
110
+ Together they form **KGRAG**, a federated retrieval layer where one query can span code, documentation, journals, filesystems, agent memory, and domain data simultaneously.
111
+
112
+ ---
113
+
114
+ ## Two ways to use it
115
+
116
+ PyCodeKG is designed to be useful at both ends — as a standalone command-line analysis tool, and as a structured context layer for AI agents.
117
+
118
+ ### 1. Standalone — `pycodekg analyze`
119
+
120
+ This single command is the actual reason I wrote this module. I got tired of my LLM doing grep on my src/ in order to get a good analysis of the codebase. This command runs fifteen analysis passes in seconds and the output drops straight into your favorite coding LLM for targeted improvement suggestions. I used this process to iteratively improve PyCodeKG and several of the analysis passes were added as a result.
121
+
122
+ The analysis/ has files *_analysis_<date>.md - I ran PyCodeKG against **numpy** and **matplotlib** for fun.
123
+
124
+ ```bash
125
+ pycodekg init # downloads embedder
126
+ pycodekg build --repo . # one-time index
127
+ pycodekg analyze. # the full report
128
+ ```
129
+
130
+ **Note**
131
+ The first-time run can take some time to warm up. Be patient.
132
+
133
+ The 15-phase pipeline runs in sequence and surfaces several important metrics:
134
+
135
+ | # | Phase | What it surfaces |
136
+ |---|-------|-----------------|
137
+ | 1 | Baseline metrics | Node/edge counts, graph shape |
138
+ | 2 | CodeRank (global PageRank) | Structurally most important symbols |
139
+ | 3 | Fan-in analysis | Heavily depended-on functions (breaking-change risk) |
140
+ | 4 | Fan-out analysis | Orchestrators and complexity hotspots |
141
+ | 5 | Dependency analysis | Orphaned / dead code candidates |
142
+ | 6 | Pattern detection | Anti-patterns and structural red flags |
143
+ | 7 | Module coupling | Tightly coupled pairs, import graph density |
144
+ | 8 | Critical paths | Longest call chains, bottlenecks |
145
+ | 9 | Public API identification | Exposed vs. internal surface |
146
+ | 10 | Docstring coverage | By module, class, function, method |
147
+ | 11 | Inheritance hierarchy | Depth, multiple inheritance, diamond patterns |
148
+ | 12 | Insight synthesis | Issues + strengths callouts |
149
+ | 13 | Snapshot history | Metric trends across releases |
150
+ | 14 | Structural centrality (SIR) | Bridge nodes, graph removal impact |
151
+ | 15 | Concern-based ranking | Nodes grouped by architectural concern |
152
+
153
+ Every finding maps to a file and line number — no hallucinated signatures, no probabilistic guesses. The Markdown output is LLM-ready; the JSON snapshot is CI-gate-ready. Reach for `analyze` before any non-trivial refactor, at every release, and whenever you inherit an unfamiliar codebase. Full reference: [docs/Analyze.md](docs/Analyze.md).
154
+
155
+ ```bash
156
+ pycodekg analyze --quiet --json ~/.claude/pycodekg_analysis_latest.json
157
+ jq '.docstring_coverage.total' ~/.claude/pycodekg_analysis_latest.json
158
+ ```
159
+
160
+ ### 2. Agentic — MCP server for grounded AI workflows
161
+
162
+ Run `pycodekg mcp` and Claude (or any MCP-aware client) gets nineteen tools backed by the same graph: `graph_stats`, `query_codebase`, `pack_snippets`, `get_node`, `list_nodes`, `callers`, `explain`, `centrality`, `bridge_centrality`, `framework_nodes`, `analyze_repo`, `snapshot_list / show / diff`, and more. Setup for Claude Code, Claude Desktop, Kilo Code, Copilot, and Cline is a single line — see [docs/MCP.md](docs/MCP.md) and [docs/INSTALLATION.md](docs/INSTALLATION.md).
163
+
164
+ The agent benefit isn't subtle. Tools like `pack_snippets` return *actual source* with line numbers and surrounding context; `callers` returns the *real* fan-in resolved across import aliases, not a regex's best guess. The agent stops fabricating function signatures and starts citing them. Multi-step workflows — *"find the auth path, list its callers, summarize what changes if I rename it"* — collapse from dozens of `grep`s and file reads into a handful of source-grounded calls.
165
+
166
+ Independent assessments tend to put it the same way:
167
+
168
+ > "PyCodeKG compresses a multi-step workflow — semantic search, graph expansion, caller tracing, snippet retrieval, and architectural summarization — into a small set of tools that are fast to invoke and easy to chain. In practice, it let me move from broad orientation to intent-driven discovery and then to structural validation without dropping down into manual grep or repeated file reads."
169
+ > — *GPT-5 (via Cline)*
170
+
171
+ > "What sets it apart from 'search the repo with embeddings' tools is the structural layer… Verdict: 4.5/5 — recommend without reservation for any non-trivial Python codebase."
172
+ > — *Claude Opus 4.7*
173
+
174
+ > "PyCodeKG is dramatically more effective than traditional grep/file-reading workflows. Unique value: hybrid search combining natural-language intent with precise structural relationships."
175
+ > — *Claude Haiku 4.5*
176
+
177
+ Full reports in [assessments/](assessments/).
178
+
179
+ ---
180
+
181
+ ## Get started in 60 seconds
182
+
183
+ **Requirements:** Python ≥ 3.12, < 3.14
184
+
185
+ ```bash
186
+ pip install 'pycode-kg[viz,viz3d]' # base + Streamlit + 3-D viewer
187
+
188
+ cd /path/to/your/repo
189
+ pycodekg init --repo . # download model, build graph, install hooks, snapshot
190
+ pycodekg analyze . # the architectural report
191
+ ```
192
+
193
+ That's the recommended path. Variants (minimal install, MCP-only, contributor setup) are in [docs/INSTALLATION.md](docs/INSTALLATION.md). Every CLI subcommand is also exposed as a script alias (`pycodekg-analyze`, `pycodekg-build`, `pycodekg-mcp`, …) for use in Makefiles and Poetry projects.
194
+
195
+ ---
196
+
197
+ ## How retrieval works
198
+
199
+ Search is hybrid by design. A query like *"authentication flow"* runs in two phases:
200
+
201
+ 1. **Vector phase** — the query is embedded with a local sentence-transformer (cached after first download) and LanceDB returns the `k` closest functions, classes, and modules by cosine similarity.
202
+ 2. **Graph expansion phase** — each seed hit is expanded `hop` BFS steps along the typed edges (`CONTAINS`, `CALLS`, `IMPORTS`, `INHERITS`, `RESOLVES_TO`) so call chains and module relationships surface alongside the names that matched.
203
+
204
+ **Structure is treated as ground truth; the embeddings are strictly an acceleration layer.** When the graph and the vector index disagree, the graph wins. This is why fan-in lookups are accurate even for same-named symbols across modules — `RESOLVES_TO` edges bridge call sites through their import aliases, and `callers()` does a two-phase reverse traversal that grep simply cannot replicate.
205
+
206
+ The graph is built around four node kinds (module, class, function, method) and five edge relations. Schema and edge semantics are documented in [docs/CHEATSHEET.md](docs/CHEATSHEET.md).
207
+
208
+ ---
209
+
210
+ ## What you can do with it
211
+
212
+ | If you want to… | Reach for | Detail |
213
+ |---|---|---|
214
+ | **Get a thorough architectural report** | `pycodekg analyze` | [docs/Analyze.md](docs/Analyze.md) |
215
+ | **Generate a coherent architecture description** | `pycodekg architecture` | [docs/Architecture_usage.md](docs/Architecture_usage.md) |
216
+ | **Track metrics across releases** | `pycodekg snapshot save / list / diff` | [docs/SNAPSHOTS.md](docs/SNAPSHOTS.md) |
217
+ | **Identify the most structurally important code** | `pycodekg centrality` (SIR PageRank) | [docs/CODERANK.md](docs/CODERANK.md) |
218
+ | **Pull source-grounded context for an LLM** | `pycodekg pack "..." --format md` | [docs/CHEATSHEET.md](docs/CHEATSHEET.md) |
219
+ | **Run a hybrid semantic + structural query** | `pycodekg query "..."` | [docs/CHEATSHEET.md](docs/CHEATSHEET.md) |
220
+ | **Browse the graph interactively** | `pycodekg viz` (Streamlit) | [docs/INSTALLATION.md](docs/INSTALLATION.md) |
221
+ | **See call graphs in 3-D** *(active development — functional but rough)* | `pycodekg viz3d --layout funnel` | [docs/VIZ3D.md](docs/VIZ3D.md) |
222
+ | **Wire it into Claude / Copilot / Cline** | `pycodekg mcp` | [docs/MCP.md](docs/MCP.md) |
223
+
224
+ If you only read one doc after this one, read [docs/Analyze.md](docs/Analyze.md) — that's where most of the day-to-day value lives.
225
+
226
+ ---
227
+
228
+ ## Architecture
229
+
230
+ ```
231
+ src/pycode_kg/
232
+ ├── visitor.py # AST extraction (three-pass: structure, calls, dataflow)
233
+ ├── graph.py # GraphBuilder: file discovery + dispatch
234
+ ├── store.py # SQLite persistence + canonical edges
235
+ ├── index.py # LanceDB semantic index
236
+ ├── pycodekg.py # Public façade
237
+ ├── pycodekg_query.py # Hybrid query
238
+ ├── pycodekg_snippet_packer.py # Source-grounded packs
239
+ ├── pycodekg_thorough_analysis.py # `analyze` engine
240
+ ├── architecture.py # `architecture` description generator
241
+ ├── ranking/ # PageRank, bridge centrality, framework nodes
242
+ ├── snapshots.py # Temporal metric snapshots
243
+ ├── analysis/ # Coupling, cycles, orphans, hotspots
244
+ ├── cli/ # All `pycodekg-*` entry points
245
+ ├── mcp_server.py # MCP server (nineteen tools)
246
+ ├── app.py # Streamlit web app
247
+ ├── viz3d.py / layout3d.py # PyVista/PyQt5 3-D viewer
248
+ └── viz3d_timeline.py # Metric history timeline
249
+ ```
250
+
251
+ The MCP server, the CLI, and the Streamlit app are thin wrappers over the same store + index + ranking core — there is exactly one code path for each capability. The latest architectural deep-dive is in [docs/analysis_v0.19.0.md](docs/analysis_v0.19.0.md), produced (of course) by `pycodekg analyze` against this very repo.
252
+
253
+ ---
254
+
255
+ ## Documentation map
256
+
257
+ | Doc | What it covers |
258
+ |---|---|
259
+ | [docs/INSTALLATION.md](docs/INSTALLATION.md) | All install variants, MCP setup, contributor setup, troubleshooting |
260
+ | [docs/Analyze.md](docs/Analyze.md) | The `analyze` command — every metric, every flag, interpretation guide |
261
+ | [docs/Architecture_usage.md](docs/Architecture_usage.md) | Generating coherent architecture descriptions |
262
+ | [docs/SNAPSHOTS.md](docs/SNAPSHOTS.md) | Temporal metric snapshots, diffing across releases |
263
+ | [docs/CODERANK.md](docs/CODERANK.md) | SIR PageRank, bridge centrality, framework hubs |
264
+ | [docs/MCP.md](docs/MCP.md) | MCP server setup for Claude / Kilo / Copilot / Cline, tool reference |
265
+ | [docs/CHEATSHEET.md](docs/CHEATSHEET.md) | Every CLI flag and every MCP tool — one page |
266
+ | [docs/VIZ3D.md](docs/VIZ3D.md) | The 3-D PyVista viewer and layouts |
267
+ | [CHANGELOG.md](CHANGELOG.md) | Release history |
268
+
269
+ ---
270
+
271
+ ## Citation
272
+
273
+ If you use PyCodeKG in your research or project, please cite it:
274
+
275
+ [![DOI](https://zenodo.org/badge/1202379010.svg)](https://zenodo.org/badge/latestdoi/1202379010)
276
+
277
+ > Suchanek, E. G. (2026). *PyCodeKG: A Knowledge Graph for Python Codebases* (Version 0.19.0) [Software]. Flux-Frontiers. https://doi.org/10.5281/zenodo.19834777
278
+
279
+ ```bibtex
280
+ @software{suchanek_pycode_kg,
281
+ author = {Suchanek, Eric G.},
282
+ title = {{PyCodeKG}: A Knowledge Graph for Python Codebases},
283
+ version = {0.19.0},
284
+ year = {2026},
285
+ publisher = {Flux-Frontiers},
286
+ url = {https://github.com/Flux-Frontiers/pycode_kg},
287
+ doi = {10.5281/zenodo.19834777},
288
+ }
289
+ ```
290
+
291
+ ---
292
+
293
+ ## License
294
+
295
+ [Elastic License 2.0](https://www.elastic.co/licensing/elastic-license) — free for non-commercial and internal use; commercial redistribution or hosting requires a license from Flux-Frontiers.
296
+
297
+ ---
298
+
299
+ ## Support & acknowledgments
300
+
301
+ - **Issues** — [GitHub Issues](https://github.com/Flux-Frontiers/pycode_kg/issues)
302
+ - Sister projects [DocKG](https://github.com/Flux-Frontiers/doc_kg) and [MetaboKG](https://github.com/Flux-Frontiers/metabo_kg)
303
+ - LanceDB, sentence-transformers, PyVista, Streamlit, and FastMCP for the foundations
304
+
305
+ ---
306
+
307
+ *Built for Python developers and AI agents that work alongside them — egs · Last updated May 2026*
308
+
@@ -0,0 +1,234 @@
1
+
2
+ <p align="center">
3
+ <img src="assets/logos/pycodeKG.PNG" alt="PyCodeKG" width="200"/>
4
+ </p>
5
+
6
+ [![Python](https://img.shields.io/badge/python-3.12%20%7C%203.13-blue.svg)](https://www.python.org/)
7
+ [![License: Elastic-2.0](https://img.shields.io/badge/License-Elastic%202.0-blue.svg)](https://www.elastic.co/licensing/elastic-license)
8
+ [![Version](https://img.shields.io/badge/version-0.19.1-blue.svg)](https://github.com/Flux-Frontiers/pycode_kg/releases)
9
+ [![CI](https://github.com/Flux-Frontiers/pycode_kg/actions/workflows/ci.yml/badge.svg)](https://github.com/Flux-Frontiers/pycode_kg/actions/workflows/ci.yml)
10
+ [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
11
+ [![DOI](https://zenodo.org/badge/1202379010.svg)](https://zenodo.org/badge/latestdoi/1202379010)
12
+
13
+ # PyCodeKG — A Knowledge Graph for Python Codebases
14
+
15
+ **PyCodeKG turns a Python codebase into a deterministic, queryable knowledge graph — and uses it to produce architectural analyses you can act on, with or without an LLM in the loop.**
16
+
17
+ It walks the AST of every module, class, function, and method in your repo, extracts the typed relationships that actually hold the code together (`CONTAINS`, `CALLS`, `IMPORTS`, `INHERITS`, `RESOLVES_TO`), and stores the result in SQLite. A LanceDB vector index sits alongside the graph so that *"authentication flow"* and *"verify_jwt"* both find the right place to start exploring. From there you can rank functions by structural importance, trace fan-in across import aliases, detect circular imports and dead code, render the call graph in 3D, snapshot metrics for diffing across releases, or hand the whole thing to Claude over MCP.
18
+
19
+ The original motivation was simple: **produce thorough, defensible analyses of Python codebases that don't depend on inference**. Every result is computed from the AST and the graph — no model is asked to guess. When an LLM is present, it consumes the *same* grounded output as a structured context pack, and the hallucinations that plague "embed-the-repo" tools largely disappear.
20
+
21
+ Everything runs on your laptop. No cloud APIs, no quotas, no source code leaving the machine.
22
+
23
+ [Technical Paper (PDF)](article/pycode_kg.pdf) · *Author: Eric G. Suchanek, PhD — Flux-Frontiers, Liberty TWP, OH*
24
+
25
+ ---
26
+
27
+ ## Sister projects
28
+
29
+ PyCodeKG is part of a growing family of knowledge-graph systems that share the same hybrid semantic-plus-structural design — each one applies it to a different kind of corpus:
30
+
31
+ - **[DocKG](https://github.com/Flux-Frontiers/doc_kg)** — Markdown and prose. Indexes PyCodeKG's own documentation, so the docs you're reading are themselves a queryable graph.
32
+ - **[MetaboKG](https://github.com/Flux-Frontiers/metabo_kg)** — metabolic pathway data (KEGG, SBML, BioPAX), with FBA / ODE simulation on top of the graph.
33
+ - **[DiaryKG](https://github.com/Flux-Frontiers/diary_kg)** — personal journals and diary corpora; semantic search and graph traversal over a writer's body of work.
34
+ - **[FTreeKG](https://github.com/Flux-Frontiers/FTreeKG)** — filesystem trees as a queryable graph of directories, files, and contents.
35
+ - **[AgentKG](https://github.com/Flux-Frontiers/agent_kg)** — conversational memory as a knowledge graph: turns, decisions, commitments, preferences, and the relationships between them.
36
+
37
+ Together they form **KGRAG**, a federated retrieval layer where one query can span code, documentation, journals, filesystems, agent memory, and domain data simultaneously.
38
+
39
+ ---
40
+
41
+ ## Two ways to use it
42
+
43
+ PyCodeKG is designed to be useful at both ends — as a standalone command-line analysis tool, and as a structured context layer for AI agents.
44
+
45
+ ### 1. Standalone — `pycodekg analyze`
46
+
47
+ This single command is the actual reason I wrote this module. I got tired of my LLM doing grep on my src/ in order to get a good analysis of the codebase. This command runs fifteen analysis passes in seconds and the output drops straight into your favorite coding LLM for targeted improvement suggestions. I used this process to iteratively improve PyCodeKG and several of the analysis passes were added as a result.
48
+
49
+ The analysis/ has files *_analysis_<date>.md - I ran PyCodeKG against **numpy** and **matplotlib** for fun.
50
+
51
+ ```bash
52
+ pycodekg init # downloads embedder
53
+ pycodekg build --repo . # one-time index
54
+ pycodekg analyze. # the full report
55
+ ```
56
+
57
+ **Note**
58
+ The first-time run can take some time to warm up. Be patient.
59
+
60
+ The 15-phase pipeline runs in sequence and surfaces several important metrics:
61
+
62
+ | # | Phase | What it surfaces |
63
+ |---|-------|-----------------|
64
+ | 1 | Baseline metrics | Node/edge counts, graph shape |
65
+ | 2 | CodeRank (global PageRank) | Structurally most important symbols |
66
+ | 3 | Fan-in analysis | Heavily depended-on functions (breaking-change risk) |
67
+ | 4 | Fan-out analysis | Orchestrators and complexity hotspots |
68
+ | 5 | Dependency analysis | Orphaned / dead code candidates |
69
+ | 6 | Pattern detection | Anti-patterns and structural red flags |
70
+ | 7 | Module coupling | Tightly coupled pairs, import graph density |
71
+ | 8 | Critical paths | Longest call chains, bottlenecks |
72
+ | 9 | Public API identification | Exposed vs. internal surface |
73
+ | 10 | Docstring coverage | By module, class, function, method |
74
+ | 11 | Inheritance hierarchy | Depth, multiple inheritance, diamond patterns |
75
+ | 12 | Insight synthesis | Issues + strengths callouts |
76
+ | 13 | Snapshot history | Metric trends across releases |
77
+ | 14 | Structural centrality (SIR) | Bridge nodes, graph removal impact |
78
+ | 15 | Concern-based ranking | Nodes grouped by architectural concern |
79
+
80
+ Every finding maps to a file and line number — no hallucinated signatures, no probabilistic guesses. The Markdown output is LLM-ready; the JSON snapshot is CI-gate-ready. Reach for `analyze` before any non-trivial refactor, at every release, and whenever you inherit an unfamiliar codebase. Full reference: [docs/Analyze.md](docs/Analyze.md).
81
+
82
+ ```bash
83
+ pycodekg analyze --quiet --json ~/.claude/pycodekg_analysis_latest.json
84
+ jq '.docstring_coverage.total' ~/.claude/pycodekg_analysis_latest.json
85
+ ```
86
+
87
+ ### 2. Agentic — MCP server for grounded AI workflows
88
+
89
+ Run `pycodekg mcp` and Claude (or any MCP-aware client) gets nineteen tools backed by the same graph: `graph_stats`, `query_codebase`, `pack_snippets`, `get_node`, `list_nodes`, `callers`, `explain`, `centrality`, `bridge_centrality`, `framework_nodes`, `analyze_repo`, `snapshot_list / show / diff`, and more. Setup for Claude Code, Claude Desktop, Kilo Code, Copilot, and Cline is a single line — see [docs/MCP.md](docs/MCP.md) and [docs/INSTALLATION.md](docs/INSTALLATION.md).
90
+
91
+ The agent benefit isn't subtle. Tools like `pack_snippets` return *actual source* with line numbers and surrounding context; `callers` returns the *real* fan-in resolved across import aliases, not a regex's best guess. The agent stops fabricating function signatures and starts citing them. Multi-step workflows — *"find the auth path, list its callers, summarize what changes if I rename it"* — collapse from dozens of `grep`s and file reads into a handful of source-grounded calls.
92
+
93
+ Independent assessments tend to put it the same way:
94
+
95
+ > "PyCodeKG compresses a multi-step workflow — semantic search, graph expansion, caller tracing, snippet retrieval, and architectural summarization — into a small set of tools that are fast to invoke and easy to chain. In practice, it let me move from broad orientation to intent-driven discovery and then to structural validation without dropping down into manual grep or repeated file reads."
96
+ > — *GPT-5 (via Cline)*
97
+
98
+ > "What sets it apart from 'search the repo with embeddings' tools is the structural layer… Verdict: 4.5/5 — recommend without reservation for any non-trivial Python codebase."
99
+ > — *Claude Opus 4.7*
100
+
101
+ > "PyCodeKG is dramatically more effective than traditional grep/file-reading workflows. Unique value: hybrid search combining natural-language intent with precise structural relationships."
102
+ > — *Claude Haiku 4.5*
103
+
104
+ Full reports in [assessments/](assessments/).
105
+
106
+ ---
107
+
108
+ ## Get started in 60 seconds
109
+
110
+ **Requirements:** Python ≥ 3.12, < 3.14
111
+
112
+ ```bash
113
+ pip install 'pycode-kg[viz,viz3d]' # base + Streamlit + 3-D viewer
114
+
115
+ cd /path/to/your/repo
116
+ pycodekg init --repo . # download model, build graph, install hooks, snapshot
117
+ pycodekg analyze . # the architectural report
118
+ ```
119
+
120
+ That's the recommended path. Variants (minimal install, MCP-only, contributor setup) are in [docs/INSTALLATION.md](docs/INSTALLATION.md). Every CLI subcommand is also exposed as a script alias (`pycodekg-analyze`, `pycodekg-build`, `pycodekg-mcp`, …) for use in Makefiles and Poetry projects.
121
+
122
+ ---
123
+
124
+ ## How retrieval works
125
+
126
+ Search is hybrid by design. A query like *"authentication flow"* runs in two phases:
127
+
128
+ 1. **Vector phase** — the query is embedded with a local sentence-transformer (cached after first download) and LanceDB returns the `k` closest functions, classes, and modules by cosine similarity.
129
+ 2. **Graph expansion phase** — each seed hit is expanded `hop` BFS steps along the typed edges (`CONTAINS`, `CALLS`, `IMPORTS`, `INHERITS`, `RESOLVES_TO`) so call chains and module relationships surface alongside the names that matched.
130
+
131
+ **Structure is treated as ground truth; the embeddings are strictly an acceleration layer.** When the graph and the vector index disagree, the graph wins. This is why fan-in lookups are accurate even for same-named symbols across modules — `RESOLVES_TO` edges bridge call sites through their import aliases, and `callers()` does a two-phase reverse traversal that grep simply cannot replicate.
132
+
133
+ The graph is built around four node kinds (module, class, function, method) and five edge relations. Schema and edge semantics are documented in [docs/CHEATSHEET.md](docs/CHEATSHEET.md).
134
+
135
+ ---
136
+
137
+ ## What you can do with it
138
+
139
+ | If you want to… | Reach for | Detail |
140
+ |---|---|---|
141
+ | **Get a thorough architectural report** | `pycodekg analyze` | [docs/Analyze.md](docs/Analyze.md) |
142
+ | **Generate a coherent architecture description** | `pycodekg architecture` | [docs/Architecture_usage.md](docs/Architecture_usage.md) |
143
+ | **Track metrics across releases** | `pycodekg snapshot save / list / diff` | [docs/SNAPSHOTS.md](docs/SNAPSHOTS.md) |
144
+ | **Identify the most structurally important code** | `pycodekg centrality` (SIR PageRank) | [docs/CODERANK.md](docs/CODERANK.md) |
145
+ | **Pull source-grounded context for an LLM** | `pycodekg pack "..." --format md` | [docs/CHEATSHEET.md](docs/CHEATSHEET.md) |
146
+ | **Run a hybrid semantic + structural query** | `pycodekg query "..."` | [docs/CHEATSHEET.md](docs/CHEATSHEET.md) |
147
+ | **Browse the graph interactively** | `pycodekg viz` (Streamlit) | [docs/INSTALLATION.md](docs/INSTALLATION.md) |
148
+ | **See call graphs in 3-D** *(active development — functional but rough)* | `pycodekg viz3d --layout funnel` | [docs/VIZ3D.md](docs/VIZ3D.md) |
149
+ | **Wire it into Claude / Copilot / Cline** | `pycodekg mcp` | [docs/MCP.md](docs/MCP.md) |
150
+
151
+ If you only read one doc after this one, read [docs/Analyze.md](docs/Analyze.md) — that's where most of the day-to-day value lives.
152
+
153
+ ---
154
+
155
+ ## Architecture
156
+
157
+ ```
158
+ src/pycode_kg/
159
+ ├── visitor.py # AST extraction (three-pass: structure, calls, dataflow)
160
+ ├── graph.py # GraphBuilder: file discovery + dispatch
161
+ ├── store.py # SQLite persistence + canonical edges
162
+ ├── index.py # LanceDB semantic index
163
+ ├── pycodekg.py # Public façade
164
+ ├── pycodekg_query.py # Hybrid query
165
+ ├── pycodekg_snippet_packer.py # Source-grounded packs
166
+ ├── pycodekg_thorough_analysis.py # `analyze` engine
167
+ ├── architecture.py # `architecture` description generator
168
+ ├── ranking/ # PageRank, bridge centrality, framework nodes
169
+ ├── snapshots.py # Temporal metric snapshots
170
+ ├── analysis/ # Coupling, cycles, orphans, hotspots
171
+ ├── cli/ # All `pycodekg-*` entry points
172
+ ├── mcp_server.py # MCP server (nineteen tools)
173
+ ├── app.py # Streamlit web app
174
+ ├── viz3d.py / layout3d.py # PyVista/PyQt5 3-D viewer
175
+ └── viz3d_timeline.py # Metric history timeline
176
+ ```
177
+
178
+ The MCP server, the CLI, and the Streamlit app are thin wrappers over the same store + index + ranking core — there is exactly one code path for each capability. The latest architectural deep-dive is in [docs/analysis_v0.19.0.md](docs/analysis_v0.19.0.md), produced (of course) by `pycodekg analyze` against this very repo.
179
+
180
+ ---
181
+
182
+ ## Documentation map
183
+
184
+ | Doc | What it covers |
185
+ |---|---|
186
+ | [docs/INSTALLATION.md](docs/INSTALLATION.md) | All install variants, MCP setup, contributor setup, troubleshooting |
187
+ | [docs/Analyze.md](docs/Analyze.md) | The `analyze` command — every metric, every flag, interpretation guide |
188
+ | [docs/Architecture_usage.md](docs/Architecture_usage.md) | Generating coherent architecture descriptions |
189
+ | [docs/SNAPSHOTS.md](docs/SNAPSHOTS.md) | Temporal metric snapshots, diffing across releases |
190
+ | [docs/CODERANK.md](docs/CODERANK.md) | SIR PageRank, bridge centrality, framework hubs |
191
+ | [docs/MCP.md](docs/MCP.md) | MCP server setup for Claude / Kilo / Copilot / Cline, tool reference |
192
+ | [docs/CHEATSHEET.md](docs/CHEATSHEET.md) | Every CLI flag and every MCP tool — one page |
193
+ | [docs/VIZ3D.md](docs/VIZ3D.md) | The 3-D PyVista viewer and layouts |
194
+ | [CHANGELOG.md](CHANGELOG.md) | Release history |
195
+
196
+ ---
197
+
198
+ ## Citation
199
+
200
+ If you use PyCodeKG in your research or project, please cite it:
201
+
202
+ [![DOI](https://zenodo.org/badge/1202379010.svg)](https://zenodo.org/badge/latestdoi/1202379010)
203
+
204
+ > Suchanek, E. G. (2026). *PyCodeKG: A Knowledge Graph for Python Codebases* (Version 0.19.0) [Software]. Flux-Frontiers. https://doi.org/10.5281/zenodo.19834777
205
+
206
+ ```bibtex
207
+ @software{suchanek_pycode_kg,
208
+ author = {Suchanek, Eric G.},
209
+ title = {{PyCodeKG}: A Knowledge Graph for Python Codebases},
210
+ version = {0.19.0},
211
+ year = {2026},
212
+ publisher = {Flux-Frontiers},
213
+ url = {https://github.com/Flux-Frontiers/pycode_kg},
214
+ doi = {10.5281/zenodo.19834777},
215
+ }
216
+ ```
217
+
218
+ ---
219
+
220
+ ## License
221
+
222
+ [Elastic License 2.0](https://www.elastic.co/licensing/elastic-license) — free for non-commercial and internal use; commercial redistribution or hosting requires a license from Flux-Frontiers.
223
+
224
+ ---
225
+
226
+ ## Support & acknowledgments
227
+
228
+ - **Issues** — [GitHub Issues](https://github.com/Flux-Frontiers/pycode_kg/issues)
229
+ - Sister projects [DocKG](https://github.com/Flux-Frontiers/doc_kg) and [MetaboKG](https://github.com/Flux-Frontiers/metabo_kg)
230
+ - LanceDB, sentence-transformers, PyVista, Streamlit, and FastMCP for the foundations
231
+
232
+ ---
233
+
234
+ *Built for Python developers and AI agents that work alongside them — egs · Last updated May 2026*
@@ -66,7 +66,7 @@ ruff = ">=0.4.0"
66
66
  # ---------------------------------------------------------------------------
67
67
  [project]
68
68
  name = "pycode-kg"
69
- version = "0.18.2"
69
+ version = "0.19.1"
70
70
  description = "A tool to build a searchable knowledge graph from Python repositories"
71
71
  readme = "README.md"
72
72
  license = "Elastic-2.0"
@@ -94,7 +94,7 @@ dependencies = [
94
94
  "safetensors>=0.5.0",
95
95
  "sentence-transformers>=5.4.1",
96
96
  "torch>=2.5.1",
97
- "transformers>=4.57.6",
97
+ "transformers>=4.40.0,<4.57",
98
98
  "kgmodule-utils>=0.2.1",
99
99
  ]
100
100
 
@@ -32,7 +32,7 @@ KGModule SDK (build new domain KGs)::
32
32
  from pycode_kg import KGModule, KGExtractor, PyCodeKGExtractor, NodeSpec, EdgeSpec
33
33
  """
34
34
 
35
- __version__ = "0.18.2"
35
+ __version__ = "0.19.1"
36
36
  __author__ = "Eric G. Suchanek, PhD"
37
37
 
38
38
  # Low-level primitives (locked v0 contract)