Skip to content

🐍 Python API

SpecMem provides a comprehensive Python API for programmatic access.

Installation

pip install specmem

Quick Start

from specmem import SpecMemClient

# Initialize client
sm = SpecMemClient()

# Query specifications
results = sm.query("authentication")

# Get context for changes
bundle = sm.get_context_for_change(["auth/service.py"])

# Analyze impact
impacted = sm.get_impacted_specs(["auth/service.py"])

# Validate specs
issues = sm.validate()

Core Classes

🔌 SpecMemClient

Main entry point for all SpecMem operations.

Reference →

🧠 Memory Bank

Vector-based specification storage and retrieval.

Reference →

🗄️ Vector Stores

Backend storage implementations.

Reference →

🔌 Adapters

Framework-specific spec parsers.

Reference →

🔋 Power Adapter

Parse Kiro Power configurations.

Reference →

🔌 MCP Server

Model Context Protocol server for Kiro.

Reference →

📊 Impact Graph

Relationship tracking and analysis.

Reference →

💚 Health Score

Project health scoring and improvement suggestions.

Reference →

📈 Coverage

Spec coverage analysis and test suggestions.

Reference →

♻️ Lifecycle

Spec health, pruning, generation, and compression.

Reference →

🔧 Kiro Config

Index steering files, MCP servers, and hooks.

Reference →

Data Classes

SpecBlock

from specmem.core import SpecBlock, SpecType, Lifecycle, Priority

spec = SpecBlock(
    id="auth-001",
    path="auth/requirements.md",
    framework="kiro",
    spec_type=SpecType.REQUIREMENT,
    title="User Authentication",
    content="...",
    summary="JWT-based authentication",
    tags=["auth", "security"],
    lifecycle=Lifecycle.ACTIVE,
    priority=Priority.CRITICAL,
)

ContextBundle

from specmem.client import ContextBundle

bundle = sm.get_context_for_change(["auth/service.py"])

print(bundle.tldr)              # Brief summary
print(bundle.specs)             # Relevant specs
print(bundle.pinned)            # Pinned specs
print(bundle.impacted)          # Impacted specs
print(bundle.recommended_tests) # Tests to run
print(bundle.warnings)          # Validation warnings

QueryResult

from specmem.client import QueryResult

results = sm.query("authentication", top_k=5)

for result in results:
    print(result.spec)      # SpecBlock
    print(result.score)     # Similarity score (0-1)
    print(result.highlights) # Matching text highlights

Async Support

import asyncio
from specmem import AsyncSpecMemClient

async def main():
    sm = AsyncSpecMemClient()

    results = await sm.query("authentication")
    bundle = await sm.get_context_for_change(["auth/service.py"])

asyncio.run(main())

Type Hints

SpecMem is fully typed. Enable type checking in your IDE:

from specmem import SpecMemClient
from specmem.core import SpecBlock

sm: SpecMemClient = SpecMemClient()
specs: list[SpecBlock] = sm.get_all_specs()