api-uses-lazy-imports
IN premise
Heavy modules (`derive`, `compact`, `export_markdown`, `check_stale`, `import_beliefs`, `import_agent`) are imported inside function bodies in `api.py`, not at module level, to keep the module fast to import for callers that only need a subset of operations.
Summary
The API module deliberately delays loading its heaviest dependencies until they are actually needed, rather than pulling everything in up front. This means tools or scripts that only use a few operations from the API stay fast to start up, avoiding the cost of initializing code paths they never call.
Dependents
These beliefs depend on this one:
- startup-performance-uses-lazy-loading — Both the API and CLI layers defer importing heavy modules (derive, compact, ask, asyncio, Storage) to function bodies rather than module top-level, minimizing import-time overhead for CLI responsiveness.
Details
| Source | entries/2026/04/24/reasons_lib-api.md |