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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.528s · 52.6MB
glibcpy 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)
Errors
Common errors & fixes
AttributeError: module 'py2neo' has no attribute 'Graph'
Incorrect import in older style; or py2neo not installed correctly.
fixRun `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.
fixProvide a valid (username, password) tuple: `Graph('bolt://localhost:7687', auth=('neo4j', 'yourpassword'))`. OSError: [Errno 111] Connection refused
Neo4j not running, or wrong host/port.
fixEnsure 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+).
fixChange 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