Skip to content

Instantly share code, notes, and snippets.

@excenter
Created March 18, 2019 03:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save excenter/bd34328637b16d4ad8158f9e70af9caa to your computer and use it in GitHub Desktop.
Save excenter/bd34328637b16d4ad8158f9e70af9caa to your computer and use it in GitHub Desktop.
py2neo cheat sheet
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)
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
from py2neo import Graph, Node, Relationship
graph = Graph(
host="alpha.graph.domain.co",
auth=('neo4j', 'thePassword-butBetter')
)
graph.delete_all()
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