Back to Graphrag

Copyright (c) 2026 Microsoft Corporation.

packages/graphrag-storage/example_notebooks/basic_storage_example.ipynb

3.0.9877 B
Original Source
python
# Copyright (c) 2026 Microsoft Corporation.
# Licensed under the MIT License.

Basic storage example

This example creates a file storage system using the GraphRAG storage package's configuration system. The example shows setting up file storage in a specified directory and demonstrates basic storage operations like setting and getting key-value pairs.

python
from graphrag_storage import StorageConfig, StorageType, create_storage


async def run():
    """Demonstrate basic storage operations."""
    storage = create_storage(StorageConfig(type=StorageType.File, base_dir="output"))

    print("Saving and retrieving a value from storage...")
    print("Setting key 'my_key' to 'value'")

    await storage.set("my_key", "value")
    print("Getting key 'my_key':")
    print(await storage.get("my_key"))


if __name__ == "__main__":
    await run()