Registry / database / py2neo

py2neo

JSON →
library2021.2.4pypypi✓ verified 88d ago

Py2neo is a client library and toolkit for working with Neo4j from Python applications. As of version 2021.2.4, it supports Neo4j 4.x and uses the Bolt protocol. Development has slowed; users are encouraged to migrate to the official neo4j driver for newer Neo4j versions.

pip install py2neo
INSTALL
IMPORT
SIG · PY2NEO
P
py2neo
databasepythonv2021.2.4
Install
3.4s avg
Import
521ms
Disk
52MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2021.2.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.528s · 52.6MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 3.4s · import 0.514s · 54MB
52MB installed
● package 52MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Graph
✓ from py2neo import Graph
✗ from py2neo.database import Graph
In older versions (pre-2021), Graph was under py2neo.database. Use py2neo.Graph directly.
Node
✓ from py2neo import Node
Common mistake: from py2neo.data import Node (deprecated).
Relationship
✓ from py2neo import Relationship
Same as Node; import from top-level py2neo.
NodeMatcher
✓ from py2neo import NodeMatcher
Available from py2neo directly.

Connect to Neo4j, create nodes and a relationship, then run a Cypher query.

from py2neo import Graph, Node, Relationship # Connect to Neo4j (adjust URI/user/password) graph = Graph("bolt://localhost:7687", auth=("neo4j", "password")) # Create a node alice = Node("Person", name="Alice") graph.create(alice) # Create another node and relationship bob = Node("Person", name="Bob") knows = Relationship(alice, "KNOWS", bob) graph.create(knows) # Query back results = graph.run("MATCH (a:Person)-[:KNOWS]->(b:Person) RETURN a.name, b.name").data() print(results)
Debug
Known issues
deprecatedpy2neo is no longer actively developed. The official neo4j Python driver (neo4j) is recommended for new projects, especially for Neo4j 5.x.
fix
Use `pip install neo4j` and migrate to the official driver.
affects: >=2021.0.0
breakingVersion 2021.0 dropped support for Neo4j 3.x and removed the HTTP API for Bolt-only. Existing code using REST endpoints will break.
fix
Update connection strings from http:// to bolt:// and ensure Neo4j is 4.x+.
affects: >=2021.0.0
gotchaThe `Graph` constructor no longer accepts keyword arguments for host, port, etc. It expects a full URI string.
fix
Use `Graph('bolt://localhost:7687', auth=(user, pass))` instead of `Graph(host='localhost', ...)`.
affects: >=2021.0.0
gotchaSubgraph matching with `NodeMatcher` may return `None` if no match found; always check result before accessing attributes.
fix
Use `matcher.match('Person', name='Alice').first()` and check if result is not None.
affects: all
Errors
Common errors & fixes
AttributeError: module 'py2neo' has no attribute 'Graph'
Incorrect import in older style; or py2neo not installed correctly.
fix
Run `pip install py2neo --upgrade` and use `from py2neo import Graph`.
py2neo.database.ClientError: The client is unauthorized due to authentication failure.
Wrong credentials or missing auth tuple in Graph constructor.
fix
Provide a valid (username, password) tuple: `Graph('bolt://localhost:7687', auth=('neo4j', 'yourpassword'))`.
OSError: [Errno 111] Connection refused
Neo4j not running, or wrong host/port.
fix
Ensure Neo4j is started and reachable at the specified URI. Try `bolt://localhost:7687`.
ValueError: The protocol specified is not supported.
Using 'http' URI with a Bolt-only version of py2neo (2021+).
fix
Change to `bolt://` in the URI. Older versions accept `http://` but are deprecated.
Upgrade
Version history
2021.2.4latest on PyPI · released Oct 20, 2023
Audit
Dependencies
neoboltrequiredBolt protocol driver for Neo4j, required at runtime
neotimerequiredDateTime handling for Neo4j temporal types
urllib3requiredHTTP client for REST API calls
Agent activity
17 hits · last 30 days
node
10
Resources
py2neo — pip install py2neo · libregistry