Skip to main content

Python SDK for Akasha — The Shared Cognitive Fabric for Intelligent Agent Systems

Project description

Akasha Python SDK

The official Python client for Akasha — The Shared Cognitive Fabric for Intelligent Agent Systems.

PyPI Python License

Installation

pip install akasha-client

Quick Start

from akasha import AkashaHttpClient

# Connect (auto-TLS with self-signed certs → verify_ssl=False for dev)
client = AkashaHttpClient(
    "https://localhost:7777",
    api_key="ak_your_api_key",
    verify_ssl=False,
)

# Write a record
record = client.put("agents/planner/state", {
    "status": "thinking",
    "task": "summarize document",
    "confidence": 0.85,
})

print(f"Created: {record.path} (v{record.version})")

# Read it back
state = client.get("agents/planner/state")
print(f"Status: {state.value['status']}")

# Query with glob patterns
all_states = client.query("agents/*/state")
for r in all_states:
    print(f"  {r.path}: {r.value}")

# Delete
client.delete("agents/planner/state")
client.close()

CAS (Compare-And-Swap) — Optimistic Concurrency

Prevent lost updates when multiple agents write to the same path:

from akasha import AkashaHttpClient, CasConflictError

client = AkashaHttpClient("https://localhost:7777", verify_ssl=False)

# Read current version
record = client.get("shared/counter")

try:
    # Only update if nobody else changed it since our read
    updated = client.put_cas(
        "shared/counter",
        {"count": record.value["count"] + 1},
        expected_version=record.version,
    )
    print(f"Updated to v{updated.version}")
except CasConflictError as e:
    print(f"Conflict! Expected v{e.expected_version}, got v{e.actual_version}")
    print(f"Current value: {e.current}")

Memory Layers

Akasha organizes knowledge into four cognitive layers:

from akasha import AkashaHttpClient, MemoryLayer

client = AkashaHttpClient("https://localhost:7777", verify_ssl=False)

# Working memory (volatile, 30 min TTL)
client.put(
    f"{MemoryLayer.WORKING.prefix}agent-1/scratch",
    {"current_task": "analyze"},
    ttl_seconds=MemoryLayer.WORKING.default_ttl_seconds,
)

# Episodic memory (event log, 24h TTL)
client.put(
    f"{MemoryLayer.EPISODIC.prefix}agent-1/events/2024-01-15",
    {"action": "summarized", "input_tokens": 4500},
    ttl_seconds=MemoryLayer.EPISODIC.default_ttl_seconds,
)

# Semantic memory (permanent knowledge)
client.put(
    f"{MemoryLayer.SEMANTIC.prefix}domain/users/preferences",
    {"theme": "dark", "language": "es"},
)

# Query all episodic memories
episodes = client.query(MemoryLayer.EPISODIC.glob_all)

Authentication

# API Key (recommended for agents)
client = AkashaHttpClient(
    "https://akasha.example.com",
    api_key="ak_live_abc123",
)

# JWT Token (for user sessions)
client = AkashaHttpClient(
    "https://akasha.example.com",
    token="eyJhbGciOiJIUzI1NiIs...",
)

Context Manager

with AkashaHttpClient("https://localhost:7777", verify_ssl=False) as client:
    client.put("test/hello", {"message": "world"})
    record = client.get("test/hello")
    print(record.value)
# Connection auto-closed

Async Support

import asyncio
from akasha import AsyncAkashaClient  # gRPC-based async client

async def main():
    async with AsyncAkashaClient("localhost:50051") as client:
        await client.put("agents/worker/status", {"busy": True})
        record = await client.get("agents/worker/status")
        print(record.value)

asyncio.run(main())

API Reference

AkashaHttpClient

Method Description
put(path, value, *, ttl_seconds, tags) Write a record
put_cas(path, value, *, expected_version, ...) Write with CAS concurrency control
get(path)Record | None Read a record
delete(path)bool Delete a record
query(pattern, *, limit)list[Record] Glob query
list_agents()list[dict] List registered agents
tree()dict Full state tree snapshot
health()dict Health check
metrics()dict Server metrics

Record

Field Type Description
path str Hierarchical path
value Any Stored value (auto JSON)
version int Monotonic version counter
created_at datetime Creation timestamp
updated_at datetime Last update timestamp
ttl_seconds float | None Time-to-live
tags dict[str, str] Key-value metadata

CasConflictError

Field Type Description
expected_version int Version you expected
actual_version int Server's current version
current dict Current record data

Requirements

  • Python ≥ 3.10
  • httpx ≥ 0.27 (HTTP client)
  • grpcio ≥ 1.60 (gRPC client)
  • msgpack ≥ 1.0 (serialization)

Links

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

akasha_client-1.0.8.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

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

akasha_client-1.0.8-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file akasha_client-1.0.8.tar.gz.

File metadata

  • Download URL: akasha_client-1.0.8.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for akasha_client-1.0.8.tar.gz
Algorithm Hash digest
SHA256 3f369c646e522bcb65f7a850aa3ed1e1bf9bf238af4f9e2f540c354a8caac046
MD5 a5ceb72ba9f099176242a4758a03f967
BLAKE2b-256 7527fbf3ce216de18304ba5389ca6f131058166fbac01562b3e0dd18572bd7d6

See more details on using hashes here.

File details

Details for the file akasha_client-1.0.8-py3-none-any.whl.

File metadata

  • Download URL: akasha_client-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for akasha_client-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 829a8790f3c176af9ad5708e497d70d85473212f1118951960deb3e514e2110a
MD5 6fc142d4152a6ea74e6315b4a13348b5
BLAKE2b-256 41daffb6ecaf12c7e258faa3589506a1f059a7ae4289ec3c18c137147a407f45

See more details on using hashes here.

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