🐍 Python API¶
SpecMem provides a comprehensive Python API for programmatic access.
Installation¶
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¶
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: