The Py2neo Handbook - EOL !

PyPI version PyPI Downloads License Coverage Status

Py2neo is a client library and toolkit for working with Neo4j from within Python applications. The library supports both Bolt and HTTP and provides a high level API, an OGM, admin tools, a Cypher lexer for Pygments, and many other bells and whistles.

Warning

Py2neo is now End of Life. There will be no more updates. It is recommended to use the official Neo4j drivers instead, or if you have more feature-rich use cases like OGM, consider other options like neomodel.

Since the original maintainer of the library deleted the PyPI index, it was necessary to create a new tag for the latest version : 2021.1.4

As for past versions, you can still find them in PyPI, but under a new package name : py2neo-history

Original introduction :

Command line tooling has been removed from the library in py2neo 2021.2. This functionality now exists in the separate ipy2neo project.

As of version 2021.1, Py2neo contains full support for routing, as exposed by a Neo4j cluster. This can be enabled using a neo4j://... URI or by passing routing=True to a Graph constructor.

Py2neo also provides support for the multi-database functionality added in Neo4j 4.0. More about this can be found in the documentation for the Graph class.

Remember to take a look at the full release notes for version 2021.2.

Installation & Compatibility

To install the latest release of py2neo, simply use:

$ pip install py2neo

The following versions of Python and Neo4j (all editions) are supported:

Neo4j

Python 3.5+

Python 2.7

4.4

GitHub workflow status for tests against Neo4j 4.4 using py35+

GitHub workflow status for tests against Neo4j 4.4 using py27

4.3

GitHub workflow status for tests against Neo4j 4.3 using py35+

GitHub workflow status for tests against Neo4j 4.3 using py27

4.2

GitHub workflow status for tests against Neo4j 4.2 using py35+

GitHub workflow status for tests against Neo4j 4.2 using py27

4.1

GitHub workflow status for tests against Neo4j 4.1 using py35+

GitHub workflow status for tests against Neo4j 4.1 using py27

4.0

GitHub workflow status for tests against Neo4j 4.0 using py35+

GitHub workflow status for tests against Neo4j 4.0 using py27

3.5

GitHub workflow status for tests against Neo4j 3.5 using py35+

GitHub workflow status for tests against Neo4j 3.5 using py27

3.4

GitHub workflow status for tests against Neo4j 3.4 using py35+

GitHub workflow status for tests against Neo4j 3.4 using py27

Note that py2neo is developed and tested under Linux using standard CPython distributions. While other operating systems and Python distributions may work, support for these is not available.

Quick Example

To run a query against a local database is straightforward:

>>> from py2neo import Graph
>>> graph = Graph("bolt://localhost:7687", auth=("neo4j", "password"))
>>> graph.run("UNWIND range(1, 3) AS n RETURN n, n * n as n_sq")
   n | n_sq
-----|------
   1 |    1
   2 |    4
   3 |    9

Releases & Versioning

As of 2020, py2neo has switched to Calendar Versioning, using a scheme of YYYY.N.M. Here, N is an incrementing zero-based number for each year, and M is a revision within that version (also zero-based).

No compatibility guarantees are given between versions, but as a general rule, a change in M should require little-to-no work within client applications, whereas a change in N may require some work. A change to the year is likely to require a more significant amount of work to upgrade.

Note that py2neo is developed on a rolling basis, so patches are not made to old versions. Users will instead need to install the latest release to adopt bug fixes.

Core Graph API

Py2neo consists of several distinct regions of API, the heart of which is the Graph API. This has evolved from the original, foundational API included with early versions of the library, and remains relevant for general purpose use today.

The Graph class represents a graph database exposed by a Neo4j service running on a single instance or cluster, and which provides access to a large portion of the most commonly used py2neo features. The full DBMS is represented by a GraphService object.

For convenience, all core functions and classes are exported from the py2neo root namespace. This includes all connectivity and database management functionality as well as entity matching and core errors.

Data Types

The Node and Relationship objects are key to this library, both of which extend the Subgraph class. A comprehensive set of graph structure data types and operations are provided, allowing great flexibility in how graph data can be used.

Cypher

Bulk Operations

Object-Graph Mapping

Python DB API 2.0 Compatibility

Guides