Query NetworkX graphs using Cypher syntax. Extended fork of GrandCypher.
Project description
nxCypher
nxCypher is an extended fork of GrandCypher, a partial (and growing!) implementation of the Cypher graph query language written in Python, for Python data structures.
pip install nxcypher
# Note: You will want a version of grandiso>=2.2.0 for best performance!
You likely already know Cypher from the Neo4j Graph Database. Use it with your favorite graph libraries in Python!
Usage
Example Usage with NetworkX:
from nxcypher import NXCypher
import networkx as nx
NXCypher(nx.karate_club_graph()).run("""
MATCH (A)-[]->(B)
MATCH (B)-[]->(C)
WHERE A.club == "Mr. Hi"
RETURN A.club, B.club
""")
See examples.md for more!
Example Usage with SQL
Create your own "Sqlite for Neo4j"! This example uses grand-graph to run queries in SQL:
import grand
from nxcypher import NXCypher
G = grand.Graph(
backend=grand.backends.SQLBackend(
db_url="my_persisted_graph.db",
directed=True
)
)
# use the networkx-style API for the Grand library:
G.nx.add_node("A", foo="bar")
G.nx.add_edge("A", "B")
G.nx.add_edge("B", "C")
G.nx.add_edge("C", "A")
NXCypher(G.nx).run("""
MATCH (A)-[]->(B)-[]->(C)
MATCH (C)-[]->(A)
WHERE
A.foo == "bar"
RETURN
A, B, C
""")
Feature Parity
| Feature | Support |
|---|---|
Multiple MATCH clauses |
✅ |
WHERE-clause filtering on nodes |
✅ |
Anonymous -[]- edges |
✅ |
LIMIT |
✅ |
SKIP |
✅ |
Node/edge attributes with {} syntax |
✅ |
WHERE-clause filtering on edges |
✅ |
Named -[]- edges |
✅ |
Chained ()-[]->()-[]->() edges |
✅ |
Backwards ()<-[]-() edges |
✅ |
Anonymous () nodes |
✅ |
Undirected ()-[]-() edges |
✅ |
Boolean Arithmetic (AND/OR) |
✅ |
(:Type) node-labels |
✅ |
[:Type] edge-labels |
✅ |
DISTINCT |
✅ |
ORDER BY |
✅ |
IN |
✅ |
Aggregation functions (COUNT, SUM, MIN, MAX, AVG) |
✅ |
COUNT(*) aggregate |
✅ |
DISTINCT in aggregates (COUNT(DISTINCT x)) |
✅ |
COLLECT() aggregation |
✅ |
Aliasing of returned entities (return X as Y) |
✅ |
Negated edges (WHERE NOT (a)-->(b)) |
✅ |
OPTIONAL MATCH |
✅ |
Multiple independent OPTIONAL MATCH |
✅ |
WITH clause |
✅ |
UNWIND clause |
✅ |
Graph mutations (CREATE, SET, DELETE, DETACH DELETE) |
✅ |
REMOVE clause |
✅ |
MERGE clause with ON CREATE/ON MATCH |
✅ |
String functions (toLower, toUpper, trim) |
✅ |
List functions (size, head, tail) |
✅ |
Type functions (type, labels, keys) |
✅ |
CASE expressions (searched and simple) |
✅ |
UNION / UNION ALL |
✅ |
| List comprehensions | ✅ |
| ✅ = Supported | 🛣 = On Roadmap | 🥺 = Help Welcome | 🔴 = Not Planned |
Attribution
nxCypher is an extended fork of GrandCypher by APL Brain. The original project provides the foundation for this implementation.
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines, including the DCO sign-off requirement.
License
nxCypher is licensed under the Apache License 2.0.
This project implements a subset of the Cypher query language. Cypher is a registered trademark of Neo4j, Inc. This project is not affiliated with or endorsed by Neo4j, Inc.
Citing
If this tool is helpful to your research, please consider citing the original GrandCypher work:
# https://doi.org/10.1038/s41598-021-91025-5
@article{Matelsky_Motifs_2021,
title={{DotMotif: an open-source tool for connectome subgraph isomorphism search and graph queries}},
volume={11},
ISSN={2045-2322},
url={http://dx.doi.org/10.1038/s41598-021-91025-5},
DOI={10.1038/s41598-021-91025-5},
number={1},
journal={Scientific Reports},
publisher={Springer Science and Business Media LLC},
author={Matelsky, Jordan K. and Reilly, Elizabeth P. and Johnson, Erik C. and Stiso, Jennifer and Bassett, Danielle S. and Wester, Brock A. and Gray-Roncal, William},
year={2021},
month={Jun}
}
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 nxcypher-1.0.0.tar.gz.
File metadata
- Download URL: nxcypher-1.0.0.tar.gz
- Upload date:
- Size: 109.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b8317ceaf588332dee3df8553f7525441a064881559151117b68d87e226f558
|
|
| MD5 |
04b71ace3fdb942aacb16ceffbd5f382
|
|
| BLAKE2b-256 |
c15f25c75b3a769751f55e3d17e23fafc664cdce6ce5a65d230730634e44410f
|
File details
Details for the file nxcypher-1.0.0-py3-none-any.whl.
File metadata
- Download URL: nxcypher-1.0.0-py3-none-any.whl
- Upload date:
- Size: 100.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
936e8423d30dce9cfa3791f039a8addb2fc06c2490f40a33e9e56418b5de1407
|
|
| MD5 |
397b59d240f4be1f815e21fb4873c403
|
|
| BLAKE2b-256 |
37290cb2fb2760d7f6ed7abbabb9c9eb08a1c1851cb9b99feec47d663171824b
|