Skip to main content

Python Client

Official Python SDK for the Nebula Memory API.

Installation

pip install nebula-client

Setup

# Set environment variable
export NEBULA_API_KEY="your_api_key_here"
from nebula import Nebula

# Automatically uses NEBULA_API_KEY environment variable
nebula = Nebula()

Quick Start

from nebula import Nebula

# Initialize client
nebula = Nebula()

# Store a memory
memory_id = nebula.store_memory({
    "collection_id": "my-collection",
    "content": "Nebula makes memory management easy",
    "metadata": {"topic": "nebula"}
})

# Search memories
results = nebula.search(
    query="memory management",
    collection_ids=["my-collection"]
)

for result in results:
    print(f"Content: {result.content}")
For more detailed examples, see Memory Operations.

Async Support

The Python SDK includes a dedicated async client:
import asyncio
from nebula import AsyncNebula

async def main():
    # Create async client (uses NEBULA_API_KEY env var)
    nebula = AsyncNebula()

    # All operations are async
    collection = await nebula.create_collection(name="async_notes", description="Async example")

    memory_id = await nebula.store_memory({
        "collection_id": collection.id,
        "content": "Async operations are fast",
        "metadata": {"type": "example"}
    })

    results = await nebula.search(
        query="async",
        collection_ids=[collection.id]
    )

    for result in results:
        print(f"{result.content}")

    # Clean up
    await nebula.aclose()

asyncio.run(main())

Async Context Manager

import asyncio
from nebula import AsyncNebula

async def main():
    # Automatically handles cleanup
    async with AsyncNebula() as nebula:
        collection = await nebula.create_collection(name="notes", description="My notes")

        memory_id = await nebula.store_memory({
            "collection_id": collection.id,
            "content": "Context managers are clean"
        })

        results = await nebula.search(
            query="clean",
            collection_ids=[collection.id]
        )

        print(f"Found {len(results)} results")

asyncio.run(main())

Next Steps