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 vertices and properties to the graph.

add_property(timestamp, properties)

Adds properties to the graph.

add_vertex(timestamp, id[, properties])

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

after(start)

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

at(time)

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

before(end)

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

bincode()

Get bincode encoded graph

count_edges()

Number of edges in the graph

count_temporal_edges()

Number of edges in the graph

count_vertices()

Number of vertices in the graph

default_layer()

Create a view including all the edges in the default layer

edge(src, dst)

Gets the edge with the specified source and destination vertices

expanding(step)

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

has_edge(src, dst[, layer])

Returns true if the graph contains the specified edge

has_vertex(id)

Returns true if the graph contains the specified vertex

index()

Indexes all vertex and edge properties.

layer(name)

Create a view including all the edges in the layers names

layers(names)

Create a view including all the edges in the layers names

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)

Loads a graph from the given path.

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

Load a graph from a Pandas DataFrame.

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

Load vertex properties from a Pandas DataFrame.

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

Load vertices 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.

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.

subgraph(vertices)

Returns a subgraph given a set of vertices

update_constant_properties(properties)

Updates static properties to the graph.

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

vertex(id)

Gets the vertex with the specified id

window([start, end])

Create a view of the graph 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 graph is valid.

end_date_time

Gets the latest datetime that this graph is valid

latest_date_time

DateTime of latest activity in the graph

latest_time

Timestamp of latest activity in the graph

properties

Get all graph properties

start

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

start_date_time

Gets the earliest datetime that this graph is valid

unique_layers

Return all the layer ids in the graph

vertices

Gets the vertices in the graph

window_size

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

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 vertices 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 vertex.

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

  • 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_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

add_vertex(timestamp, id, properties=None)#

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

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

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

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

Returns:

None

after(start)#

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

Parameters:

start – The start time of the window.

Returns:

A graph object.

at(time)#

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

Parameters:

time – The time of the window.

Returns:

A graph object.

before(end)#

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

Parameters:

end – The end time of the window.

Returns:

A graph object.

bincode()#

Get bincode encoded graph

count_edges()#

Number of edges in the graph

Returns:

the number of edges in the graph

count_temporal_edges()#

Number of edges in the graph

Returns:

the number of temporal edges in the graph

count_vertices()#

Number of vertices in the graph

Returns:

the number of vertices in the graph

default_layer()#

Create a view including all the edges in the default layer

Returns:

a view including all the edges in the default layer

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 vertices

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

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

Returns:

the edge with the specified source and destination vertices, 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 graph is valid.

Returns:

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

end_date_time#

Gets the latest datetime that this graph is valid

Returns:

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

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) – The step size of the window.

Returns:

A WindowSet object.

has_edge(src, dst, layer=None)#

Returns true if the graph contains the specified edge

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

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

  • layer (str) – the edge layer (optional)

Returns:

true if the graph contains the specified edge, false otherwise

has_vertex(id)#

Returns true if the graph contains the specified vertex

Parameters:

id (str or int) – the vertex id

Returns:

true if the graph contains the specified vertex, false otherwise

index()#

Indexes all vertex and edge properties. Returns a GraphIndex which allows the user to search the edges and vertices 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)#

Create a view including all the edges in the layers names

Parameters:

name (str) – the name of the layers to include

Returns:

a view including all the edges in the layers names

layers(names)#

Create a view including all the edges in the layers names

Parameters:

name (str) – the name of the layers to include

Returns:

a view including all the edges in the layers names

load_edge_props_from_pandas(df, src, dst, const_props=None, shared_const_props=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 vertex.

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

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

  • shared_const_props (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, props=None, const_props=None, shared_const_props=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 vertex ids.

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

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

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

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

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

  • 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 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)#

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_props=None, edge_const_props=None, edge_shared_const_props=None, edge_layer=None, layer_in_df=True, vertex_df=None, vertex_id=None, vertex_time=None, vertex_props=None, vertex_const_props=None, vertex_shared_const_props=None)#

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 vertex ids.

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

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

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

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

  • edge_shared_const_props (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.

  • vertex_df (pandas.DataFrame) – The DataFrame containing the vertices (optional) Defaults to None.

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

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

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

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

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

Returns:

The loaded Graph object.

Return type:

Graph

load_vertex_props_from_pandas(df, id, const_props=None, shared_const_props=None)#

Load vertex properties from a Pandas DataFrame.

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

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

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

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

Returns:

Result of the operation.

Return type:

Result<(), GraphError>

load_vertices_from_pandas(df, id, time, props=None, const_props=None, shared_const_props=None)#

Load vertices from a Pandas DataFrame into the graph.

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

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

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

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

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

  • shared_const_props (Dictionary/Hashmap of properties) – A dictionary of constant properties that will be added to every vertex. 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

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 – The size of the window.

  • step – The step size of the window. Defaults to the window size.

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

start#

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

Returns:

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

start_date_time#

Gets the earliest datetime that this graph is valid

Returns:

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

subgraph(vertices)#

Returns a subgraph given a set of vertices

Parameters:

vertices (*) – set of vertices

Returns:

GraphView - Returns the subgraph

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

vectorise(embedding, cache=None, node_document=None, edge_document=None, verbose=False)#
vertex(id)#

Gets the vertex with the specified id

Parameters:

id (str or int) – the vertex id

Returns:

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

vertices#

Gets the vertices in the graph

Returns:

the vertices in the graph

window(start=None, end=None)#

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

Parameters:
  • start – The start time of the window. Defaults to the start time of the graph.

  • end – The end time of the window. Defaults to the end time of the graph.

Returns: r A graph object.

window_size#

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

class raphtory.GraphWithDeletions#

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 vertices and properties to the graph.

add_property(timestamp, properties)

Adds properties to the graph.

add_vertex(timestamp, id[, properties])

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

after(start)

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

at(time)

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

before(end)

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

bincode()

Get bincode encoded graph

count_edges()

Number of edges in the graph

count_temporal_edges()

Number of edges in the graph

count_vertices()

Number of vertices in the graph

default_layer()

Create a view including all the edges in the default layer

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

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

edge(src, dst)

Gets the edge with the specified source and destination vertices

expanding(step)

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

has_edge(src, dst[, layer])

Returns true if the graph contains the specified edge

has_vertex(id)

Returns true if the graph contains the specified vertex

index()

Indexes all vertex and edge properties.

layer(name)

Create a view including all the edges in the layers names

layers(names)

Create a view including all the edges in the layers names

load_from_file(path)

Loads a graph from the given path.

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.

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.

subgraph(vertices)

Returns a subgraph given a set of vertices

update_constant_properties(properties)

Updates static properties to the graph.

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

vertex(id)

Gets the vertex with the specified id

window([start, end])

Create a view of the graph 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 graph is valid.

end_date_time

Gets the latest datetime that this graph is valid

latest_date_time

DateTime of latest activity in the graph

latest_time

Timestamp of latest activity in the graph

properties

Get all graph properties

start

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

start_date_time

Gets the earliest datetime that this graph is valid

unique_layers

Return all the layer ids in the graph

vertices

Gets the vertices in the graph

window_size

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

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 vertices and properties to the graph.

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

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

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

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

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

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

add_vertex(timestamp, id, properties=None)#

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

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

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

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

Returns:

None

after(start)#

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

Parameters:

start – The start time of the window.

Returns:

A graph object.

at(time)#

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

Parameters:

time – The time of the window.

Returns:

A graph object.

before(end)#

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

Parameters:

end – The end time of the window.

Returns:

A graph object.

bincode()#

Get bincode encoded graph

count_edges()#

Number of edges in the graph

Returns:

the number of edges in the graph

count_temporal_edges()#

Number of edges in the graph

Returns:

the number of temporal edges in the graph

count_vertices()#

Number of vertices in the graph

Returns:

the number of vertices in the graph

default_layer()#

Create a view including all the edges in the default layer

Returns:

a view including all the edges in the default layer

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

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

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

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

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

  • 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 vertices

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

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

Returns:

the edge with the specified source and destination vertices, 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 graph is valid.

Returns:

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

end_date_time#

Gets the latest datetime that this graph is valid

Returns:

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

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) – The step size of the window.

Returns:

A WindowSet object.

has_edge(src, dst, layer=None)#

Returns true if the graph contains the specified edge

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

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

  • layer (str) – the edge layer (optional)

Returns:

true if the graph contains the specified edge, false otherwise

has_vertex(id)#

Returns true if the graph contains the specified vertex

Parameters:

id (str or int) – the vertex id

Returns:

true if the graph contains the specified vertex, false otherwise

index()#

Indexes all vertex and edge properties. Returns a GraphIndex which allows the user to search the edges and vertices 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)#

Create a view including all the edges in the layers names

Parameters:

name (str) – the name of the layers to include

Returns:

a view including all the edges in the layers names

layers(names)#

Create a view including all the edges in the layers names

Parameters:

name (str) – the name of the layers to include

Returns:

a view including all the edges in the layers names

static load_from_file(path)#

Loads a graph from the given path.

Parameters:

path (str) – The path to the graph.

Returns:

The loaded graph.

Return type:

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

Returns:

GraphView - Returns a graph clone

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 – The size of the window.

  • step – The step size of the window. Defaults to the window size.

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

start#

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

Returns:

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

start_date_time#

Gets the earliest datetime that this graph is valid

Returns:

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

subgraph(vertices)#

Returns a subgraph given a set of vertices

Parameters:

vertices (*) – set of vertices

Returns:

GraphView - Returns the subgraph

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

vectorise(embedding, cache=None, node_document=None, edge_document=None, verbose=False)#
vertex(id)#

Gets the vertex with the specified id

Parameters:

id (str or int) – the vertex id

Returns:

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

vertices#

Gets the vertices in the graph

Returns:

the vertices in the graph

window(start=None, end=None)#

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

Parameters:
  • start – The start time of the window. Defaults to the start time of the graph.

  • end – The end time of the window. Defaults to the end time of the graph.

Returns: r A graph object.

window_size#

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