# How to Export code-review-graph to GraphML, Neo4j, or Obsidian Formats

> Export your code-review-graph data to GraphML, Neo4j, or Obsidian formats using dedicated functions. Learn how to serialize your graph for analysis and integration.

- Repository: [Tirth Kanani/code-review-graph](https://github.com/tirth8205/code-review-graph)
- Tags: how-to-guide
- Published: 2026-07-26

---

**The code-review-graph library provides dedicated functions `export_graphml()`, `export_neo4j_cypher()`, and `export_obsidian_vault()` in [`exports.py`](https://github.com/tirth8205/code-review-graph/blob/main/exports.py) to serialize the internal `GraphStore` to GraphML XML, Neo4j Cypher scripts, or an Obsidian markdown vault.**

The code-review-graph library models your entire codebase as a directed multigraph using the `GraphStore` class. When you need to analyze or visualize this graph in external tools, the library offers a unified export pipeline that converts the internal graph structure into three popular formats. All exporters follow a consistent pattern: first retrieving a serializable payload from the graph store, then writing the target format to disk.

## Understanding the Export Pipeline

All export operations begin with `export_graph_data(store)` defined in [`visualization.py`](https://github.com/tirth8205/code-review-graph/blob/main/visualization.py) at line 102. This function extracts the in-memory payload containing nodes and edges collections from the `GraphStore` instance.

The `GraphStore` class, defined in [`graph.py`](https://github.com/tirth8205/code-review-graph/blob/main/graph.py), serves as the central data model holding the directed multigraph structure. It provides the `store.graph` property containing the raw nodes and edges, plus utility methods such as `_sanitize_name` for cleaning identifiers.

## Exporting to GraphML Format

The `export_graphml(store, output_path)` function ([`exports.py`](https://github.com/tirth8205/code-review-graph/blob/main/exports.py) line 58) generates an XML document compliant with the GraphML schema specification. 

For each node in the graph, it emits `<data>` elements capturing attributes such as `kind`, `file`, `language`, and `community`. Edges receive a `kind` attribute indicating the relationship type between code entities. This format is compatible with visualization tools like Gephi, yEd, and Cytoscape.

## Exporting to Neo4j Cypher

For Neo4j compatibility, `export_neo4j_cypher(store, output_path)` ([`exports.py`](https://github.com/tirth8205/code-review-graph/blob/main/exports.py) line 124) generates executable Cypher statements. 

The exporter creates `CREATE (:<Label> {...});` statements for nodes and `MATCH … CREATE (a)-[:REL]->(b);` statements for relationships. Helper functions `_cypher_escape` and `_cypher_props` (lines 73-88) ensure proper escaping of string literals and property formatting to prevent injection issues and handle special characters safely.

## Exporting to Obsidian Vault

The `export_obsidian_vault(store, output_dir)` function ([`exports.py`](https://github.com/tirth8205/code-review-graph/blob/main/exports.py) line 95) produces a complete Obsidian-compatible markdown vault. 

It generates one markdown file per node containing YAML front-matter with metadata and wikilinks (`[[...]]`) connecting related entities. The exporter also creates community overview pages and a master index for navigation. The `_obsidian_slug` helper (lines 146-151) converts node names into filesystem-safe filenames, ensuring compatibility across Windows, macOS, and Linux.

## Programmatic Python API

To export programmatically, first load your project to obtain a `GraphStore` instance, then call the appropriate export function:

```python
from pathlib import Path
from code_review_graph.main import load_project
from code_review_graph.exports import (
    export_graphml,
    export_neo4j_cypher,
    export_obsidian_vault,
)

# Load repository into GraphStore

store = load_project(Path("/path/to/my/code"))

# Export to GraphML

export_graphml(store, Path("output.graphml"))

# Export to Neo4j Cypher script

export_neo4j_cypher(store, Path("import.cypher"))

# Export to Obsidian vault directory

export_obsidian_vault(store, Path("obsidian_vault"))

```

## Command-Line Interface

The CLI interface in [`cli.py`](https://github.com/tirth8205/code-review-graph/blob/main/cli.py) (lines 1658-1685) exposes the same export functionality through the `--export` flag:

```bash

# GraphML export

code-review-graph --project /path/to/project --export graphml --out graph.graphml

# Neo4j Cypher export

code-review-graph --project /path/to/project --export neo4j --out import.cypher

# Obsidian vault export

code-review-graph --project /path/to/project --export obsidian --out ./vault

```

## Summary

- The `GraphStore` class in [`graph.py`](https://github.com/tirth8205/code-review-graph/blob/main/graph.py) maintains the directed multigraph representation of your codebase
- All exporters rely on `export_graph_data()` from [`visualization.py`](https://github.com/tirth8205/code-review-graph/blob/main/visualization.py) (line 102) to serialize the graph payload
- **GraphML exports** ([`exports.py`](https://github.com/tirth8205/code-review-graph/blob/main/exports.py) line 58) create XML files with node attributes like `kind`, `file`, and `community`
- **Neo4j exports** ([`exports.py`](https://github.com/tirth8205/code-review-graph/blob/main/exports.py) line 124) generate `CREATE` and `MATCH` Cypher statements with proper string escaping via `_cypher_escape`
- **Obsidian exports** ([`exports.py`](https://github.com/tirth8205/code-review-graph/blob/main/exports.py) line 95) build markdown vaults with YAML front-matter and wikilinks, using `_obsidian_slug` (lines 146-151) for safe filenames
- Both Python API and CLI ([`cli.py`](https://github.com/tirth8205/code-review-graph/blob/main/cli.py) lines 1658-1685) support all three formats

## Frequently Asked Questions

### What is the difference between the GraphML and Neo4j export formats?

GraphML is an XML-based format suitable for visualization tools like Gephi and Cytoscape, preserving node attributes as data elements. Neo4j export generates Cypher query language scripts that recreate the graph structure in a Neo4j database using `CREATE` statements for nodes and relationships, optimized for graph database import.

### Can I customize the node attributes included in the exports?

The exporters automatically include standard attributes defined in the `GraphStore` such as `kind`, `file`, `language`, and `community`. To add custom attributes, you would need to modify the node data structure in [`graph.py`](https://github.com/tirth8205/code-review-graph/blob/main/graph.py) and update the respective exporter logic in [`exports.py`](https://github.com/tirth8205/code-review-graph/blob/main/exports.py), as all formats consume the same payload from `export_graph_data()`.

### How does the Obsidian vault export handle special characters in filenames?

The `export_obsidian_vault()` function uses the `_obsidian_slug` helper ([`exports.py`](https://github.com/tirth8205/code-review-graph/blob/main/exports.py) lines 146-151) to sanitize node names into filesystem-safe strings. This ensures that special characters or spaces in code entity names do not break the markdown file creation process across different operating systems.

### Is there a performance difference between exporting via Python API versus CLI?

No significant performance difference exists because the CLI commands in [`cli.py`](https://github.com/tirth8205/code-review-graph/blob/main/cli.py) (lines 1658-1685) simply import and invoke the same export functions available in the Python API. Both methods utilize the `export_graph_data()` pipeline from [`visualization.py`](https://github.com/tirth8205/code-review-graph/blob/main/visualization.py) to prepare the serializable graph payload before writing to disk.