Skip to main content

Query Grand and NetworkX graphs using Cypher syntax.

Project description

GrandCypher

GitHub Workflow Status (branch)
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:

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!
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:

# 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


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.0.1.tar.gz (41.4 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.0.1-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: grand_cypher-1.0.1.tar.gz
  • Upload date:
  • Size: 41.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.7

File hashes

Hashes for grand_cypher-1.0.1.tar.gz
Algorithm Hash digest
SHA256 576990dbc070d12ba49d39447c83515e8a62dbb1ef83986c1ec7f6391240a3e7
MD5 449b71906882a389075b499f34d32738
BLAKE2b-256 d1785c74812e3f1bc9942f88a0e5f8783113764dbcfda67a47e06dc601c63dc0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for grand_cypher-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af769d1e8c3a9a657953adaf468fbfc9d632b0d34fd6d2965248607007ef51a4
MD5 03c487ed9f4ecc8277bd872b2d06dd35
BLAKE2b-256 7dfbe658eaa18dd9103f5a88e7610243584be35501231d7ccd0c3eff3357e932

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 Pingdom Monitoring Sentry Error logging StatusPage Status page