Graph Data Types

Cypher queries can return entire graph structures as well as individual property values.

The graph data types detailed here model graph data returned from a Cypher query. Graph values cannot be passed in as parameters as it would be unclear whether the entity was intended to be passed by reference or by value. The identity or properties of that entity should be passed explicitly instead.

The driver contains a corresponding class for each of the graph types that can be returned.

Cypher Type Python Type
Node Node
Relationship Relationship
Path Path
class neo4j.types.graph.Graph

A local, self-contained graph object that acts as a container for Node and Relationship instances. This is typically obtained via the BoltStatementResult.graph() method.

Graph.nodes

Access a set view of the nodes in this graph.

Graph.relationships

Access a set view of the relationships in this graph.

Graph.relationship_type(name)

Obtain a Relationship subclass for a given relationship type name.

class neo4j.types.graph.Node
node == other

Compares nodes for equality.

node != other

Compares nodes for inequality.

hash(node)

Computes the hash of a node.

len(node)

Returns the number of properties on a node.

iter(node)

Iterates through all properties on a node.

node[key]

Returns a node property by key. Raises KeyError if the key does not exist.

key in node

Checks whether a property key exists for a given node.

Node.graph

The Graph to which this entity belongs.

Node.id

The identity of this entity in its container Graph.

Node.labels

The set of labels attached to this node.

Node.get(name, default=None)

Get a property value by name, optionally with a default.

Node.keys()

Return an iterable of all property names.

Node.values()

Return an iterable of all property values.

Node.items()

Return an iterable of all property name-value pairs.

class neo4j.types.graph.Relationship
relationship == other

Compares relationships for equality.

relationship != other

Compares relationships for inequality.

hash(relationship)

Computes the hash of a relationship.

len(relationship)

Returns the number of properties on a relationship.

iter(relationship)

Iterates through all properties on a relationship.

relationship[key]

Returns a relationship property by key. Raises KeyError if the key does not exist.

key in relationship

Checks whether a property key exists for a given relationship.

type(relationship)

Returns the type (class) of a relationship. Relationship objects belong to a custom subtype based on the type name in the underlying database.

Relationship.graph

The Graph to which this entity belongs.

Relationship.id

The identity of this entity in its container Graph.

Relationship.nodes

The pair of nodes which this relationship connects.

Relationship.start_node

The start node of this relationship.

Relationship.end_node

The end node of this relationship.

Relationship.type

The type name of this relationship. This is functionally equivalent to type(relationship).__name__.

Relationship.get(name, default=None)

Get a property value by name, optionally with a default.

Relationship.keys()

Return an iterable of all property names.

Relationship.values()

Return an iterable of all property values.

Relationship.items()

Return an iterable of all property name-value pairs.

class neo4j.types.graph.Path
path == other

Compares paths for equality.

path != other

Compares paths for inequality.

hash(path)

Computes the hash of a path.

len(path)

Returns the number of relationships in a path.

iter(path)

Iterates through all the relationships in a path.

Path.graph

The Graph to which this path belongs.

Path.nodes

The sequence of Node objects in this path.

Path.start_node

The first Node in this path.

Path.end_node

The last Node in this path.

Path.relationships

The sequence of Relationship objects in this path.