0% found this document useful (0 votes)
103 views16 pages

Neo4j Connector

Jelle Jan Bankert created the neo4j-connector Python driver to efficiently interact with Neo4j databases from Python scripts. He found existing drivers to be slow for large queries of over 10,000 nodes. The neo4j-connector uses the requests library and is 4 times faster than existing solutions like py2neo for big queries, making it suitable for tasks like importing large datasets. It requires Neo4j 3.0+ and Python 3.5+ and is open source on GitHub.

Uploaded by

javabean
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views16 pages

Neo4j Connector

Jelle Jan Bankert created the neo4j-connector Python driver to efficiently interact with Neo4j databases from Python scripts. He found existing drivers to be slow for large queries of over 10,000 nodes. The neo4j-connector uses the requests library and is 4 times faster than existing solutions like py2neo for big queries, making it suitable for tasks like importing large datasets. It requires Neo4j 3.0+ and Python 3.5+ and is open source on GitHub.

Uploaded by

javabean
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

neo4j-connector

how I accidentally built the fastest* Neo4j Python driver

Jelle Jan Bankert


About me
Jelle Jan “JJ” Bankert
Research Engineer @ Textkernel
Knowledge Mining Team
Python, Neo4j, Docker, ELK-stack, Linux, etc.

The kind of person who takes pictures of presentations…


About you
Interested in interacting with Neo4j using Python scripts

I’m assuming that you have basic knowledge of:


• Neo4j
• Cypher
• Python
Context
“Can you import these 50k nodes?”
“Can you make a script that merges ‘duplicate’ nodes?”
“Can you update this property according to business logic?”
Approach
• Research and use existing tools?
• Research and use existing driver libraries?
• Look up the API and build my own connector?

ft w a re
ee r s o
e n g in , 2 0 1 9
gon na JJ
ne e r s
w ar e Engi
Sof t
neo4j-connector
• Neo4j HTTP API
• Send 1 or more Cypher queries (“statements”)
• Transactions are immediately committed
• requests library
• Responses are transformed for easy use (by default)
• Requires Neo4j 3.0+, Python 3.5+
• Open source

source: https://github.com/textkernel/neo4j-connector
Driver comparison
Drivers
• neo4j-connector
• neo4j-driver
• py2neo

Scenarios
1. RETURN count(*)
2. retrieve nodes by label, limit [10, 100, 1k, 10k, 100k]
3. retrieve nodes by name, for [10, 100, 1k, 10k] names per request
Results
• For big queries the neo4j-connector is a lot faster
• around 4x faster than py2neo
• *bolt looks better for sequential (dependent) queries

Discussion
• Compiled C vs Python
• Relative difference for complicated queries may decrease
Demo
import neo4j

connector = neo4j.Connector('http://localhost:7474', ('neo4j','neo4j'))


response = connector.run("MATCH () RETURN COUNT(*) as node_count")
first_row = response[0]
print(first_row['node_count'])
Get your hands dirty
Installation: pip install neo4j-connector

Documentation: https://neo4j-connector.readthedocs.io

Source + pull requests: https://github.com/textkernel/neo4j-connector

email: [email protected]

this presentation: https://bit.ly/2HY40gw


neo4j-connector core
statement = {'statement': cypher, 'parameters': parameters)
requests.post(self.endpoint, json={'statements': [statement]}, auth=self.credentials).json()

You might also like