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}
}

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grand_cypher-1.2.0.tar.gz (81.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grand_cypher-1.2.0-py3-none-any.whl (73.4 kB view details)

Uploaded Python 3

File details

Details for the file grand_cypher-1.2.0.tar.gz.

File metadata

  • Download URL: grand_cypher-1.2.0.tar.gz
  • Upload date:
  • Size: 81.0 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

Hashes for grand_cypher-1.2.0.tar.gz
Algorithm Hash digest
SHA256 2fc47eeabe96e93ee9d5b41b50b611e17a849676009e9f2e3b9052ada5d8ebbf
MD5 84deb9f4b61da2dfdb8b342c8b2c016a
BLAKE2b-256 00bf1863931d5cb777ce900bc6989c7c2995e9e807e5c33403519ddec7f102bf

See more details on using hashes here.

File details

Details for the file grand_cypher-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: grand_cypher-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 73.4 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

Hashes for grand_cypher-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64021a947f9ad9e79a0c14c857bd9ce80985fd1a818d21454991cce934e37f58
MD5 8facc7d0f876c9eeafae00816c4e7eb7
BLAKE2b-256 1042ba452bb593d53327d9d5dede688b17e38b532ee0126375754d722a91bf1a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page