Skip to content

Add Neo4j Cypher export (--neo4j)#2774

Merged
soxoj merged 1 commit into
soxoj:mainfrom
thunderstornX:neo4j-export
Jun 29, 2026
Merged

Add Neo4j Cypher export (--neo4j)#2774
soxoj merged 1 commit into
soxoj:mainfrom
thunderstornX:neo4j-export

Conversation

@thunderstornX

Copy link
Copy Markdown
Contributor

Summary

Adds a --neo4j export that serializes the maigret graph (the same one --graph builds) into a Cypher script importable into Neo4j, per #2630 and your go-ahead there.

Closes #2630

What it does

maigret <username> --neo4j writes a *_neo4j.cypher file. It reuses the existing MaigretGraph (the structure behind --graph), so it captures the same username / account / site / data nodes and relationships, and serializes them as idempotent Cypher:

  • each node is MERGEd on a unique name (re-imports do not create duplicates),
  • edges become [:LINKED_TO] relationships,
  • with a CREATE CONSTRAINT ... IF NOT EXISTS on the node name.

No new runtime dependency (networkx is already used). Import with cypher-shell -u neo4j -p <pw> < <file>.cypher, or paste into the Neo4j Browser.

Refactor

I extracted the graph-building out of save_graph_report into a shared _build_maigret_graph() helper so both --graph and --neo4j use it; save_graph_report behavior is unchanged.

Testing

  • Full pytest suite passes. Added tests/test_report.py::test_generate_neo4j_report (covers the Cypher structure plus escaping of quotes and newlines) and updated tests/test_cli.py's arg baseline for the new flag. No regressions; --graph still works.
  • Live import: generated the Cypher from a real scan and imported it into Neo4j 5 with zero errors (25 nodes / 26 relationships; idempotent on re-import).
  • Docs: added --neo4j to the README usage block and docs/source/command-line-options.rst.

Note: the CREATE CONSTRAINT ... IF NOT EXISTS FOR ... REQUIRE line uses Neo4j 4.4+ syntax; the MERGE statements keep the import idempotent on any version.

Serialize the maigret graph (the same one --graph builds) into an idempotent Cypher script importable into Neo4j. Reuses MaigretGraph via an extracted _build_maigret_graph() helper, leaving save_graph_report behavior unchanged; no new runtime dependency. Adds the --neo4j flag, the neo4j_report setting, docs, and a unit test.

Closes soxoj#2630
@thunderstornX

Copy link
Copy Markdown
Contributor Author
neo4j_browser_graph

@soxoj

soxoj commented Jun 29, 2026

Copy link
Copy Markdown
Owner

@thunderstornX amazing job, thanks a lot for an amazing contribution!
Sorry for the delay, I needed time to test it 👍
Feel free to improve this functionality further!

@soxoj
soxoj merged commit e41c4d7 into soxoj:main Jun 29, 2026
6 checks passed
@thunderstornX

Copy link
Copy Markdown
Contributor Author
image thank you for your support and guidance, I will try to contribute more, I Just completed my Masters and am Looking for opportunities, feel free to visit my profile and throw any openings :) i will be thankful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add export to Neo4j

2 participants