Skip to main content

Grand-Cypher

GitHub Workflow Status (branch)
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, or read the expressions and functions guide. Implementation details are documented in Architecture.md.

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, COLLECT) ✅ Thanks @jackboyla!
Aliasing of returned entities (return X as Y) ✅ Thanks @jackboyla!
WHERE clause arithmetic support for math / numbers ✅ Thanks @q-rosiebloxsom!
Scalar functions (toLower, toUpper, trim, coalesce, size, type) ✅
Relationship lists and predicates (ALL, ANY, NONE, SINGLE) ✅
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}
}

Metadata

Release files for grand-cypher 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for grand-cypher 1.2.0
File Size Uploaded
grand_cypher-1.2.0.tar.gz 81.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for grand-cypher 1.2.0
File Interpreter ABI Platform
grand_cypher-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 154.3 kB

Release files / grand_cypher-1.2.0.tar.gz

Download URL grand_cypher-1.2.0.tar.gz
Size 81.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2fc47eeabe96e93ee9d5b41b50b611e17a849676009e9f2e3b9052ada5d8ebbf
BLAKE2b-256 checksum
How to use checksums
00bf1863931d5cb777ce900bc6989c7c2995e9e807e5c33403519ddec7f102bf
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / grand_cypher-1.2.0-py3-none-any.whl

Download URL grand_cypher-1.2.0-py3-none-any.whl
Size 73.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
64021a947f9ad9e79a0c14c857bd9ce80985fd1a818d21454991cce934e37f58
BLAKE2b-256 checksum
How to use checksums
1042ba452bb593d53327d9d5dede688b17e38b532ee0126375754d722a91bf1a
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.13.0

1 release file

0.12.0

1 release file

0.11.0

1 release file

0.10.0

1 release file

0.9.0

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page