Skip to main content

Python SDK for Kagura Memory Cloud — AI-driven memory management

Project description

Kagura Ai
Memory SDK — Python client for Kagura Memory Cloud

PyPI version Python versions CI codecov License: MIT MCP Checked with pyright

What is this?

This SDK connects your Python code to Kagura Memory Cloud, giving AI assistants the ability to remember, search, and learn from past interactions. It provides three clients for different use cases:

Client Protocol Use Case
KaguraAgent MCP + LLM AI-powered — auto-decides what to remember/recall from conversations
KaguraClient MCP (JSON-RPC) Direct memory ops — remember, recall, explore, reference, forget
ResourceClient REST API External data ingestion — push data from Slack, CI/CD, CRM into Kagura

Installation

pip install kagura-memory
# or
uv add kagura-memory

Quick Start

Configuration

Copy the example and fill in your credentials:

cp .kagura.json.example .kagura.json
# Edit .kagura.json — set api_key and mcp_url

Used by the CLI (kagura commands) and load_config() in Python code:

{
  "api_key": "kagura_your_api_key",
  "mcp_url": "http://localhost:8080/mcp/w/{workspace_id}",
  "model": "gpt-5.4-nano",
  "context_id": "dev"
}

Or use environment variables: KAGURA_API_KEY, KAGURA_MCP_URL, KAGURA_MODEL, KAGURA_CONTEXT_ID

Get your API key from the Kagura Memory Cloud Web UI: Integrations > API Keys

KaguraAgent — AI-Powered Memory

Let the AI analyze conversations and automatically decide what to remember and recall:

from kagura_memory import KaguraAgent, Session, Message

agent = KaguraAgent(api_key="kagura_...", model="gpt-5.4-nano")

session = Session(messages=[
    Message(role="user", content="FastAPIでOAuth2を実装したい"),
    Message(role="assistant", content="Authlibを使うパターンが推奨です..."),
    Message(role="user", content="なるほど、これ覚えておいて"),
])

async with agent:
    result = await agent.process(session, deep=True, verbose=2)
    print(f"Remembered: {len(result.remembered)}, Recalled: {len(result.recalled)}")

Supports OpenAI, Claude, Gemini, Ollama via LiteLLM.

KaguraClient — Direct Memory Operations

For programmatic control without LLM:

from kagura_memory import KaguraClient

async with KaguraClient(api_key="kagura_...", mcp_url="https://...") as client:
    await client.remember(context_id="dev", summary="OAuth2 pattern", content="Use Authlib...")
    results = await client.recall(context_id="dev", query="OAuth2", k=5)
    await client.explore(context_id="dev", memory_id="uuid", depth=3)

ResourceClient — External Data Ingestion

Push data from external systems into Kagura so AI can search it:

from kagura_memory import ResourceClient, ResourceEventRequest

async with ResourceClient.from_mcp_url(api_key="kagura_...", mcp_url="http://localhost:8080/mcp/w/...") as client:
    # One-call setup: create public context + set resource_id + create token
    token = await client.setup_resource(resource_id="products", summary="Product catalog")
    print(f"Save this token: {token.token}")  # Shown only once!

    event = ResourceEventRequest(
        op="upsert", doc_id="SKU-001", version=1,
        payload={"name": "Wireless Headphones", "price": 79.99},
    )
    await client.ingest_event("products", token.token, event)

See examples/ for complete working examples.

CLI

# AI-powered (requires LLM API key)
kagura process -m "Remember: FastAPI uses Depends() for DI"

# Direct memory operations
kagura remember -s "FastAPI DI" --content "Use Depends()..." -c dev
kagura recall "dependency injection" -k 10
kagura explore -m "memory-uuid" --depth 3
kagura forget -m "memory-uuid"
kagura contexts

# Resource tokens
kagura resource tokens create -r products -d "Product sync"
kagura resource ingest -r products -k TOKEN --doc-id SKU-001 -V 1 -p '{"name":"Widget"}'
kagura resource ingest-batch -r products -k TOKEN -f events.json

# Config
kagura config show

Claude Code Integration

Use Kagura Memory as an MCP server in Claude Code:

cp .mcp.json.example .mcp.json
# Edit .mcp.json — set workspace_id and API key

Or use the CLI directly:

kagura process -m "今日の学び:FastAPIのDIはDepends()を使う"

API Coverage

Operation SDK Client Protocol Auth
Memory (remember/recall/forget/explore/reference) KaguraClient MCP API Key
Context (create/update/list/get) KaguraClient MCP API Key
Context delete Web UI only Session
Resource Token (create/list/update/revoke) ResourceClient REST API API Key
Resource Event ingestion ResourceClient REST API Resource Token

Context deletion is intentionally Web UI only — destructive operations require session authentication and confirmation.

Development

git clone https://github.com/kagura-ai/kagura-memory-python-sdk.git
cd kagura-memory-python-sdk
uv sync --dev
uv run ruff check src/ tests/   # Lint
uv run ruff format src/ tests/  # Format
uv run pyright src/              # Type check
uv run pytest tests/ -v          # Test

Development with Claude Code

This project is developed with Claude Code:

/workflow        # Check current state and next step
/quality         # Run all quality checks
/simplify        # Review for reuse, quality, efficiency
/self-review     # Pre-PR self-review
/release <level> # Bump version, tag, push, create GitHub Release
/kagura-guide    # SDK usage reference

Typical flow: Issue → Branch → Implement → /quality/simplify/self-review → PR → Merge → /release

Links

License

MIT License — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kagura_memory-0.4.2.tar.gz (191.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kagura_memory-0.4.2-py3-none-any.whl (34.2 kB view details)

Uploaded Python 3

File details

Details for the file kagura_memory-0.4.2.tar.gz.

File metadata

  • Download URL: kagura_memory-0.4.2.tar.gz
  • Upload date:
  • Size: 191.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kagura_memory-0.4.2.tar.gz
Algorithm Hash digest
SHA256 08b08eefdfe3d93c8c3085d45a7c92caffceb1692d16e7a80beb3e7db0b53548
MD5 ba75d1c1f2a6b87e71fa507715f0e1a5
BLAKE2b-256 d9d1d87cb80cdb44afc200c9a72254693f160aa9ad1b2c5819850fdac4bf22e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for kagura_memory-0.4.2.tar.gz:

Publisher: publish.yml on kagura-ai/kagura-memory-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kagura_memory-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: kagura_memory-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 34.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kagura_memory-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 07fd9d560a4279f5d97e339997bfab958bbfd4cda5f924f7e3d7c887d236bdd7
MD5 ead3dafd6820bfb20e5e4d98a3b8e67b
BLAKE2b-256 1bd9c821527870166a886cae163aaf08a914fef32d45bbf16832d430f41c62c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for kagura_memory-0.4.2-py3-none-any.whl:

Publisher: publish.yml on kagura-ai/kagura-memory-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page