Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Python and Neo4j
1. Python and Neo4j
Eric Lee
Silicon Cloud International Pte Ltd
2015.DEC.17
@Singapore Neo4j Meetup
2. About Me
Eric Lee
NoSQL
Silicon Cloud
International
:Love
:EMPLOYEE_OF
Secured
Private Cloud
:PROVIDES
Neo4j
Cassandra
:IS
:IS
Python Perl JavaScript
:PROGRAMMING_IN
:PROGRAMMING_IN
:PROGRAMMING_IN
3. Start Your Neo4j Server
• Install Oracle JDK 8
• Download Neo4j Enterprise or Community edition
• Unzip it
• In Neo4j directory, execute this command:
./bin/neo4j start
4. Python Libraries for Neo4j
• Py2neo
Good performance for great amounts of nodes.
• neo4j-rest-client
If only a few nodes, use this REST based client.
• neo4jdb-python
Mainly for Cypher syntax manipulation.
8. Create Node
• Create node with label and properties
from py2neo import Graph, Node
graph = Graph(…)
Node1 = Node(“User”, Name=“Eric”, Gender=“M”)
graph.create(Node1)
Label Properties
9. Create Relationship
• One to one relationship
from py2neo import Graph, Node, Relationship
graph = Graph(…)
eric = Node(“User”, Name=“Eric”, Gender=“M”)
sci = Node(“Company”, Name=“Silicon Cloud Intl”)
ericWorkInsci = Relationship(eric,”WORK_IN”,sci,Since=2015)
graph.create(ericWorkInsci) Relationship Name Relationship Property
CREATE (User{Name:”Eric”…})-[:WORK_IN{Since:2015}]->(Company{Name:”Silicon Cloud Intl”})
10. Search
• Find One Node
graph.find_one(“User”,”Name”,”Eric”)
• Return all Nodes
results = graph.find(“User”, “Name”,”Eric”)
# will return an object
for result in results:
print result
Label Property Value
12. Delete
• Specific Objects
eric = graph.find_one(“User”, “Name”, “Eric”)
eric.delete()
• All nodes and relationships
graph.delete_all()
Easy than “MATCH (n)-[r]-(q) DELETE n,r,q”
13. Uniqueness
• Unique nodes
graph.schema.create_uniqueness_constraint("User", “Employee_ID”)
#Set the constraint first
eric = graph.merge_one(“User”, “Employee_ID”, “0007” )
• Unique Paths
eric = graph.merge_one(“User”, “Employee_ID”, “0007” )
mojy = graph.merge_one(“User”, “Employee_ID”, “0001” )
graph.create_unique(Relationship(mojy,”RECRUITS”,eric))
14. Submit Cypher Queries
• Submit qualified Cypher Syntax
graph.cypher.execute(cypher syntax string)
Return a list, to access each element, you can create a for loop.