memra-local 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ """Memra Local — offline memory server for AI agents."""
2
+
3
+ __version__ = "0.2.0"
@@ -0,0 +1,6 @@
1
+ """Entry point for `python -m memra_local`."""
2
+
3
+ from memra_local.cli import cli
4
+
5
+ if __name__ == "__main__":
6
+ cli()
memra_local/app.py ADDED
@@ -0,0 +1,65 @@
1
+ """FastAPI application factory with lifespan for memra-local."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from contextlib import asynccontextmanager
6
+ from pathlib import Path
7
+ from typing import AsyncIterator
8
+
9
+ from fastapi import FastAPI
10
+
11
+ from memra_local import __version__
12
+ from memra_local.config import resolve_scope
13
+ from memra_local.routes import bootstrap, memories, search
14
+ from memra_local.services.factory import create_service
15
+
16
+
17
+ def create_app(
18
+ scope: str = "auto",
19
+ storage_dir: Path | None = None,
20
+ ) -> FastAPI:
21
+ """Create and configure the FastAPI application.
22
+
23
+ Args:
24
+ scope: Storage scope -- "global", "project", or "auto".
25
+ storage_dir: Override storage directory (used by tests).
26
+
27
+ Returns:
28
+ Configured FastAPI app with service on app.state.service.
29
+ """
30
+ resolved_scope = resolve_scope(scope) if storage_dir is None else scope
31
+
32
+ # Use shared factory for service creation (same as MCP server)
33
+ service = create_service(scope=scope, storage_dir=storage_dir)
34
+
35
+ @asynccontextmanager
36
+ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
37
+ """Index is already initialized by factory; just handle shutdown."""
38
+ yield
39
+ service.index.close()
40
+
41
+ app = FastAPI(
42
+ title="Memra Local",
43
+ version=__version__,
44
+ description="Local memory server for AI agents",
45
+ lifespan=lifespan,
46
+ )
47
+
48
+ # Store service on app state for route access
49
+ app.state.service = service
50
+
51
+ # Include routers with /v1 prefix
52
+ app.include_router(memories.router, prefix="/v1")
53
+ app.include_router(search.router, prefix="/v1")
54
+ app.include_router(bootstrap.router, prefix="/v1")
55
+
56
+ # Health endpoint (no prefix)
57
+ @app.get("/health")
58
+ def health():
59
+ return {
60
+ "status": "healthy",
61
+ "version": __version__,
62
+ "scope": resolved_scope,
63
+ }
64
+
65
+ return app