Node metrics and functions

Nodes can be accessed by storing the object returned from a call to add_node(), by directly asking for a specific entity via node(), or by iterating over all entities via nodes. Once you have a node, you can ask it some questions.

Update history

Nodes have functions for querying their earliest_time and latest_time (as an epoch or datetime) as well as for accessing their full history (using history or history.dt).

The history property returns all events on a node, including both direct node updates and events on connected edges. If you only want to count events that occurred on connected edges, use edge_history_count().

In the example below, both values are the same because we only loaded edge updates when building the graph. If we had also called add_node() with timestamps, history would include those additional events.

For more details on working with temporal history, see History and EventTime.

Neighbours, edges and paths

To investigate who a node is connected with we can ask for its degree(), edges, or neighbours. As Raphtory graphs are directed, all of these functions also have an in_ and out_ variation, allowing you get only incoming and outgoing connections respectively. These functions return the following:

  • degree: A count of the number of unique connections a node has
  • edges: An Edges iterable of edge objects, one for each unique (src,dst) pair
  • neighbours: A PathFromNode iterable of node objects, one for each entity the original node shares an edge with

In the code below we call a selection of these functions to show the sort of questions you may ask.

The final section of the code makes use of v.neighbours.name.collect() - this is a chain of functions which are run on each node in the PathFromNode iterable. We will discuss these sort of operations more in Chaining functions.

Selecting subsets with []

You can also use [] indexing with filter expressions to select a subset of neighbours, edges, or nodes. Unlike creating a filtered graph view, the filter does not persist on the returned entities — it simply selects which ones to return.

This non-persistent behaviour is particularly powerful for graph traversal — for example, finding all baboons that groom Felipe, then exploring who they play with. We cover these multi-hop patterns in depth in Chaining Queries.

The .nbr property on an edge returns the "other" node — the neighbour from the node's perspective. When traversing from a node via its edges, you don't always know whether you're the source or destination of each edge. Using .nbr gives you the node at the opposite end, regardless of direction.

For more details on filter expressions and combining filters with logical operators, see Filtering.

Node type and layers

Use node_type to get a node's type, and has_layer() to check if a node has edges in a specific layer.