Created
March 18, 2019 03:35
-
-
Save excenter/bd34328637b16d4ad8158f9e70af9caa to your computer and use it in GitHub Desktop.
py2neo cheat sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from py2neo import Graph, Node, Relationship | |
graph = Graph( | |
host="alpha.graph.domain.co", | |
auth=('neo4j', 'thePassword-butBetter') | |
) | |
url="https://py2neo.org/v4/database.html#py2neo.database.Graph.delete_all" | |
a = Node("Type", url=url) | |
graph.merge(a, "Website", "url") | |
graph.pull(a) | |
print(a) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from py2neo import Graph, Node, Relationship | |
graph = Graph( | |
host="alpha.graph.domain.co", | |
auth=('neo4j', 'thePassword-butBetter') | |
) | |
badId=124464 | |
# # how to delete a particular ID | |
killme = graph.evaluate("MATCH (n) where id(n) = $badId RETURN n", badId=badId) | |
# # Delete node | |
graph.delete(killme) | |
# # this explodes if you give it None | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from py2neo import Graph, Node, Relationship | |
graph = Graph( | |
host="alpha.graph.domain.co", | |
auth=('neo4j', 'thePassword-butBetter') | |
) | |
graph.delete_all() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from py2neo import Graph, Node, Relationship | |
graph = Graph( | |
host="alpha.graph.domain.co", | |
auth=('neo4j', 'thePassword-butBetter') | |
) | |
# instead use an existing node with | |
a = Node("Type", url=url) | |
number = 2 | |
count = graph.run( | |
"MATCH(a) < -[r:CREATED]-(b) WHERE ID(a)=$spicyId AND b.number <= $number RETURN count(r)", | |
number=number, | |
spicyId=a.identity | |
).evaluate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment