Goals This guide provides an overview of how to connecting to Neo4j from Python. While it is not comprehensive, it aims to introduce the available drivers and links to other relevant resources. Prerequisites You should be familiar with graph database… Learn More →

Goals
This guide provides an overview of how to connecting to Neo4j from Python. While it is not comprehensive, it aims to introduce the available drivers and links to other relevant resources.
Prerequisites
Intermediate

python logo master v3 TM


Neo4j can be installed on any system and then accessed via its binary and HTTP APIs.

You can use the official binary driver for Python (neo4j-python-driver) or connect via HTTP with any of our community drivers.

Neo4j Python Driver

Unresolved directive in <stdin> – include::../_includes/python-driver.adoc[]

Unresolved directive in <stdin> – include::../_includes/sample_project.adoc[]

Unresolved directive in <stdin> – include::../_includes/community-driver-notice.adoc[]

For anyone working with Python, the Neo4j community have contributed a range of driver options. These range from lightweight to comprehensive driver packages as well as libraries designed for use with web frameworks such as Django.

Both Python 2 and Python 3 are supported by most of the libraries listed here and this should help give more flexibility when putting together your Neo4j-based technology stack.

While we do not provide a specific web framework recommendation, both the lightweight Flask and the more comprehensive Django frameworks are known to work well.

Many Pythonistas have invested a lot of time and love to develop these libraries, so if you use them, please provide feedback to the authors and help us improve.

Py2neo

py2neo.200x200

Py2neo is a client library and comprehensive toolkit for working with Neo4j from within Python applications and from the command line. The core library has no external dependencies and has been carefully designed to be easy and intuitive to use.

Author

Nigel Small

Package

https://pypi.python.org/pypi/py2neo

Source

https://github.com/nigelsmall/py2neo

Example

https://github.com/neo4j-examples/movies-python-py2neo-2.0

Docs

http://py2neo.org/

Python

2.7 / 3.3 / 3.4

Installation
pip install py2neo
Example
from py2neo import Graph, Path

graph = Graph()



tx = graph.cypher.begin()

for name in ["Alice", "Bob", "Carol"]:

    tx.append("CREATE (person:Person {name:{name}}) RETURN person", name=name)

alice, bob, carol = [result.one for result in tx.commit()]



friends = Path(alice, "KNOWS", bob, "KNOWS", carol)

graph.create(friends)

Neo4jRestClient

The main goal of neo4j-rest-client was to enable Python programmers already using Neo4j locally through python-embedded, to use the Neo4j REST server. So the syntax of neo4j-rest-client’s API is fully compatible with python-embedded. However, a new syntax is introduced in order to reach a more pythonic style and to enrich the API with the new features the Neo4j team introduces.

Author

Javier de la Rosa

Package

https://pypi.python.org/pypi/neo4jrestclient/

Source

https://github.com/versae/neo4j-rest-client

Example

https://github.com/neo4j-examples/movies-python-neo4jrestclient

Docs

http://neo4j-rest-client.readthedocs.org/

Bulbflow

blubflow.200x200

Bulbs is an open-source Python persistence framework for graph databases and the first piece of a larger web development toolkit. It’s like an ORM for graphs.

Author

James Thornton

Package

https://pypi.python.org/pypi/bulbs

Source

https://github.com/espeed/bulbs

Docs

http://bulbflow.com/

Python

2.6 / 2.7 / 3.0 / 3.1 / 3.2

NeoModel

neomodel.200x80

An Object Graph Mapper (OGM) also usable for Django for the Neo4j graph database.

Author

Robin Edwards

Package

https://pypi.python.org/pypi/neomodel

Source

http://github.com/robinedwards/neomodel

Docs

http://neomodel.readthedocs.org/

Python

2.7 / 3.4 / pypy / pypy3