PersistentGraph

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

Methods

MethodDescription
add_edgeAdds a new edge with the given source and destination nodes and properties to the graph.
add_metadataAdds metadata to the graph.
add_nodeAdds a new node with the given id and properties to the graph.
add_propertiesAdds properties to the graph.
cacheWrite PersistentGraph to cache file and initialise the cache.
create_indexCreate graph index
create_index_in_ramCreates a graph index in memory (RAM).
create_index_in_ram_with_specCreates a graph index in memory (RAM) with the provided index spec.
create_index_with_specCreate graph index with the provided index spec.
create_nodeCreates a new node with the given id and properties to the graph. It fails if the node already exists.
delete_edgeDeletes an edge given the timestamp, src and dst nodes and layer (optional).
deserialiseLoad PersistentGraph from serialised bytes.
edgeGets the edge with the specified source and destination nodes
event_graphGet event graph
get_all_node_typesReturns all the node types in the graph.
import_edgeImport a single edge into the graph.
import_edge_asImport a single edge into the graph with new id.
import_edgesImport multiple edges into the graph.
import_edges_asImport multiple edges into the graph with new ids.
import_nodeImport a single node into the graph.
import_node_asImport a single node into the graph with new id.
import_nodesImport multiple nodes into the graph.
import_nodes_asImport multiple nodes into the graph with new ids.
load_cachedLoad PersistentGraph from a file and initialise it as a cache file.
load_edge_deletionsLoad edge deletions into the graph from any data source that supports the ArrowStreamExportable protocol (by providing an arrow_c_stream() method),
load_edge_metadataLoad edge metadata into the graph from any data source that supports the ArrowStreamExportable protocol (by providing an arrow_c_stream() method),
load_edgesLoad edges into the graph from any data source that supports the ArrowStreamExportable protocol (by providing an arrow_c_stream() method),
load_from_fileLoad PersistentGraph from a file.
load_node_metadataLoad node metadata into the graph from any data source that supports the ArrowStreamExportable protocol (by providing an arrow_c_stream() method),
load_nodesLoad nodes into the graph from any data source that supports the ArrowStreamExportable protocol (by providing an arrow_c_stream() method),
nodeGets the node with the specified id
persistent_graphGet persistent graph
save_to_fileSaves the PersistentGraph to the given path.
save_to_zipSaves the PersistentGraph to the given path.
serialiseSerialise PersistentGraph to bytes.
update_metadataUpdates metadata of the graph.
write_updatesPersist the new updates by appending them to the cache file.

Method Details

add_edge

Signature: add_edge(timestamp, src, dst, properties=None, layer=None, event_id=None)

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

Parameters

NameTypeDefaultDescription
timestampint-The timestamp of the edge.
srcstr | int-The id of the source node.
dststr | int-The id of the destination node.
propertiesPropInput, optionalNoneThe properties of the edge, as a dict of string and properties.
layerstr, optionalNoneThe layer of the edge.
event_idint, optionalNoneThe optional integer which will be used as an event id.

Returns

TypeDescription
NoneThis function does not return a value, if the operation is successful.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

add_metadata

Signature: add_metadata(metadata)

Adds metadata to the graph.

Parameters

NameTypeDefaultDescription
metadatadict-The static properties of the graph.

Returns

TypeDescription
NoneThis function does not return a value, if the operation is successful.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

add_node

Signature: add_node(timestamp, id, properties=None, node_type=None, event_id=None)

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

Parameters

NameTypeDefaultDescription
timestampTimeInput-The timestamp of the node.
idstr | int-The id of the node.
propertiesPropInput, optionalNoneThe properties of the node.
node_typestr, optionalNoneThe optional string which will be used as a node type.
event_idint, optionalNoneThe optional integer which will be used as an event id.

Returns

TypeDescription
NoneThis function does not return a value, if the operation is successful.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

add_properties

Signature: add_properties(timestamp, properties, event_id=None)

Adds properties to the graph.

Parameters

NameTypeDefaultDescription
timestampTimeInput-The timestamp of the temporal property.
propertiesdict-The temporal properties of the graph.
event_idint, optionalNoneThe optional integer which will be used as an event id.

Returns

TypeDescription
NoneThis function does not return a value, if the operation is successful.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

cache

Signature: cache(path)

Write PersistentGraph to cache file and initialise the cache.

Future updates are tracked. Use write_updates to persist them to the cache file. If the file already exists its contents are overwritten.

Parameters

NameTypeDefaultDescription
pathstr-The path to the cache file

Returns

TypeDescription
None

create_index

Create graph index

Returns

TypeDescription
None

create_index_in_ram

Creates a graph index in memory (RAM).

This is primarily intended for use in tests and should not be used in production environments, as the index will not be persisted to disk.

Returns

TypeDescription
None

create_index_in_ram_with_spec

Signature: create_index_in_ram_with_spec(py_spec)

Creates a graph index in memory (RAM) with the provided index spec.

This is primarily intended for use in tests and should not be used in production environments, as the index will not be persisted to disk.

Parameters

NameTypeDefaultDescription
py_specIndexSpec-The specification for the in-memory index to be created.

Returns

TypeDescription
None

create_index_with_spec

Signature: create_index_with_spec(py_spec)

Create graph index with the provided index spec.

Parameters

NameTypeDefaultDescription
py_specAny-

Returns

TypeDescription
None

create_node

Signature: create_node(timestamp, id, properties=None, node_type=None, event_id=None)

Creates a new node with the given id and properties to the graph. It fails if the node already exists.

Parameters

NameTypeDefaultDescription
timestampTimeInput-The timestamp of the node.
idstr | int-The id of the node.
propertiesPropInput, optionalNoneThe properties of the node.
node_typestr, optionalNoneThe optional string which will be used as a node type.
event_idint, optionalNoneThe optional integer which will be used as an event id.

Returns

TypeDescription
MutableNodethe newly created node.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

delete_edge

Signature: delete_edge(timestamp, src, dst, layer=None, event_id=None)

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

Parameters

NameTypeDefaultDescription
timestampint-The timestamp of the edge.
srcstr | int-The id of the source node.
dststr | int-The id of the destination node.
layerstr, optionalNoneThe layer of the edge.
event_idint, optionalNoneThe optional integer which will be used as an event id.

Returns

TypeDescription
MutableEdgeThe deleted edge

Raises

ExceptionDescription
GraphErrorIf the operation fails.

deserialise

Signature: deserialise(bytes)

Load PersistentGraph from serialised bytes.

Parameters

NameTypeDefaultDescription
bytesbytes-The serialised bytes to decode

Returns

TypeDescription
PersistentGraph

edge

Signature: edge(src, dst)

Gets the edge with the specified source and destination nodes

Parameters

NameTypeDefaultDescription
srcstr | int-the source node id
dststr | int-the destination node id

Returns

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

event_graph

Get event graph

Returns

TypeDescription
Graphthe graph with event semantics applied

get_all_node_types

Returns all the node types in the graph.

Returns

TypeDescription
list[str]A list of node types

import_edge

Signature: import_edge(edge, merge=False)

Import a single edge into the graph.

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

Parameters

NameTypeDefaultDescription
edgeEdge-An edge object representing the edge to be imported.
mergebool, optionalFalseAn optional boolean flag indicating whether to merge the import of the edge. Defaults to False.

Returns

TypeDescription
EdgeThe imported edge.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

import_edge_as

Signature: import_edge_as(edge, new_id, merge=False)

Import a single edge into the graph with new id.

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

Parameters

NameTypeDefaultDescription
edgeEdge-A edge object representing the edge to be imported.
new_idtuple-The ID of the new edge. It's a tuple of the source and destination node ids.
mergebool, optionalFalseAn optional boolean flag indicating whether to merge the import of the edge. Defaults to False.

Returns

TypeDescription
EdgeThe imported edge.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

import_edges

Signature: import_edges(edges, merge=False)

Import multiple edges into the graph.

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

Parameters

NameTypeDefaultDescription
edgeslist[Edge]-A vector of edge objects representing the edges to be imported.
mergebool, optionalFalseAn optional boolean flag indicating whether to merge the import of the edges. Defaults to False.

Returns

TypeDescription
NoneThis function does not return a value, if the operation is successful.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

import_edges_as

Signature: import_edges_as(edges, new_ids, merge=False)

Import multiple edges into the graph with new ids.

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

Parameters

NameTypeDefaultDescription
edgeslist[Edge]-A vector of edge objects representing the edges to be imported.
new_idslist[tuple[GID, GID]]-The new edge ids
mergebool, optionalFalseAn optional boolean flag indicating whether to merge the import of the edges. Defaults to False.

Returns

TypeDescription
NoneThis function does not return a value, if the operation is successful.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

import_node

Signature: import_node(node, merge=False)

Import a single node into the graph.

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

Parameters

NameTypeDefaultDescription
nodeNode-A node object representing the node to be imported.
mergebool, optionalFalseAn optional boolean flag indicating whether to merge the import of the node. Defaults to False.

Returns

TypeDescription
NodeA Node object if the node was successfully imported, and an error otherwise.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

import_node_as

Signature: import_node_as(node, new_id, merge=False)

Import a single node into the graph with new id.

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

Parameters

NameTypeDefaultDescription
nodeNode-A node object representing the node to be imported.
new_idstr | int-The new node id.
mergebool, optionalFalseAn optional boolean flag indicating whether to merge the import of the node. Defaults to False.

Returns

TypeDescription
NodeA Node object if the node was successfully imported, and an error otherwise.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

import_nodes

Signature: import_nodes(nodes, merge=False)

Import multiple nodes into the graph.

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

Parameters

NameTypeDefaultDescription
nodeslist[Node]-A vector of node objects representing the nodes to be imported.
mergebool, optionalFalseAn optional boolean flag indicating whether to merge the import of the nodes. Defaults to False.

Returns

TypeDescription
NoneThis function does not return a value, if the operation is successful.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

import_nodes_as

Signature: import_nodes_as(nodes, new_ids, merge=False)

Import multiple nodes into the graph with new ids.

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

Parameters

NameTypeDefaultDescription
nodeslist[Node]-A vector of node objects representing the nodes to be imported.
new_idsList | int]-A list of node IDs to use for the imported nodes.
mergebool, optionalFalseAn optional boolean flag indicating whether to merge the import of the nodes. Defaults to False.

Returns

TypeDescription
NoneThis function does not return a value, if the operation is successful.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

load_cached

Signature: load_cached(path)

Load PersistentGraph from a file and initialise it as a cache file.

Future updates are tracked. Use write_updates to persist them to the cache file.

Parameters

NameTypeDefaultDescription
pathstr-The path to the cache file

Returns

TypeDescription
PersistentGraphthe loaded graph with initialised cache

load_edge_deletions

Signature: load_edge_deletions(data, time, src, dst, layer=None, layer_col=None, schema=None, csv_options=None)

Load edge deletions into the graph from any data source that supports the ArrowStreamExportable protocol (by providing an arrow_c_stream() method), a path to a CSV or Parquet file, or a directory containing multiple CSV or Parquet files. The following are known to support the ArrowStreamExportable protocol: Pandas dataframes, FireDucks(.pandas) dataframes, Polars dataframes, Arrow tables, DuckDB (e.g. DuckDBPyRelation obtained from running an SQL query).

Parameters

NameTypeDefaultDescription
dataAny-The data source containing the edges.
timestr-The column name for the update timestamps.
srcstr-The column name for the source node ids.
dststr-The column name for the destination node ids.
layerstr, optionalNoneA value to use as the layer for all edges. Cannot be used in combination with layer_col. Defaults to None.
layer_colstr, optionalNoneThe edge layer col name in the data source. Cannot be used in combination with layer. Defaults to None.
schemalist | PropType | str]] | dict | PropType | str], optionalNoneA list of (column_name, column_type) tuples or dict of {"column_name": column_type} to cast columns to. Defaults to None.
csv_optionsdict | bool], optionalNoneA dictionary of CSV reading options such as delimiter, comment, escape, quote, and terminator characters, as well as allow_truncated_rows and has_header flags. Defaults to None.

Returns

TypeDescription
NoneThis function does not return a value, if the operation is successful.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

load_edge_metadata

Signature: load_edge_metadata(data, src, dst, metadata=None, shared_metadata=None, layer=None, layer_col=None, schema=None, csv_options=None)

Load edge metadata into the graph from any data source that supports the ArrowStreamExportable protocol (by providing an arrow_c_stream() method), a path to a CSV or Parquet file, or a directory containing multiple CSV or Parquet files. The following are known to support the ArrowStreamExportable protocol: Pandas dataframes, FireDucks(.pandas) dataframes, Polars dataframes, Arrow tables, DuckDB (e.g. DuckDBPyRelation obtained from running an SQL query).

Parameters

NameTypeDefaultDescription
dataAny-The data source containing edge information.
srcstr-The column name for the source node.
dststr-The column name for the destination node.
metadatalist[str], optionalNoneList of edge metadata column names. Defaults to None.
shared_metadataPropInput, optionalNoneA dictionary of metadata properties that will be added to every edge. Defaults to None.
layerstr, optionalNoneThe edge layer name. Defaults to None.
layer_colstr, optionalNoneThe edge layer column name in a dataframe. Defaults to None.
schemalist | PropType | str]] | dict | PropType | str], optionalNoneA list of (column_name, column_type) tuples or dict of {"column_name": column_type} to cast columns to. Defaults to None.
csv_optionsdict | bool], optionalNoneA dictionary of CSV reading options such as delimiter, comment, escape, quote, and terminator characters, as well as allow_truncated_rows and has_header flags. Defaults to None.

Returns

TypeDescription
NoneThis function does not return a value if the operation is successful.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

load_edges

Signature: load_edges(data, time, src, dst, properties=None, metadata=None, shared_metadata=None, layer=None, layer_col=None, schema=None, csv_options=None)

Load edges into the graph from any data source that supports the ArrowStreamExportable protocol (by providing an arrow_c_stream() method), a path to a CSV or Parquet file, or a directory containing multiple CSV or Parquet files. The following are known to support the ArrowStreamExportable protocol: Pandas dataframes, FireDucks(.pandas) dataframes, Polars dataframes, Arrow tables, DuckDB (e.g. DuckDBPyRelation obtained from running an SQL query).

Parameters

NameTypeDefaultDescription
dataAny-The data source containing the edges.
timestr-The column name for the update timestamps.
srcstr-The column name for the source node IDs.
dststr-The column name for the destination node IDs.
propertieslist[str], optionalNoneList of edge property column names. Defaults to None.
metadatalist[str], optionalNoneList of edge metadata column names. Defaults to None.
shared_metadataPropInput, optionalNoneA dictionary of metadata properties that will be added to every edge. Defaults to None.
layerstr, optionalNoneA value to use as the layer for all edges. Cannot be used in combination with layer_col. Defaults to None.
layer_colstr, optionalNoneThe edge layer column name in a dataframe. Cannot be used in combination with layer. Defaults to None.
schemalist | PropType | str]] | dict | PropType | str], optionalNoneA list of (column_name, column_type) tuples or dict of {"column_name": column_type} to cast columns to. Defaults to None.
csv_optionsdict | bool], optionalNoneA dictionary of CSV reading options such as delimiter, comment, escape, quote, and terminator characters, as well as allow_truncated_rows and has_header flags. Defaults to None.

Returns

TypeDescription
NoneThis function does not return a value if the operation is successful.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

load_from_file

Signature: load_from_file(path)

Load PersistentGraph from a file.

Parameters

NameTypeDefaultDescription
pathstr-The path to the file.

Returns

TypeDescription
PersistentGraph

load_node_metadata

Signature: load_node_metadata(data, id, node_type=None, node_type_col=None, metadata=None, shared_metadata=None, schema=None, csv_options=None)

Load node metadata into the graph from any data source that supports the ArrowStreamExportable protocol (by providing an arrow_c_stream() method), a path to a CSV or Parquet file, or a directory containing multiple CSV or Parquet files. The following are known to support the ArrowStreamExportable protocol: Pandas dataframes, FireDucks(.pandas) dataframes, Polars dataframes, Arrow tables, DuckDB (e.g. DuckDBPyRelation obtained from running an SQL query).

Parameters

NameTypeDefaultDescription
dataAny-The data source containing node information.
idstr-The column name for the node IDs.
node_typestr, optionalNoneA value to use as the node type for all nodes. Cannot be used in combination with node_type_col. Defaults to None.
node_type_colstr, optionalNoneThe node type column name in a dataframe. Cannot be used in combination with node_type. Defaults to None.
metadatalist[str], optionalNoneList of node metadata column names. Defaults to None.
shared_metadataPropInput, optionalNoneA dictionary of metadata properties that will be added to every node. Defaults to None.
schemalist | PropType | str]] | dict | PropType | str], optionalNoneA list of (column_name, column_type) tuples or dict of {"column_name": column_type} to cast columns to. Defaults to None.
csv_optionsdict | bool], optionalNoneA dictionary of CSV reading options such as delimiter, comment, escape, quote, and terminator characters, as well as allow_truncated_rows and has_header flags. Defaults to None.

Returns

TypeDescription
NoneThis function does not return a value if the operation is successful.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

load_nodes

Signature: load_nodes(data, time, id, node_type=None, node_type_col=None, properties=None, metadata=None, shared_metadata=None, schema=None, csv_options=None)

Load nodes into the graph from any data source that supports the ArrowStreamExportable protocol (by providing an arrow_c_stream() method), a path to a CSV or Parquet file, or a directory containing multiple CSV or Parquet files. The following are known to support the ArrowStreamExportable protocol: Pandas dataframes, FireDucks(.pandas) dataframes, Polars dataframes, Arrow tables, DuckDB (e.g. DuckDBPyRelation obtained from running an SQL query).

Parameters

NameTypeDefaultDescription
dataAny-The data source containing the nodes.
timestr-The column name for the timestamps.
idstr-The column name for the node IDs.
node_typestr, optionalNoneA value to use as the node type for all nodes. Cannot be used in combination with node_type_col. Defaults to None.
node_type_colstr, optionalNoneThe node type column name in a dataframe. Cannot be used in combination with node_type. Defaults to None.
propertieslist[str], optionalNoneList of node property column names. Defaults to None.
metadatalist[str], optionalNoneList of node metadata column names. Defaults to None.
shared_metadataPropInput, optionalNoneA dictionary of metadata properties that will be added to every node. Defaults to None.
schemalist | PropType | str]] | dict | PropType | str], optionalNoneA list of (column_name, column_type) tuples or dict of {"column_name": column_type} to cast columns to. Defaults to None.
csv_optionsdict | bool], optionalNoneA dictionary of CSV reading options such as delimiter, comment, escape, quote, and terminator characters, as well as allow_truncated_rows and has_header flags. Defaults to None.

Returns

TypeDescription
NoneThis function does not return a value if the operation is successful.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

node

Signature: node(id)

Gets the node with the specified id

Parameters

NameTypeDefaultDescription
idstr | int-the node id

Returns

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

persistent_graph

Get persistent graph

Returns

TypeDescription
PersistentGraphthe graph with persistent semantics applied

save_to_file

Signature: save_to_file(path)

Saves the PersistentGraph to the given path.

Parameters

NameTypeDefaultDescription
pathstr-The path to the file.

Returns

TypeDescription
None

save_to_zip

Signature: save_to_zip(path)

Saves the PersistentGraph to the given path.

Parameters

NameTypeDefaultDescription
pathstr-The path to the file.

Returns

TypeDescription
None

serialise

Serialise PersistentGraph to bytes.

Returns

TypeDescription
bytes

update_metadata

Signature: update_metadata(metadata)

Updates metadata of the graph.

Parameters

NameTypeDefaultDescription
metadatadict-The static properties of the graph.

Returns

TypeDescription
NoneThis function does not return a value, if the operation is successful.

Raises

ExceptionDescription
GraphErrorIf the operation fails.

write_updates

Persist the new updates by appending them to the cache file.

Returns

TypeDescription
None