Skip to content

Graph Store

Graph Storage

GraphStore provides named, persistent storage for NetworkX graphs, backed by AWS S3.

Just like the DataFrame Store handles named DataFrames, the GraphStore class lets your team list, add, retrieve, and delete named NetworkX graphs from a shared, inspectable location.

Workbench REPL

Experiment with listing, adding, and getting graphs using the GraphStore() class in the Workbench REPL.

GraphStore: Storage for NetworkX Graphs

GraphStore

Bases: AWSGraphStore

GraphStore: Storage for NetworkX Graphs

Common Usage
graph_store = GraphStore()

# List all Graphs
graph_store.list()

# Add Graph
g = nx.erdos_renyi_graph(5, 0.5)
graph_store.upsert("/test/my_graph", my_graph)

# Retrieve Graph
g = graph_store.get("/test/my_graph")
print(g)

# Delete Graph
graph_store.delete("/test/my_graph")
Source code in src/workbench/api/graph_store.py
class GraphStore(AWSGraphStore):
    """GraphStore: Storage for NetworkX Graphs

    Common Usage:
        ```python
        graph_store = GraphStore()

        # List all Graphs
        graph_store.list()

        # Add Graph
        g = nx.erdos_renyi_graph(5, 0.5)
        graph_store.upsert("/test/my_graph", my_graph)

        # Retrieve Graph
        g = graph_store.get("/test/my_graph")
        print(g)

        # Delete Graph
        graph_store.delete("/test/my_graph")
        ```
    """

    def __init__(self, path_prefix: Optional[str] = None):
        """GraphStore Init Method

        Args:
            path_prefix (Optional[str]): Path prefix for storage locations (Defaults to None)
        """

        # Initialize the SuperClass
        super().__init__(path_prefix=path_prefix)

    def summary(self) -> pd.DataFrame:
        """Provide a summary of all graphs in the store.

        Returns:
            pd.DataFrame: Summary DataFrame with location, size, and modified date.
        """
        return super().summary()

    def details(self) -> pd.DataFrame:
        """Return detailed metadata for all stored graphs.

        Returns:
            pd.DataFrame: DataFrame with details like location, size, and last modified date.
        """
        return super().details()

    def check(self, location: str) -> bool:
        """Check if a graph exists.

        Args:
            location (str): Logical location of the graph.

        Returns:
            bool: True if the graph exists, False otherwise.
        """
        return super().check(location)

    def get(self, location: str) -> Union[nx.Graph, None]:
        """Retrieve a NetworkX graph from AWS S3.

        Args:
            location (str): Logical location of the graph.

        Returns:
            Union[nx.Graph, None]: The retrieved graph or None if not found.
        """
        return super().get(location)

    def upsert(self, location: str, graph: nx.Graph):
        """Insert or update a NetworkX graph in AWS S3.

        Args:
            location (str): Logical location to store the graph.
            graph (nx.Graph): The NetworkX graph to store.
        """
        super().upsert(location, graph)

    def list(self) -> list:
        """List all graphs in the store.

        Returns:
            list: A list of all graph locations in the store.
        """
        return super().list()

    def last_modified(self, location: str) -> Union[datetime, None]:
        """Return the last modified date of a graph.

        Args:
            location (str): Logical location of the graph.

        Returns:
            Union[datetime, None]: Last modified datetime or None if not found.
        """
        return super().last_modified(location)

    def delete(self, location: str):
        """Delete a NetworkX graph from AWS S3.

        Args:
            location (str): Logical location of the graph to delete.
        """
        super().delete(location)

__init__(path_prefix=None)

GraphStore Init Method

Parameters:

Name Type Description Default
path_prefix Optional[str]

Path prefix for storage locations (Defaults to None)

None
Source code in src/workbench/api/graph_store.py
def __init__(self, path_prefix: Optional[str] = None):
    """GraphStore Init Method

    Args:
        path_prefix (Optional[str]): Path prefix for storage locations (Defaults to None)
    """

    # Initialize the SuperClass
    super().__init__(path_prefix=path_prefix)

check(location)

Check if a graph exists.

Parameters:

Name Type Description Default
location str

Logical location of the graph.

required

Returns:

Name Type Description
bool bool

True if the graph exists, False otherwise.

Source code in src/workbench/api/graph_store.py
def check(self, location: str) -> bool:
    """Check if a graph exists.

    Args:
        location (str): Logical location of the graph.

    Returns:
        bool: True if the graph exists, False otherwise.
    """
    return super().check(location)

delete(location)

Delete a NetworkX graph from AWS S3.

Parameters:

Name Type Description Default
location str

Logical location of the graph to delete.

required
Source code in src/workbench/api/graph_store.py
def delete(self, location: str):
    """Delete a NetworkX graph from AWS S3.

    Args:
        location (str): Logical location of the graph to delete.
    """
    super().delete(location)

details()

Return detailed metadata for all stored graphs.

Returns:

Type Description
DataFrame

pd.DataFrame: DataFrame with details like location, size, and last modified date.

Source code in src/workbench/api/graph_store.py
def details(self) -> pd.DataFrame:
    """Return detailed metadata for all stored graphs.

    Returns:
        pd.DataFrame: DataFrame with details like location, size, and last modified date.
    """
    return super().details()

get(location)

Retrieve a NetworkX graph from AWS S3.

Parameters:

Name Type Description Default
location str

Logical location of the graph.

required

Returns:

Type Description
Union[Graph, None]

Union[nx.Graph, None]: The retrieved graph or None if not found.

Source code in src/workbench/api/graph_store.py
def get(self, location: str) -> Union[nx.Graph, None]:
    """Retrieve a NetworkX graph from AWS S3.

    Args:
        location (str): Logical location of the graph.

    Returns:
        Union[nx.Graph, None]: The retrieved graph or None if not found.
    """
    return super().get(location)

last_modified(location)

Return the last modified date of a graph.

Parameters:

Name Type Description Default
location str

Logical location of the graph.

required

Returns:

Type Description
Union[datetime, None]

Union[datetime, None]: Last modified datetime or None if not found.

Source code in src/workbench/api/graph_store.py
def last_modified(self, location: str) -> Union[datetime, None]:
    """Return the last modified date of a graph.

    Args:
        location (str): Logical location of the graph.

    Returns:
        Union[datetime, None]: Last modified datetime or None if not found.
    """
    return super().last_modified(location)

list()

List all graphs in the store.

Returns:

Name Type Description
list list

A list of all graph locations in the store.

Source code in src/workbench/api/graph_store.py
def list(self) -> list:
    """List all graphs in the store.

    Returns:
        list: A list of all graph locations in the store.
    """
    return super().list()

summary()

Provide a summary of all graphs in the store.

Returns:

Type Description
DataFrame

pd.DataFrame: Summary DataFrame with location, size, and modified date.

Source code in src/workbench/api/graph_store.py
def summary(self) -> pd.DataFrame:
    """Provide a summary of all graphs in the store.

    Returns:
        pd.DataFrame: Summary DataFrame with location, size, and modified date.
    """
    return super().summary()

upsert(location, graph)

Insert or update a NetworkX graph in AWS S3.

Parameters:

Name Type Description Default
location str

Logical location to store the graph.

required
graph Graph

The NetworkX graph to store.

required
Source code in src/workbench/api/graph_store.py
def upsert(self, location: str, graph: nx.Graph):
    """Insert or update a NetworkX graph in AWS S3.

    Args:
        location (str): Logical location to store the graph.
        graph (nx.Graph): The NetworkX graph to store.
    """
    super().upsert(location, graph)