Add Cypher query language support#147
Merged
villelaitila merged 3 commits intosoftagram:mainfrom Mar 17, 2026
Merged
Conversation
Introduce openCypher query support via a pluggable sPyCy backend, enabling
graph pattern matching directly against sgraph's hierarchical data model.
The implementation bridges sgraph's dual-layer structure (element tree +
association edges) to Cypher's labeled property graph model:
- SElement type attributes become node labels (:file, :class, :function)
- SElementAssociation deptype becomes relationship types (:imports, :inc)
- Parent-child hierarchy is optionally exposed as :CONTAINS relationships
- Element attrs and computed name/path are exposed as node properties
Key components:
src/sgraph/cypher.py
- SGraphCypherBackend: read-only sPyCy Graph ABC implementation
- cypher_query(): one-call API returning pandas DataFrames
- Subgraph extraction from query results back to SGraph models
- CLI with interactive REPL (python -m sgraph.cypher)
CLI output formats:
- Tabular: table, csv, tsv, json, jsonl
- Graph: xml, deps, dot, plantuml, graphml, cytoscape
(graph formats reconstruct an SGraph subgraph from matched
Node/Edge objects and export via existing converters)
docs/graph-conventions.md
- Documents the software architecture convention (project element,
External subtree, element types, association types, hierarchy
semantics, path format)
- Documents the genealogy convention (flat structure, person naming,
parent associations)
- Defines what a convention must specify for meaningful queries
docs/cypher.md
- Full documentation with Python API, CLI usage, query examples
for both software and genealogy conventions, output format
reference, and supported Cypher feature matrix
Optional dependency: pip install spycy-aneeshdurg
Optional dependency for the Cypher query module (python -m sgraph.cypher). Audited: no CVEs, no postinstall hooks, no network/subprocess calls, MIT license. Its deps (numpy, pandas) already overlap with sgraph's own.
Document the Cypher module in developer docs (CLAUDE.md) and user-facing README. Includes Python API example, CLI usage, and links to full docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/sgraph/cypher.py)docs/graph-conventions.md)docs/cypher.md)What it does
Enables querying sgraph models with Cypher pattern matching:
Python API:
CLI with interactive REPL:
11 output formats: table, csv, tsv, json, jsonl, xml, deps, dot, plantuml, graphml, cytoscape. Graph formats extract a subgraph from query results and export via existing sgraph converters.
Design
The
SGraphCypherBackendmaps sgraph's dual-layer model (element tree + association edges) to Cypher's labeled property graph::file,:class):imports,:inc):CONTAINSrelationships (optional)Optional dependency:
pip install spycy-aneeshdurgTest plan
*1..N), OPTIONAL MATCH, WITH, UNION\formatswitching