Skip to content

Instantly share code, notes, and snippets.

@DecisionNerd
Forked from korakot/neo4j.py
Created March 14, 2022 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DecisionNerd/efe2ffa1dd69b4c83e359f8c25b72236 to your computer and use it in GitHub Desktop.
Save DecisionNerd/efe2ffa1dd69b4c83e359f8c25b72236 to your computer and use it in GitHub Desktop.
Using Neo4j in Colab
# download 3.5.8 or neo4j-enterprise-4.0.0-alpha09mr02-unix
!curl https://neo4j.com/artifact.php?name=neo4j-community-3.5.8-unix.tar.gz -o neo4j.tar.gz
# decompress and rename
!tar -xf neo4j.tar.gz # or --strip-components=1
!mv neo4j-community-3.5.8 nj
# disable password, and start server
!sed -i '/#dbms.security.auth_enabled/s/^#//g' nj/conf/neo4j.conf
!nj/bin/neo4j start
!pip install py2neo -q
from py2neo import Graph
graph = Graph("bolt://localhost:7687")
from IPython.core.magic import register_cell_magic
@register_cell_magic
def nj(line, cell=None):
return graph.run(cell or line).to_table()
%%nj
MATCH (n) RETURN n
!pip install py2neo -q
from py2neo.data import Node, Relationship
a = Node("Person", name="Alice")
b = Node("Person", name="Bob")
ab = Relationship(a, "KNOWS", b)
ab #(Alice)-[:KNOWS]->(Bob)
# now still floating, need to add to Graph
# download and config
!wget -P nj/plugins https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/3.5.0.4/apoc-3.5.0.4-all.jar
!sed -i '/dbms.security.procedures.unrestricted/s/^#//g' nj/conf/neo4j.conf
!sed -i 's/my.extensions.example,my.procedures/apoc/' nj/conf/neo4j.conf
!nj/bin/neo4j restart
%%cypher
RETURN apoc.version()
!pip install -q ipython-cypher
import cypher # for cypher.run
%load_ext cypher
%config CypherMagic.feedback=False
%cypher MATCH (a)-[]-(b) RETURN a, b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment