Graph#

class raphtory.Graph#

Bases: GraphView

A temporal graph.

Methods:

add_constant_properties(properties)

Adds static properties to the graph.

add_edge(timestamp, src, dst[, properties, ...])

Adds a new edge with the given source and destination nodes and properties to the graph.

add_node(timestamp, id[, properties, node_type])

Adds a new node with the given id and properties to the graph.

add_property(timestamp, properties)

Adds properties to the graph.

after(start)

Create a view of the GraphView including all events after start (exclusive).

at(time)

Create a view of the GraphView including all events at time.

before(end)

Create a view of the GraphView including all events before end (exclusive).

bincode()

Get bincode encoded graph

count_edges()

Number of edges in the graph

count_nodes()

Number of nodes in the graph

count_temporal_edges()

Number of edges in the graph

default_layer()

Return a view of GraphView containing only the default edge layer :returns: The layered view :rtype: GraphView

edge(src, dst)

Gets the edge with the specified source and destination nodes

exclude_layer(name)

Return a view of GraphView containing all layers except the excluded name Errors if any of the layers do not exist.

exclude_layers(names)

Return a view of GraphView containing all layers except the excluded names Errors if any of the layers do not exist.

exclude_nodes(nodes)

Returns a subgraph given a set of nodes that are excluded from the subgraph

exclude_valid_layer(name)

Return a view of GraphView containing all layers except the excluded name :param name: layer name that is excluded for the new view :type name: str

exclude_valid_layers(names)

Return a view of GraphView containing all layers except the excluded names :param names: list of layer names that are excluded for the new view :type names: list[str]

expanding(step)

Creates a WindowSet with the given step size using an expanding window.

get_all_node_types()

Returns all the node types in the graph.

has_edge(src, dst)

Returns true if the graph contains the specified edge

has_layer(name)

Check if GraphView has the layer "name"

has_node(id)

Returns true if the graph contains the specified node

import_edge(edge[, force])

Import a single edge into the graph.

import_edges(edges[, force])

Import multiple edges into the graph.

import_node(node[, force])

Import a single node into the graph.

import_nodes(nodes[, force])

Import multiple nodes into the graph.

index()

Indexes all node and edge properties.

largest_connected_component()

Gives the large connected component of a graph.

layer(name)

Return a view of GraphView containing the layer "name" Errors if the layer does not exist

layers(names)

Return a view of GraphView containing all layers names Errors if any of the layers do not exist.

load_edge_props_from_pandas(df, src, dst[, ...])

Load edge properties from a Pandas DataFrame.

load_edges_from_pandas(df, src, dst, time[, ...])

Load edges from a Pandas DataFrame into the graph.

load_from_file(path[, force])

Loads a graph from the given path.

load_from_pandas(edge_df, edge_src, ...[, ...])

Load a graph from a Pandas DataFrame.

load_node_props_from_pandas(df, id[, ...])

Load node properties from a Pandas DataFrame.

load_nodes_from_pandas(df, id, time[, ...])

Load nodes from a Pandas DataFrame into the graph.

materialize()

Returns a 'materialized' clone of the graph view - i.e. a new graph with a copy of the data seen within the view instead of just a mask over the original graph.

node(id)

Gets the node with the specified id

persistent_graph()

Get persistent graph

rolling(window[, step])

Creates a WindowSet with the given window size and optional step using a rolling window.

save_to_file(path)

Saves the graph to the given path.

shrink_end(end)

Set the end of the window to the smaller of end and self.end()

shrink_start(start)

Set the start of the window to the larger of start and self.start()

shrink_window(start, end)

Shrink both the start and end of the window (same as calling shrink_start followed by shrink_end but more efficient)

subgraph(nodes)

Returns a subgraph given a set of nodes

subgraph_node_types(node_types)

Returns a subgraph filtered by node types given a set of node types

to_networkx([explode_edges, ...])

Returns a graph with NetworkX.

to_pyvis([explode_edges, edge_color, shape, ...])

Draw a graph with PyVis.

update_constant_properties(properties)

Updates static properties to the graph.

valid_layers(names)

Return a view of GraphView containing all layers names Any layers that do not exist are ignored

vectorise(embedding[, cache, ...])

Create a VectorisedGraph from the current graph

window(start, end)

Create a view of the GraphView including all events between start (inclusive) and end (exclusive)

Attributes:

earliest_date_time

DateTime of earliest activity in the graph

earliest_time

Timestamp of earliest activity in the graph

edges

Gets all edges in the graph

end

Gets the latest time that this GraphView is valid.

end_date_time

Gets the latest datetime that this GraphView is valid

latest_date_time

DateTime of latest activity in the graph

latest_time

Timestamp of latest activity in the graph

nodes

Gets the nodes in the graph

properties

Get all graph properties

start

Gets the start time for rolling and expanding windows for this GraphView

start_date_time

Gets the earliest datetime that this GraphView is valid

unique_layers

Return all the layer ids in the graph

window_size

Get the window size (difference between start and end) for this GraphView

add_constant_properties(properties)#

Adds static properties to the graph.

Parameters:

properties (dict) – The static properties of the graph.

Returns:

None

add_edge(timestamp, src, dst, properties=None, layer=None)#

Adds a new edge with the given source and destination nodes and properties to the graph.

Parameters:
  • timestamp (int, str, or datetime(utc)) – The timestamp of the edge.

  • src (str or int) – The id of the source node.

  • dst (str or int) – The id of the destination node.

  • properties (dict) – The properties of the edge, as a dict of string and properties (optional).

  • layer (str) – The layer of the edge (optional).

Returns:

None

add_node(timestamp, id, properties=None, node_type=None)#

Adds a new node with the given id and properties to the graph.

Parameters:
  • timestamp (int, str, or datetime(utc)) – The timestamp of the node.

  • id (str or int) – The id of the node.

  • properties (dict) – The properties of the node (optional).

  • node_type (str) – The optional string which will be used as a node type

Returns:

None

add_property(timestamp, properties)#

Adds properties to the graph.

Parameters:
  • timestamp (int, str, or datetime(utc)) – The timestamp of the temporal property.

  • properties (dict) – The temporal properties of the graph.

Returns:

None

after(start)#

Create a view of the GraphView including all events after start (exclusive).

Parameters:

start (int | DateTime | str) – The start time of the window.

Returns:

A GraphView object.

at(time)#

Create a view of the GraphView including all events at time.

Parameters:

time (int | DateTime | str) – The time of the window.

Returns:

A GraphView object.

before(end)#

Create a view of the GraphView including all events before end (exclusive).

Parameters:

end (int | DateTime | str) – The end time of the window.

Returns:

A GraphView object.

bincode()#

Get bincode encoded graph

count_edges()#

Number of edges in the graph

Returns:

the number of edges in the graph

count_nodes()#

Number of nodes in the graph

Returns:

the number of nodes in the graph

count_temporal_edges()#

Number of edges in the graph

Returns:

the number of temporal edges in the graph

default_layer()#

Return a view of GraphView containing only the default edge layer :returns: The layered view :rtype: GraphView

earliest_date_time#

DateTime of earliest activity in the graph

Returns:

the datetime of the earliest activity in the graph

earliest_time#

Timestamp of earliest activity in the graph

Returns:

the timestamp of the earliest activity in the graph

edge(src, dst)#

Gets the edge with the specified source and destination nodes

Parameters:
  • src (str or int) – the source node id

  • dst (str or int) – the destination node id

Returns:

the edge with the specified source and destination nodes, or None if the edge does not exist

edges#

Gets all edges in the graph

Returns:

the edges in the graph

end#

Gets the latest time that this GraphView is valid.

Returns:

The latest time that this GraphView is valid or None if the GraphView is valid for all times.

end_date_time#

Gets the latest datetime that this GraphView is valid

Returns:

The latest datetime that this GraphView is valid or None if the GraphView is valid for all times.

exclude_layer(name)#

Return a view of GraphView containing all layers except the excluded name Errors if any of the layers do not exist.

Parameters:

name (str) – layer name that is excluded for the new view

Returns:

The layered view

Return type:

GraphView

exclude_layers(names)#

Return a view of GraphView containing all layers except the excluded names Errors if any of the layers do not exist.

Parameters:

names (list[str]) – list of layer names that are excluded for the new view

Returns:

The layered view

Return type:

GraphView

exclude_nodes(nodes)#

Returns a subgraph given a set of nodes that are excluded from the subgraph

Parameters:

nodes (*) – set of nodes

Returns:

GraphView - Returns the subgraph

exclude_valid_layer(name)#

Return a view of GraphView containing all layers except the excluded name :param name: layer name that is excluded for the new view :type name: str

Returns:

The layered view

Return type:

GraphView

exclude_valid_layers(names)#

Return a view of GraphView containing all layers except the excluded names :param names: list of layer names that are excluded for the new view :type names: list[str]

Returns:

The layered view

Return type:

GraphView

expanding(step)#

Creates a WindowSet with the given step size using an expanding window.

An expanding window is a window that grows by step size at each iteration.

Parameters:

step (int | str) – The step size of the window.

Returns:

A WindowSet object.

get_all_node_types()#

Returns all the node types in the graph.

Returns: A list of node types

has_edge(src, dst)#

Returns true if the graph contains the specified edge

Parameters:
  • src (str or int) – the source node id

  • dst (str or int) – the destination node id

Returns:

true if the graph contains the specified edge, false otherwise

has_layer(name)#

Check if GraphView has the layer “name”

has_node(id)#

Returns true if the graph contains the specified node

Parameters:

id (str or int) – the node id

Returns:

true if the graph contains the specified node, false otherwise

import_edge(edge, force=False)#

Import a single edge into the graph.

This function takes a PyEdge object and an optional boolean flag. If the flag is set to true, the function will force the import of the edge even if it already exists in the graph.

Parameters:
  • edge (Edge)

  • force (boolean)

Returns:

Result<EdgeView<Graph, Graph>, GraphError> - A Result object which is Ok if the edge was successfully imported, and Err otherwise.

import_edges(edges, force=False)#

Import multiple edges into the graph.

This function takes a vector of PyEdge objects and an optional boolean flag. If the flag is set to true, the function will force the import of the edges even if they already exist in the graph.

Parameters:
  • edges (List(edges))

  • force (boolean)

Returns:

Result<List(EdgeView<Graph, Graph>), GraphError> - A Result object which is Ok if the edges were successfully imported, and Err otherwise.

import_node(node, force=False)#

Import a single node into the graph.

This function takes a PyNode object and an optional boolean flag. If the flag is set to true, the function will force the import of the node even if it already exists in the graph.

Parameters:
  • node (Node)

  • force (boolean)

Returns:

Result<NodeView<Graph, Graph>, GraphError> - A Result object which is Ok if the node was successfully imported, and Err otherwise.

import_nodes(nodes, force=False)#

Import multiple nodes into the graph.

This function takes a vector of PyNode objects and an optional boolean flag. If the flag is set to true, the function will force the import of the nodes even if they already exist in the graph.

Parameters:
  • nodes (List(Node))

  • force (boolean)

Returns:

Result<List(NodeView<Graph, Graph>), GraphError> - A Result object which is Ok if the nodes were successfully imported, and Err otherwise.

index()#

Indexes all node and edge properties. Returns a GraphIndex which allows the user to search the edges and nodes of the graph via tantivity fuzzy matching queries. Note this is currently immutable and will not update if the graph changes. This is to be improved in a future release.

Returns:

GraphIndex - Returns a GraphIndex

largest_connected_component()#

Gives the large connected component of a graph.

# Example Usage: g.largest_connected_component()

# Returns: A raphtory graph, which essentially is a sub-graph of the graph g

latest_date_time#

DateTime of latest activity in the graph

Returns:

the datetime of the latest activity in the graph

latest_time#

Timestamp of latest activity in the graph

Returns:

the timestamp of the latest activity in the graph

layer(name)#

Return a view of GraphView containing the layer “name” Errors if the layer does not exist

Returns:

The layered view

Return type:

GraphView

layers(names)#

Return a view of GraphView containing all layers names Errors if any of the layers do not exist.

Parameters:

names (list[str]) – list of layer names for the new view

Returns:

The layered view

Return type:

GraphView

load_edge_props_from_pandas(df, src, dst, const_properties=None, shared_const_properties=None, layer=None, layer_in_df=True)#

Load edge properties from a Pandas DataFrame.

Parameters:
  • df (Dataframe) – The Pandas DataFrame containing edge information.

  • src (str) – The column name for the source node.

  • dst (str) – The column name for the destination node.

  • const_properties (List<str>) – List of constant edge property column names. Defaults to None. (optional)

  • shared_const_properties (dict) – A dictionary of constant properties that will be added to every edge. Defaults to None. (optional)

  • layer (str) – Layer name. Defaults to None. (optional)

  • layer_in_df (bool) – Whether the layer name should be used to look up the values in a column of the data frame or if it should be used directly as the layer for all edges (optional) defaults to True.

Returns:

Result of the operation.

Return type:

Result<(), GraphError>

load_edges_from_pandas(df, src, dst, time, properties=None, const_properties=None, shared_const_properties=None, layer=None, layer_in_df=True)#

Load edges from a Pandas DataFrame into the graph.

Parameters:
  • df (Dataframe) – The Pandas DataFrame containing the edges.

  • src (str) – The column name for the source node ids.

  • dst (str) – The column name for the destination node ids.

  • time (str) – The column name for the update timestamps.

  • properties (List<str>) – List of edge property column names. Defaults to None. (optional)

  • const_properties (List<str>) – List of constant edge property column names. Defaults to None. (optional)

  • shared_const_properties (dict) – A dictionary of constant properties that will be added to every edge. Defaults to None. (optional)

  • layer (str) – The edge layer name (optional) Defaults to None.

  • layer_in_df (bool) – Whether the layer name should be used to look up the values in a column of the dateframe or if it should be used directly as the layer for all edges (optional) defaults to True.

Returns:

Result of the operation.

Return type:

Result<(), GraphError>

static load_from_file(path, force=False)#

Loads a graph from the given path.

Parameters:

path (str) – The path to the graph.

Returns:

The loaded graph.

Return type:

Graph

static load_from_pandas(edge_df, edge_src, edge_dst, edge_time, edge_properties=None, edge_const_properties=None, edge_shared_const_properties=None, edge_layer=None, layer_in_df=True, node_df=None, node_id=None, node_time=None, node_properties=None, node_const_properties=None, node_shared_const_properties=None, node_type=None, node_type_in_df=True)#

Load a graph from a Pandas DataFrame.

Parameters:
  • edge_df (pandas.DataFrame) – The DataFrame containing the edges.

  • edge_src (str) – The column name for the source node ids.

  • edge_dst (str) – The column name for the destination node ids.

  • edge_time (str) – The column name for the timestamps.

  • edge_properties (list) – The column names for the temporal properties (optional) Defaults to None.

  • edge_const_properties (list) – The column names for the constant properties (optional) Defaults to None.

  • edge_shared_const_properties (dict) – A dictionary of constant properties that will be added to every edge (optional) Defaults to None.

  • edge_layer (str) – The edge layer name (optional) Defaults to None.

  • layer_in_df (bool) – Whether the layer name should be used to look up the values in a column of the edge_df or if it should be used directly as the layer for all edges (optional) defaults to True.

  • node_df (pandas.DataFrame) – The DataFrame containing the nodes (optional) Defaults to None.

  • node_id (str) – The column name for the node ids (optional) Defaults to None.

  • node_time (str) – The column name for the node timestamps (optional) Defaults to None.

  • node_properties (list) – The column names for the node temporal properties (optional) Defaults to None.

  • node_const_properties (list) – The column names for the node constant properties (optional) Defaults to None.

  • node_shared_const_properties (dict) – A dictionary of constant properties that will be added to every node (optional) Defaults to None.

  • node_type (str) – the column name for the node type

  • node_type_in_df (bool) – whether the node type should be used to look up the values in a column of the df or if it should be used directly as the node type

Returns:

The loaded Graph object.

Return type:

Graph

load_node_props_from_pandas(df, id, const_properties=None, shared_const_properties=None)#

Load node properties from a Pandas DataFrame.

Parameters:
  • df (Dataframe) – The Pandas DataFrame containing node information.

  • id (str) – The column name for the node IDs.

  • const_properties (List<str>) – List of constant node property column names. Defaults to None. (optional)

  • shared_const_properties (<HashMap<String, Prop>>) – A dictionary of constant properties that will be added to every node. Defaults to None. (optional)

Returns:

Result of the operation.

Return type:

Result<(), GraphError>

load_nodes_from_pandas(df, id, time, node_type=None, node_type_in_df=True, properties=None, const_properties=None, shared_const_properties=None)#

Load nodes from a Pandas DataFrame into the graph.

Parameters:
  • df (pandas.DataFrame) – The Pandas DataFrame containing the nodes.

  • id (str) – The column name for the node IDs.

  • time (str) – The column name for the timestamps.

  • node_type (str) – the column name for the node type

  • node_type_in_df (bool) – whether the node type should be used to look up the values in a column of the df or if it should be used directly as the node type

  • properties (List<str>) – List of node property column names. Defaults to None. (optional)

  • const_properties (List<str>) – List of constant node property column names. Defaults to None. (optional)

  • shared_const_properties (Dictionary/Hashmap of properties) – A dictionary of constant properties that will be added to every node. Defaults to None. (optional)

Returns:

Result of the operation.

Return type:

Result<(), GraphError>

materialize()#

Returns a ‘materialized’ clone of the graph view - i.e. a new graph with a copy of the data seen within the view instead of just a mask over the original graph

Returns:

GraphView - Returns a graph clone

node(id)#

Gets the node with the specified id

Parameters:

id (str or int) – the node id

Returns:

the node with the specified id, or None if the node does not exist

nodes#

Gets the nodes in the graph

Returns:

the nodes in the graph

persistent_graph()#

Get persistent graph

properties#

Get all graph properties

Returns:

HashMap<String, Prop> - Properties paired with their names

rolling(window, step=None)#

Creates a WindowSet with the given window size and optional step using a rolling window.

A rolling window is a window that moves forward by step size at each iteration.

Parameters:
  • window (int | str) – The size of the window.

  • step (int | str | None) – The step size of the window. Defaults to window.

Returns:

A WindowSet object.

save_to_file(path)#

Saves the graph to the given path.

Parameters:

path (str) – The path to the graph.

Returns: None

shrink_end(end)#

Set the end of the window to the smaller of end and self.end()

Parameters:

end (int | DateTime | str) – the new end time of the window

Returns:

A GraphView object.

shrink_start(start)#

Set the start of the window to the larger of start and self.start()

Parameters:

start (int | DateTime | str) – the new start time of the window

Returns:

A GraphView object.

shrink_window(start, end)#

Shrink both the start and end of the window (same as calling shrink_start followed by shrink_end but more efficient)

Arguments:

start#

Gets the start time for rolling and expanding windows for this GraphView

Returns:

The earliest time that this GraphView is valid or None if the GraphView is valid for all times.

start_date_time#

Gets the earliest datetime that this GraphView is valid

Returns:

The earliest datetime that this GraphView is valid or None if the GraphView is valid for all times.

subgraph(nodes)#

Returns a subgraph given a set of nodes

Parameters:

nodes (*) – set of nodes

Returns:

GraphView - Returns the subgraph

subgraph_node_types(node_types)#

Returns a subgraph filtered by node types given a set of node types

Parameters:

node_types (*) – set of node types

Returns:

GraphView - Returns the subgraph

to_networkx(explode_edges=False, include_node_properties=True, include_edge_properties=True, include_update_history=True, include_property_history=True)#

Returns a graph with NetworkX.

Network X is a required dependency. If you intend to use this function make sure that you install Network X with pip install networkx

Parameters:
  • explode_edges (bool) – A boolean that is set to True if you want to explode the edges in the graph. By default this is set to False.

  • include_node_properties (bool) – A boolean that is set to True if you want to include the node properties in the graph. By default this is set to True.

  • include_edge_properties (bool) – A boolean that is set to True if you want to include the edge properties in the graph. By default this is set to True.

  • include_update_history (bool) – A boolean that is set to True if you want to include the update histories in the graph. By default this is set to True.

  • include_property_history (bool) – A boolean that is set to True if you want to include the histories in the graph. By default this is set to True.

Returns:

A Networkx MultiDiGraph.

to_pyvis(explode_edges=False, edge_color='#000000', shape=None, node_image=None, edge_weight=None, edge_label=None, colour_nodes_by_type=False, notebook=False, **kwargs)#

Draw a graph with PyVis. Pyvis is a required dependency. If you intend to use this function make sure that you install Pyvis with pip install pyvis

Args:

graph (graph): A Raphtory graph. explode_edges (bool): A boolean that is set to True if you want to explode the edges in the graph. By default this is set to False. edge_color (str): A string defining the colour of the edges in the graph. By default #000000 (black) is set. shape (str): An optional string defining what the node looks like.

There are two types of nodes. One type has the label inside of it and the other type has the label underneath it. The types with the label inside of it are: ellipse, circle, database, box, text. The ones with the label outside of it are: image, circularImage, diamond, dot, star, triangle, triangleDown, square and icon. By default "dot" is set.

node_image (str): An optional string defining the url of a custom node image. By default an image of a circle is set. edge_weight (str): An optional string defining the name of the property where edge weight is set on your Raphtory graph. By default 1 is set. edge_label (str): An optional string defining the name of the property where edge label is set on your Raphtory graph. By default, an empty string as the label is set. notebook (bool): A boolean that is set to True if using jupyter notebook. By default this is set to True. kwargs: Additional keyword arguments that are passed to the pyvis Network class.

Returns:

A pyvis network

unique_layers#

Return all the layer ids in the graph

update_constant_properties(properties)#

Updates static properties to the graph.

Parameters:

properties (dict) – The static properties of the graph.

Returns:

None

valid_layers(names)#

Return a view of GraphView containing all layers names Any layers that do not exist are ignored

Parameters:

names (list[str]) – list of layer names for the new view

Returns:

The layered view

Return type:

GraphView

vectorise(embedding, cache=None, overwrite_cache=False, graph_document=None, node_document=None, edge_document=None, verbose=False)#

Create a VectorisedGraph from the current graph

Parameters:
  • embedding (Callable[[list], list]) – the embedding function to translate documents to embeddings

  • cache (str) – the file to be used as a cache to avoid calling the embedding function (optional)

  • overwrite_cache (bool) – whether or not to overwrite the cache if there are new embeddings (optional)

  • node_document (str) – the property name to be used as document for nodes (optional)

  • edge_document (str) – the property name to be used as document for edges (optional)

  • verbose (bool) – whether or not to print logs reporting the progress

Returns:

A VectorisedGraph with all the documents/embeddings computed and with an initial empty selection

window(start, end)#

Create a view of the GraphView including all events between start (inclusive) and end (exclusive)

Parameters:
  • start (int | DateTime | str | None) – The start time of the window (unbounded if None).

  • end (int | DateTime | str | None) – The end time of the window (unbounded if None).

Returns: r A GraphView object.

window_size#

Get the window size (difference between start and end) for this GraphView

class raphtory.PersistentGraph#

Bases: GraphView

A temporal graph that allows edges and nodes to be deleted.

Methods:

add_constant_properties(properties)

Adds static properties to the graph.

add_edge(timestamp, src, dst[, properties, ...])

Adds a new edge with the given source and destination nodes and properties to the graph.

add_node(timestamp, id[, properties, node_type])

Adds a new node with the given id and properties to the graph.

add_property(timestamp, properties)

Adds properties to the graph.

after(start)

Create a view of the GraphView including all events after start (exclusive).

at(time)

Create a view of the GraphView including all events at time.

before(end)

Create a view of the GraphView including all events before end (exclusive).

bincode()

Get bincode encoded graph

count_edges()

Number of edges in the graph

count_nodes()

Number of nodes in the graph

count_temporal_edges()

Number of edges in the graph

default_layer()

Return a view of GraphView containing only the default edge layer :returns: The layered view :rtype: GraphView

delete_edge(timestamp, src, dst[, layer])

Deletes an edge given the timestamp, src and dst nodes and layer (optional)

edge(src, dst)

Gets the edge with the specified source and destination nodes

event_graph()

Get event graph

exclude_layer(name)

Return a view of GraphView containing all layers except the excluded name Errors if any of the layers do not exist.

exclude_layers(names)

Return a view of GraphView containing all layers except the excluded names Errors if any of the layers do not exist.

exclude_nodes(nodes)

Returns a subgraph given a set of nodes that are excluded from the subgraph

exclude_valid_layer(name)

Return a view of GraphView containing all layers except the excluded name :param name: layer name that is excluded for the new view :type name: str

exclude_valid_layers(names)

Return a view of GraphView containing all layers except the excluded names :param names: list of layer names that are excluded for the new view :type names: list[str]

expanding(step)

Creates a WindowSet with the given step size using an expanding window.

get_all_node_types()

Returns all the node types in the graph.

has_edge(src, dst)

Returns true if the graph contains the specified edge

has_layer(name)

Check if GraphView has the layer "name"

has_node(id)

Returns true if the graph contains the specified node

import_edge(edge[, force])

Import a single edge into the graph.

import_edges(edges[, force])

Import multiple edges into the graph.

import_node(node[, force])

Import a single node into the graph.

import_nodes(nodes[, force])

Import multiple nodes into the graph.

index()

Indexes all node and edge properties.

layer(name)

Return a view of GraphView containing the layer "name" Errors if the layer does not exist

layers(names)

Return a view of GraphView containing all layers names Errors if any of the layers do not exist.

load_edge_props_from_pandas(df, src, dst[, ...])

Load edge properties from a Pandas DataFrame.

load_edges_deletions_from_pandas(df, src, ...)

Load edges deletions from a Pandas DataFrame into the graph.

load_edges_from_pandas(df, src, dst, time[, ...])

Load edges from a Pandas DataFrame into the graph.

load_from_file(path[, force])

Loads a graph from the given path.

load_from_pandas(edge_df, edge_src, ...[, ...])

Load a graph from a Pandas DataFrame.

load_node_props_from_pandas(df, id[, ...])

Load node properties from a Pandas DataFrame.

load_nodes_from_pandas(df, id, time[, ...])

Load nodes from a Pandas DataFrame into the graph.

materialize()

Returns a 'materialized' clone of the graph view - i.e. a new graph with a copy of the data seen within the view instead of just a mask over the original graph.

node(id)

Gets the node with the specified id

rolling(window[, step])

Creates a WindowSet with the given window size and optional step using a rolling window.

save_to_file(path)

Saves the graph to the given path.

shrink_end(end)

Set the end of the window to the smaller of end and self.end()

shrink_start(start)

Set the start of the window to the larger of start and self.start()

shrink_window(start, end)

Shrink both the start and end of the window (same as calling shrink_start followed by shrink_end but more efficient)

subgraph(nodes)

Returns a subgraph given a set of nodes

subgraph_node_types(node_types)

Returns a subgraph filtered by node types given a set of node types

to_networkx([explode_edges, ...])

Returns a graph with NetworkX.

to_pyvis([explode_edges, edge_color, shape, ...])

Draw a graph with PyVis.

update_constant_properties(properties)

Updates static properties to the graph.

valid_layers(names)

Return a view of GraphView containing all layers names Any layers that do not exist are ignored

vectorise(embedding[, cache, ...])

Create a VectorisedGraph from the current graph

window(start, end)

Create a view of the GraphView including all events between start (inclusive) and end (exclusive)

Attributes:

earliest_date_time

DateTime of earliest activity in the graph

earliest_time

Timestamp of earliest activity in the graph

edges

Gets all edges in the graph

end

Gets the latest time that this GraphView is valid.

end_date_time

Gets the latest datetime that this GraphView is valid

latest_date_time

DateTime of latest activity in the graph

latest_time

Timestamp of latest activity in the graph

nodes

Gets the nodes in the graph

properties

Get all graph properties

start

Gets the start time for rolling and expanding windows for this GraphView

start_date_time

Gets the earliest datetime that this GraphView is valid

unique_layers

Return all the layer ids in the graph

window_size

Get the window size (difference between start and end) for this GraphView

add_constant_properties(properties)#

Adds static properties to the graph.

Parameters:

properties (dict) – The static properties of the graph.

Returns:

None

add_edge(timestamp, src, dst, properties=None, layer=None)#

Adds a new edge with the given source and destination nodes and properties to the graph.

Parameters:
  • timestamp (int) – The timestamp of the edge.

  • src (str or int) – The id of the source node.

  • dst (str or int) – The id of the destination node.

  • properties (dict) – The properties of the edge, as a dict of string and properties

  • layer (str) – The layer of the edge.

Returns:

None

add_node(timestamp, id, properties=None, node_type=None)#

Adds a new node with the given id and properties to the graph.

Parameters:
  • timestamp (int, str, or datetime(utc)) – The timestamp of the node.

  • id (str or int) – The id of the node.

  • properties (dict) – The properties of the node.

  • node_type (str) – The optional string which will be used as a node type

Returns:

None

add_property(timestamp, properties)#

Adds properties to the graph.

Parameters:
  • timestamp (int, str, or datetime(utc)) – The timestamp of the temporal property.

  • properties (dict) – The temporal properties of the graph.

Returns:

None

after(start)#

Create a view of the GraphView including all events after start (exclusive).

Parameters:

start (int | DateTime | str) – The start time of the window.

Returns:

A GraphView object.

at(time)#

Create a view of the GraphView including all events at time.

Parameters:

time (int | DateTime | str) – The time of the window.

Returns:

A GraphView object.

before(end)#

Create a view of the GraphView including all events before end (exclusive).

Parameters:

end (int | DateTime | str) – The end time of the window.

Returns:

A GraphView object.

bincode()#

Get bincode encoded graph

count_edges()#

Number of edges in the graph

Returns:

the number of edges in the graph

count_nodes()#

Number of nodes in the graph

Returns:

the number of nodes in the graph

count_temporal_edges()#

Number of edges in the graph

Returns:

the number of temporal edges in the graph

default_layer()#

Return a view of GraphView containing only the default edge layer :returns: The layered view :rtype: GraphView

delete_edge(timestamp, src, dst, layer=None)#

Deletes an edge given the timestamp, src and dst nodes and layer (optional)

Parameters:
  • timestamp (int) – The timestamp of the edge.

  • src (str or int) – The id of the source node.

  • dst (str or int) – The id of the destination node.

  • layer (str) – The layer of the edge. (optional)

Returns:

None or a GraphError if the edge could not be deleted

earliest_date_time#

DateTime of earliest activity in the graph

Returns:

the datetime of the earliest activity in the graph

earliest_time#

Timestamp of earliest activity in the graph

Returns:

the timestamp of the earliest activity in the graph

edge(src, dst)#

Gets the edge with the specified source and destination nodes

Parameters:
  • src (str or int) – the source node id

  • dst (str or int) – the destination node id

Returns:

the edge with the specified source and destination nodes, or None if the edge does not exist

edges#

Gets all edges in the graph

Returns:

the edges in the graph

end#

Gets the latest time that this GraphView is valid.

Returns:

The latest time that this GraphView is valid or None if the GraphView is valid for all times.

end_date_time#

Gets the latest datetime that this GraphView is valid

Returns:

The latest datetime that this GraphView is valid or None if the GraphView is valid for all times.

event_graph()#

Get event graph

exclude_layer(name)#

Return a view of GraphView containing all layers except the excluded name Errors if any of the layers do not exist.

Parameters:

name (str) – layer name that is excluded for the new view

Returns:

The layered view

Return type:

GraphView

exclude_layers(names)#

Return a view of GraphView containing all layers except the excluded names Errors if any of the layers do not exist.

Parameters:

names (list[str]) – list of layer names that are excluded for the new view

Returns:

The layered view

Return type:

GraphView

exclude_nodes(nodes)#

Returns a subgraph given a set of nodes that are excluded from the subgraph

Parameters:

nodes (*) – set of nodes

Returns:

GraphView - Returns the subgraph

exclude_valid_layer(name)#

Return a view of GraphView containing all layers except the excluded name :param name: layer name that is excluded for the new view :type name: str

Returns:

The layered view

Return type:

GraphView

exclude_valid_layers(names)#

Return a view of GraphView containing all layers except the excluded names :param names: list of layer names that are excluded for the new view :type names: list[str]

Returns:

The layered view

Return type:

GraphView

expanding(step)#

Creates a WindowSet with the given step size using an expanding window.

An expanding window is a window that grows by step size at each iteration.

Parameters:

step (int | str) – The step size of the window.

Returns:

A WindowSet object.

get_all_node_types()#

Returns all the node types in the graph.

Returns: A list of node types

has_edge(src, dst)#

Returns true if the graph contains the specified edge

Parameters:
  • src (str or int) – the source node id

  • dst (str or int) – the destination node id

Returns:

true if the graph contains the specified edge, false otherwise

has_layer(name)#

Check if GraphView has the layer “name”

has_node(id)#

Returns true if the graph contains the specified node

Parameters:

id (str or int) – the node id

Returns:

true if the graph contains the specified node, false otherwise

import_edge(edge, force=False)#

Import a single edge into the graph.

This function takes a PyEdge object and an optional boolean flag. If the flag is set to true, the function will force the import of the edge even if it already exists in the graph.

Parameters:
  • edge (Edge)

  • force (boolean)

Returns:

Result<EdgeView<Graph, Graph>, GraphError> - A Result object which is Ok if the edge was successfully imported, and Err otherwise.

import_edges(edges, force=False)#

Import multiple edges into the graph.

This function takes a vector of PyEdge objects and an optional boolean flag. If the flag is set to true, the function will force the import of the edges even if they already exist in the graph.

Parameters:
  • edges (List(edges))

  • force (boolean)

Returns:

Result<List(EdgeView<Graph, Graph>), GraphError> - A Result object which is Ok if the edges were successfully imported, and Err otherwise.

import_node(node, force=False)#

Import a single node into the graph.

This function takes a PyNode object and an optional boolean flag. If the flag is set to true, the function will force the import of the node even if it already exists in the graph.

Parameters:
  • node (Node)

  • force (boolean)

Returns:

Result<NodeView<Graph, Graph>, GraphError> - A Result object which is Ok if the node was successfully imported, and Err otherwise.

import_nodes(nodes, force=False)#

Import multiple nodes into the graph.

This function takes a vector of PyNode objects and an optional boolean flag. If the flag is set to true, the function will force the import of the nodes even if they already exist in the graph.

Parameters:
  • nodes (List(Node))

  • force (boolean)

Returns:

Result<List(NodeView<Graph, Graph>), GraphError> - A Result object which is Ok if the nodes were successfully imported, and Err otherwise.

index()#

Indexes all node and edge properties. Returns a GraphIndex which allows the user to search the edges and nodes of the graph via tantivity fuzzy matching queries. Note this is currently immutable and will not update if the graph changes. This is to be improved in a future release.

Returns:

GraphIndex - Returns a GraphIndex

latest_date_time#

DateTime of latest activity in the graph

Returns:

the datetime of the latest activity in the graph

latest_time#

Timestamp of latest activity in the graph

Returns:

the timestamp of the latest activity in the graph

layer(name)#

Return a view of GraphView containing the layer “name” Errors if the layer does not exist

Returns:

The layered view

Return type:

GraphView

layers(names)#

Return a view of GraphView containing all layers names Errors if any of the layers do not exist.

Parameters:

names (list[str]) – list of layer names for the new view

Returns:

The layered view

Return type:

GraphView

load_edge_props_from_pandas(df, src, dst, const_properties=None, shared_const_properties=None, layer=None, layer_in_df=True)#

Load edge properties from a Pandas DataFrame.

Parameters:
  • df (Dataframe) – The Pandas DataFrame containing edge information.

  • src (str) – The column name for the source node.

  • dst (str) – The column name for the destination node.

  • const_properties (List<str>) – List of constant edge property column names. Defaults to None. (optional)

  • shared_const_properties (dict) – A dictionary of constant properties that will be added to every edge. Defaults to None. (optional)

  • layer (str) – Layer name. Defaults to None. (optional)

  • layer_in_df (bool) – Whether the layer name should be used to look up the values in a column of the data frame or if it should be used directly as the layer for all edges (optional) defaults to True.

Returns:

Result of the operation.

Return type:

Result<(), GraphError>

load_edges_deletions_from_pandas(df, src, dst, time, layer=None, layer_in_df=True)#

Load edges deletions from a Pandas DataFrame into the graph.

Parameters:
  • df (Dataframe) – The Pandas DataFrame containing the edges.

  • src (str) – The column name for the source node ids.

  • dst (str) – The column name for the destination node ids.

  • time (str) – The column name for the update timestamps.

  • layer (str) – The edge layer name (optional) Defaults to None.

  • layer_in_df (bool) – Whether the layer name should be used to look up the values in a column of the dateframe or if it should be used directly as the layer for all edges (optional) defaults to True.

Returns:

Result of the operation.

Return type:

Result<(), GraphError>

load_edges_from_pandas(df, src, dst, time, properties=None, const_properties=None, shared_const_properties=None, layer=None, layer_in_df=True)#

Load edges from a Pandas DataFrame into the graph.

Parameters:
  • df (Dataframe) – The Pandas DataFrame containing the edges.

  • src (str) – The column name for the source node ids.

  • dst (str) – The column name for the destination node ids.

  • time (str) – The column name for the update timestamps.

  • properties (List<str>) – List of edge property column names. Defaults to None. (optional)

  • const_properties (List<str>) – List of constant edge property column names. Defaults to None. (optional)

  • shared_const_properties (dict) – A dictionary of constant properties that will be added to every edge. Defaults to None. (optional)

  • layer (str) – The edge layer name (optional) Defaults to None.

  • layer_in_df (bool) – Whether the layer name should be used to look up the values in a column of the dateframe or if it should be used directly as the layer for all edges (optional) defaults to True.

Returns:

Result of the operation.

Return type:

Result<(), GraphError>

static load_from_file(path, force=False)#

Loads a graph from the given path.

Parameters:

path (str) – The path to the graph.

Returns:

The loaded graph.

Return type:

Graph

static load_from_pandas(edge_df, edge_src, edge_dst, edge_time, edge_properties=None, edge_const_properties=None, edge_shared_const_properties=None, edge_layer=None, layer_in_df=True, node_df=None, node_id=None, node_time=None, node_properties=None, node_const_properties=None, node_shared_const_properties=None, node_type=None, node_type_in_df=True)#

Load a graph from a Pandas DataFrame.

Parameters:
  • edge_df (pandas.DataFrame) – The DataFrame containing the edges.

  • edge_src (str) – The column name for the source node ids.

  • edge_dst (str) – The column name for the destination node ids.

  • edge_time (str) – The column name for the timestamps.

  • edge_properties (list) – The column names for the temporal properties (optional) Defaults to None.

  • edge_const_properties (list) – The column names for the constant properties (optional) Defaults to None.

  • edge_shared_const_properties (dict) – A dictionary of constant properties that will be added to every edge (optional) Defaults to None.

  • edge_layer (str) – The edge layer name (optional) Defaults to None.

  • layer_in_df (bool) – Whether the layer name should be used to look up the values in a column of the edge_df or if it should be used directly as the layer for all edges (optional) defaults to True.

  • node_df (pandas.DataFrame) – The DataFrame containing the nodes (optional) Defaults to None.

  • node_id (str) – The column name for the node ids (optional) Defaults to None.

  • node_time (str) – The column name for the node timestamps (optional) Defaults to None.

  • node_properties (list) – The column names for the node temporal properties (optional) Defaults to None.

  • node_const_properties (list) – The column names for the node constant properties (optional) Defaults to None.

  • node_shared_const_properties (dict) – A dictionary of constant properties that will be added to every node (optional) Defaults to None.

  • node_type (str) – the column name for the node type

  • node_type_in_df (bool) – whether the node type should be used to look up the values in a column of the df or if it should be used directly as the node type

Returns:

The loaded Graph object.

Return type:

Graph

load_node_props_from_pandas(df, id, const_properties=None, shared_const_properties=None)#

Load node properties from a Pandas DataFrame.

Parameters:
  • df (Dataframe) – The Pandas DataFrame containing node information.

  • id (str) – The column name for the node IDs.

  • const_properties (List<str>) – List of constant node property column names. Defaults to None. (optional)

  • shared_const_properties (<HashMap<String, Prop>>) – A dictionary of constant properties that will be added to every node. Defaults to None. (optional)

Returns:

Result of the operation.

Return type:

Result<(), GraphError>

load_nodes_from_pandas(df, id, time, node_type=None, node_type_in_df=True, properties=None, const_properties=None, shared_const_properties=None)#

Load nodes from a Pandas DataFrame into the graph.

Parameters:
  • df (pandas.DataFrame) – The Pandas DataFrame containing the nodes.

  • id (str) – The column name for the node IDs.

  • time (str) – The column name for the timestamps.

  • node_type (str) – the column name for the node type

  • node_type_in_df (bool) – whether the node type should be used to look up the values in a column of the df or if it should be used directly as the node type

  • properties (List<str>) – List of node property column names. Defaults to None. (optional)

  • const_properties (List<str>) – List of constant node property column names. Defaults to None. (optional)

  • shared_const_properties (Dictionary/Hashmap of properties) – A dictionary of constant properties that will be added to every node. Defaults to None. (optional)

Returns:

Result of the operation.

Return type:

Result<(), GraphError>

materialize()#

Returns a ‘materialized’ clone of the graph view - i.e. a new graph with a copy of the data seen within the view instead of just a mask over the original graph

Returns:

GraphView - Returns a graph clone

node(id)#

Gets the node with the specified id

Parameters:

id (str or int) – the node id

Returns:

the node with the specified id, or None if the node does not exist

nodes#

Gets the nodes in the graph

Returns:

the nodes in the graph

properties#

Get all graph properties

Returns:

HashMap<String, Prop> - Properties paired with their names

rolling(window, step=None)#

Creates a WindowSet with the given window size and optional step using a rolling window.

A rolling window is a window that moves forward by step size at each iteration.

Parameters:
  • window (int | str) – The size of the window.

  • step (int | str | None) – The step size of the window. Defaults to window.

Returns:

A WindowSet object.

save_to_file(path)#

Saves the graph to the given path.

Parameters:

path (str) – The path to the graph.

Returns: None

shrink_end(end)#

Set the end of the window to the smaller of end and self.end()

Parameters:

end (int | DateTime | str) – the new end time of the window

Returns:

A GraphView object.

shrink_start(start)#

Set the start of the window to the larger of start and self.start()

Parameters:

start (int | DateTime | str) – the new start time of the window

Returns:

A GraphView object.

shrink_window(start, end)#

Shrink both the start and end of the window (same as calling shrink_start followed by shrink_end but more efficient)

Arguments:

start#

Gets the start time for rolling and expanding windows for this GraphView

Returns:

The earliest time that this GraphView is valid or None if the GraphView is valid for all times.

start_date_time#

Gets the earliest datetime that this GraphView is valid

Returns:

The earliest datetime that this GraphView is valid or None if the GraphView is valid for all times.

subgraph(nodes)#

Returns a subgraph given a set of nodes

Parameters:

nodes (*) – set of nodes

Returns:

GraphView - Returns the subgraph

subgraph_node_types(node_types)#

Returns a subgraph filtered by node types given a set of node types

Parameters:

node_types (*) – set of node types

Returns:

GraphView - Returns the subgraph

to_networkx(explode_edges=False, include_node_properties=True, include_edge_properties=True, include_update_history=True, include_property_history=True)#

Returns a graph with NetworkX.

Network X is a required dependency. If you intend to use this function make sure that you install Network X with pip install networkx

Parameters:
  • explode_edges (bool) – A boolean that is set to True if you want to explode the edges in the graph. By default this is set to False.

  • include_node_properties (bool) – A boolean that is set to True if you want to include the node properties in the graph. By default this is set to True.

  • include_edge_properties (bool) – A boolean that is set to True if you want to include the edge properties in the graph. By default this is set to True.

  • include_update_history (bool) – A boolean that is set to True if you want to include the update histories in the graph. By default this is set to True.

  • include_property_history (bool) – A boolean that is set to True if you want to include the histories in the graph. By default this is set to True.

Returns:

A Networkx MultiDiGraph.

to_pyvis(explode_edges=False, edge_color='#000000', shape=None, node_image=None, edge_weight=None, edge_label=None, colour_nodes_by_type=False, notebook=False, **kwargs)#

Draw a graph with PyVis. Pyvis is a required dependency. If you intend to use this function make sure that you install Pyvis with pip install pyvis

Args:

graph (graph): A Raphtory graph. explode_edges (bool): A boolean that is set to True if you want to explode the edges in the graph. By default this is set to False. edge_color (str): A string defining the colour of the edges in the graph. By default #000000 (black) is set. shape (str): An optional string defining what the node looks like.

There are two types of nodes. One type has the label inside of it and the other type has the label underneath it. The types with the label inside of it are: ellipse, circle, database, box, text. The ones with the label outside of it are: image, circularImage, diamond, dot, star, triangle, triangleDown, square and icon. By default "dot" is set.

node_image (str): An optional string defining the url of a custom node image. By default an image of a circle is set. edge_weight (str): An optional string defining the name of the property where edge weight is set on your Raphtory graph. By default 1 is set. edge_label (str): An optional string defining the name of the property where edge label is set on your Raphtory graph. By default, an empty string as the label is set. notebook (bool): A boolean that is set to True if using jupyter notebook. By default this is set to True. kwargs: Additional keyword arguments that are passed to the pyvis Network class.

Returns:

A pyvis network

unique_layers#

Return all the layer ids in the graph

update_constant_properties(properties)#

Updates static properties to the graph.

Parameters:

properties (dict) – The static properties of the graph.

Returns:

None

valid_layers(names)#

Return a view of GraphView containing all layers names Any layers that do not exist are ignored

Parameters:

names (list[str]) – list of layer names for the new view

Returns:

The layered view

Return type:

GraphView

vectorise(embedding, cache=None, overwrite_cache=False, graph_document=None, node_document=None, edge_document=None, verbose=False)#

Create a VectorisedGraph from the current graph

Parameters:
  • embedding (Callable[[list], list]) – the embedding function to translate documents to embeddings

  • cache (str) – the file to be used as a cache to avoid calling the embedding function (optional)

  • overwrite_cache (bool) – whether or not to overwrite the cache if there are new embeddings (optional)

  • node_document (str) – the property name to be used as document for nodes (optional)

  • edge_document (str) – the property name to be used as document for edges (optional)

  • verbose (bool) – whether or not to print logs reporting the progress

Returns:

A VectorisedGraph with all the documents/embeddings computed and with an initial empty selection

window(start, end)#

Create a view of the GraphView including all events between start (inclusive) and end (exclusive)

Parameters:
  • start (int | DateTime | str | None) – The start time of the window (unbounded if None).

  • end (int | DateTime | str | None) – The end time of the window (unbounded if None).

Returns: r A GraphView object.

window_size#

Get the window size (difference between start and end) for this GraphView