Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aplbrain/grand-cypher
Implementation of the Cypher language for searching NetworkX graphs
https://github.com/aplbrain/grand-cypher
cypher grand graph graph-database neo4j networks networkx python
Last synced: 7 days ago
JSON representation
Implementation of the Cypher language for searching NetworkX graphs
- Host: GitHub
- URL: https://github.com/aplbrain/grand-cypher
- Owner: aplbrain
- License: apache-2.0
- Created: 2020-11-13T00:39:26.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-12-05T03:31:20.000Z (about 1 month ago)
- Last Synced: 2024-12-29T10:08:03.028Z (14 days ago)
- Topics: cypher, grand, graph, graph-database, neo4j, networks, networkx, python
- Language: Python
- Homepage:
- Size: 98.6 KB
- Stars: 87
- Watchers: 19
- Forks: 9
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-cypher - Grand-Cypher
README
GrandCypher
```shell
pip install grand-cypher
# Note: You will want a version of grandiso>=2.2.0 for best performance!
# pip install -U 'grandiso>=2.2.0'
```GrandCypher is a partial (and growing!) implementation of the Cypher graph query language written in Python, for Python data structures.
You likely already know Cypher from the Neo4j Graph Database. Use it with your favorite graph libraries in Python!
## Usage
### Example Usage with NetworkX:
```python
from grandcypher import GrandCypher
import networkx as nxGrandCypher(nx.karate_club_graph()).run("""
MATCH (A)-[]->(B)
MATCH (B)-[]->(C)
WHERE A.club == "Mr. Hi"
RETURN A.club, B.club
""")
```See [examples.md](docs/examples.md) for more!
### Example Usage with SQL
Create your own "Sqlite for Neo4j"! This example uses [grand-graph](https://github.com/aplbrain/grand) to run queries in SQL:
```python
import grand
from grandcypher import GrandCypherG = 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")GrandCypher(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 | ✅ Thanks @khoale88! |
| Backwards `()<-[]-()` edges | ✅ Thanks @khoale88! |
| Anonymous `()` nodes | ✅ Thanks @khoale88! |
| Undirected `()-[]-()` edges | ✅ Thanks @khoale88! |
| Boolean Arithmetic (`AND`/`OR`) | ✅ Thanks @khoale88! |
| `(:Type)` node-labels | ✅ Thanks @khoale88! |
| `[:Type]` edge-labels | ✅ Thanks @khoale88! |
| `DISTINCT` | ✅ Thanks @jackboyla! |
| `ORDER BY` | ✅ Thanks @jackboyla! |
| Aggregation functions (`COUNT`, `SUM`, `MIN`, `MAX`, `AVG`) | ✅ Thanks @jackboyla! |
| Aliasing of returned entities (`return X as Y`) | ✅ Thanks @jackboyla! |
| Negated edges (`where not (a)-->(b)`) | 🥺 |
| `OPTIONAL MATCH` | 🥺 |
| Graph mutations (e.g. `DELETE`, `SET`,...) | 🥺 || | | | |
| -------------- | -------------- | ----------------- | ---------------- |
| ✅ = Supported | 🛣 = On Roadmap | 🥺 = Help Welcome | 🔴 = Not Planned |## Citing
If this tool is helpful to your research, please consider citing it with:
```bibtex
# 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}
}
```