Unified code + documentation knowledge graph from Sphinx builds and Python AST analysis
Project description
sphinxcontrib-nexus
A unified code + documentation knowledge graph extracted from Sphinx builds and Python AST analysis. Queryable via MCP, CLI, and Python API.
What makes it unique: Nexus is the only tool that puts code structure (call graphs, imports, inheritance, type annotations) and documentation structure (equations, cross-references, citations, theory pages) in the same graph. This enables queries that are impossible with code-only or doc-only tools — like tracing from a literature citation through an equation to the function that implements it.
Quick Start
pip install sphinxcontrib-nexus
As a Sphinx Extension
Add to your docs/conf.py:
extensions = ['sphinxcontrib.nexus']
After sphinx-build, find the graph at <outdir>/_nexus/graph.db (SQLite) and <outdir>/_nexus/graph.json.
Standalone AST Analysis (no Sphinx needed)
nexus analyze src/ --db graph.db
MCP Server (for Claude Code / AI agents)
nexus serve --db graph.db --project-root /path/to/project
Install Skills + MCP Server for Claude Code
nexus setup # project-level: .mcp.json + .claude/skills/
nexus setup --global # user-level: ~/.claude.json + ~/.claude/skills/ (all projects)
Ingest a Paper
nexus ingest paper.pdf --db graph.db # extracts concepts, equations, citations via LLM
Interactive Graph Visualizer
nexus visualize --db graph.db # opens HTML graph explorer in browser
Configuration
| Config value | Default | Description |
|---|---|---|
nexus_output |
_nexus |
Output directory relative to build output |
nexus_ast_analyze |
True |
Run AST analysis during Sphinx build |
nexus_max_viz_nodes |
300 |
Max nodes in auto-generated graph.html |
Supported Project Layouts
Nexus works with any Python project:
- Standard packages:
myproject/mypackage/__init__.py— detected automatically - src layout:
src/mypackage/— detected automatically - Flat modules: directories with
.pyfiles but no__init__.py— detected automatically - Custom sys.path: projects that add directories to
sys.pathinconf.py— picked up from the Sphinx build environment
What the Graph Contains
Node Types (16)
| Type | Source | Example |
|---|---|---|
file |
Sphinx | RST/doc pages |
section |
Sphinx | Labeled sections (:ref: targets) |
equation |
Sphinx | Labeled math equations (:eq: targets) |
term |
Sphinx | Glossary terms |
function |
Sphinx + AST | Python functions |
class |
Sphinx + AST | Python classes |
method |
Sphinx + AST | Python methods |
attribute |
Sphinx + AST | Class attributes |
module |
Sphinx + AST | Python modules |
data |
Sphinx | Module-level data |
exception |
Sphinx | Exception classes |
type |
Sphinx | Type aliases |
external |
Auto-detected | stdlib, builtins, installed packages (numpy, scipy, ...) |
unresolved |
Auto-detected | Referenced but not documented symbols |
Edge Types (13)
| Edge | Meaning | Source |
|---|---|---|
contains |
Parent → child (toctree, module→function, class→method) | Sphinx + AST |
references |
Cross-reference (:ref:, :term:) |
Sphinx |
documents |
Doc page → code symbol (:func:, :class:) |
Sphinx |
equation_ref |
Doc → equation (:eq:) |
Sphinx |
cites |
Doc → citation | Sphinx |
implements |
Code → equation (inferred from co-occurrence in docs) | Merge |
calls |
Function → function | AST |
imports |
Module → module | AST |
inherits |
Class → parent class | AST |
type_uses |
Function → type (from annotations) | AST |
tests |
Test → tested function | AST |
derives |
Derivation → equation | AST |
MCP Tools (20)
Exploration
query— keyword search across node namescontext— 360-degree view of a symbol (all connections grouped by type)neighbors— direct connections with direction and type filteringshortest_path— how two concepts connectgod_nodes— most connected nodes (entry points)stats— graph-level statistics
Safety & Refactoring
impact— blast radius analysis (what breaks if you change X)detect_changes— map git diff to affected symbolsrename— safe multi-file rename with confidence taggingretest— minimum set of tests to re-run after changescommunities— detect functional groupings with cohesion scoresgraph_query— Cypher-like pattern matching ("function -calls-> function")bridges— find architectural hotspots connecting communities
Code + Doc Fusion (unique to Nexus)
provenance_chain— citation → equation → code traceabilityverification_coverage— equation → code → test coverage mapstaleness— detect docs that drifted from codesession_briefing— AI agent context restorationtrace_error— trace from failing test to equations on call pathmigration_plan— plan dependency migration with phased blast radiusingest— LLM-powered paper/PDF ingestion into the graphprocesses— detect named execution flows through the codebase
MCP Resources (4)
| Resource | Content |
|---|---|
nexus://graph/stats |
Node/edge counts by type |
nexus://graph/communities |
Functional area summaries |
nexus://graph/schema |
Node types, edge types, ID format |
nexus://briefing |
Session briefing for AI agents |
Skills (8)
Installed via nexus setup. Each skill triggers on natural language:
| Skill | Triggers on |
|---|---|
nexus-exploring |
"How does X work?", "What calls this?" |
nexus-impact |
"Is it safe to change X?", "What tests to re-run?" |
nexus-debugging |
"Why is X failing?", "Which equation is wrong?" |
nexus-refactoring |
"Rename this", "Extract this into a module" |
nexus-verification |
"What's verified?", "Which docs are stale?" |
nexus-migration |
"Plan numpy→jax migration" |
nexus-guide |
"What Nexus tools are available?" |
nexus-cli |
"Analyze the codebase", "Start the server" |
Storage
The graph is stored in two formats:
- SQLite (primary) — indexed queries, FTS5 full-text search, 0.05ms neighbor lookups
- JSON (secondary) — human-readable, NetworkX node-link format
Python API
from sphinxcontrib.nexus.export import load_sqlite
from sphinxcontrib.nexus.query import GraphQuery
kg = load_sqlite("_nexus/graph.db")
q = GraphQuery(kg)
# What uses numpy.ndarray?
q.query("ndarray", node_types=["external"])
# Blast radius of changing a function
q.impact("py:function:sn_solver.solve_sn", direction="upstream")
# Citation → equation → code chain
q.provenance_chain("py:function:sn_sweep.sweep_spherical")
# Migration plan
q.migration_plan("numpy", "jax")
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sphinxcontrib_nexus-0.4.2.tar.gz.
File metadata
- Download URL: sphinxcontrib_nexus-0.4.2.tar.gz
- Upload date:
- Size: 60.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d584efc4c72d85a0760e7850ea4fe71e0bfe6ffbc21d70e119d27611b4dc7a8f
|
|
| MD5 |
31111d4f8bf8bd33a27429210f1900ad
|
|
| BLAKE2b-256 |
0a2bd864d98a23b0ee095863a8f45a2251c7af3234e7ff1a22f64a372766390d
|
Provenance
The following attestation bundles were made for sphinxcontrib_nexus-0.4.2.tar.gz:
Publisher:
publish.yml on deOliveira-R/sphinxcontrib-nexus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinxcontrib_nexus-0.4.2.tar.gz -
Subject digest:
d584efc4c72d85a0760e7850ea4fe71e0bfe6ffbc21d70e119d27611b4dc7a8f - Sigstore transparency entry: 1253564261
- Sigstore integration time:
-
Permalink:
deOliveira-R/sphinxcontrib-nexus@2fd8f73dba51474d2b2826c8fcea75c7556486ee -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/deOliveira-R
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2fd8f73dba51474d2b2826c8fcea75c7556486ee -
Trigger Event:
push
-
Statement type:
File details
Details for the file sphinxcontrib_nexus-0.4.2-py3-none-any.whl.
File metadata
- Download URL: sphinxcontrib_nexus-0.4.2-py3-none-any.whl
- Upload date:
- Size: 68.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3b5586148b3b4094d2de0ff66da088bdeec96c6c77a4baef4404b140947f8f1
|
|
| MD5 |
9cf5dd9cc266f6c035d6098f89a842e3
|
|
| BLAKE2b-256 |
04bac158a53163be0f30eb6476a57f283aa21540bc4bfcb75ccf613ec50ef31f
|
Provenance
The following attestation bundles were made for sphinxcontrib_nexus-0.4.2-py3-none-any.whl:
Publisher:
publish.yml on deOliveira-R/sphinxcontrib-nexus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinxcontrib_nexus-0.4.2-py3-none-any.whl -
Subject digest:
e3b5586148b3b4094d2de0ff66da088bdeec96c6c77a4baef4404b140947f8f1 - Sigstore transparency entry: 1253564407
- Sigstore integration time:
-
Permalink:
deOliveira-R/sphinxcontrib-nexus@2fd8f73dba51474d2b2826c8fcea75c7556486ee -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/deOliveira-R
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2fd8f73dba51474d2b2826c8fcea75c7556486ee -
Trigger Event:
push
-
Statement type: