Grand-Cypher
pip install grand-cypher
Grand-Cypher 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:
from grandcypher import GrandCypher
import networkx as nx
GrandCypher(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 grandcypher import GrandCypher
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")
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! |
IN |
✅ Thanks @davidmezzetti! |
Aggregation functions (COUNT, SUM, MIN, MAX, AVG) |
✅ Thanks @jackboyla! |
Aliasing of returned entities (return X as Y) |
✅ Thanks @jackboyla! |
WHERE clause arithmetic support for math / numbers |
✅ Thanks @q-rosiebloxsom! |
Negated edges (where not (a)-->(b)) |
🥺 |
OPTIONAL MATCH |
🥺 |
Graph mutations (e.g. DELETE, SET,...) |
🥺 |
| ✅ = Supported | 🛣 = On Roadmap | 🥺 = Help Welcome | 🔴 = Not Planned |
Plus several quality-of-life features for Python users, such as:
| Feature | Support |
|---|---|
| Interoperability with NetworkX, Grand, and other Python graph libraries | ✅ |
| Support for node and edge Labels | ✅ ([Read More]) |
| Pickleable results | ✅ Thanks @q-rosiebloxsom! |
Citing
If this tool is helpful to your research, please consider citing it with:
# 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}
}
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 grand_cypher-1.1.0.tar.gz.
File metadata
- Download URL: grand_cypher-1.1.0.tar.gz
- Upload date:
- Size: 72.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87d386616f660a17db4ed189286f74e02a0635f32fe2fca47d734bfaeba47c7e
|
|
| MD5 |
b4eaa5014dfc3dc57a741a17d8c79ba4
|
|
| BLAKE2b-256 |
1e3a758725b7bfc51894a6df3644eea4a29b16cc9cdf935d53f38b3996f24851
|
File details
Details for the file grand_cypher-1.1.0-py3-none-any.whl.
File metadata
- Download URL: grand_cypher-1.1.0-py3-none-any.whl
- Upload date:
- Size: 63.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ee790f5d8b773fce9105fa88480e61fa2ae6f84e2514c44369dac4107f37aa9
|
|
| MD5 |
bede023f2f61d46aaf4def317c4daacb
|
|
| BLAKE2b-256 |
f6505951832881afc9f67dbb42760c6dce9e12372018e62fc4e2fce1d027f892
|