API reference¶
Generated from the apogee-ai-templates source with mkdocstrings. Every symbol below is exported from apogee_ai_templates, so it is part of the supported public surface.
Application¶
RenderedFile
dataclass
¶
Application · DTOs¶
BenchDTO
dataclass
¶
RenderDTO
dataclass
¶
ScaffoldDTO
dataclass
¶
Python
ScaffoldDTO(blueprint_code: str, output_dir: str, variables: dict[str, str] = dict(), renderer: str = 'simple')
variables
class-attribute
instance-attribute
¶
Application · Use cases¶
BenchRenderUseCase
¶
execute
async
¶
Source code in apogee_ai_templates/application/use_cases/bench_render_use_case.py
Python
async def execute(self, renders: int) -> dict[str, float]:
if renders <= 0:
raise ValueError("renders must be positive")
renderer = SimpleRenderer()
ctx = RenderContext(variables={
"name": "Madson", "product": "apogee", "version": "0.1.0",
})
start = time.perf_counter()
for _ in range(renders):
renderer.render(_TEMPLATE, ctx)
elapsed = (time.perf_counter() - start) * 1000.0
return {
"renders": float(renders),
"elapsed_ms": elapsed,
"renders_per_second": (renders / elapsed * 1000.0) if elapsed > 0 else 0.0,
}
ListBlueprintsUseCase
¶
Source code in apogee_ai_templates/application/use_cases/list_templates_use_case.py
execute
async
¶
ListTemplatesUseCase
¶
Source code in apogee_ai_templates/application/use_cases/list_templates_use_case.py
execute
async
¶
RenderTemplateUseCase
¶
Source code in apogee_ai_templates/application/use_cases/render_template_use_case.py
execute
async
¶
Python
execute(name: str, context: RenderContext) -> str
Source code in apogee_ai_templates/application/use_cases/render_template_use_case.py
ScaffoldProjectUseCase
¶
Renders every TemplateFile of a Blueprint into RenderedFiles.
Renders both file paths and bodies through the same renderer so paths
can use placeholders like {{project_name}}/main.py.
Source code in apogee_ai_templates/application/use_cases/scaffold_project_use_case.py
execute
async
¶
Python
execute(blueprint_code: str, context: RenderContext) -> list[RenderedFile]
Source code in apogee_ai_templates/application/use_cases/scaffold_project_use_case.py
Python
async def execute(
self, blueprint_code: str, context: RenderContext
) -> list[RenderedFile]:
blueprint = self._blueprints.get(blueprint_code)
for required in blueprint.required_vars:
if required not in context.variables:
raise MissingVariableError(required)
out: list[RenderedFile] = []
for f in blueprint.files:
rendered_path = self._renderer.render(f.path, context)
rendered_body = self._renderer.render(f.template, context)
out.append(RenderedFile(
path=rendered_path,
content=rendered_body,
executable=f.executable,
))
return out
Domain¶
Blueprint
dataclass
¶
Python
Blueprint(code: str, name: str, kind: BlueprintKind = CUSTOM, description: str = '', files: tuple[TemplateFile, ...] = (), required_vars: tuple[str, ...] = (), metadata: dict[str, str] = dict())
metadata
class-attribute
instance-attribute
¶
Template
dataclass
¶
Python
Template(name: str, body: str, description: str = '', required_vars: tuple[str, ...] = (), metadata: dict[str, str] = dict())
metadata
class-attribute
instance-attribute
¶
TemplateFile
dataclass
¶
Domain · Enums¶
BlueprintKind
¶
Bases: str, Enum
RendererKind
¶
Domain · Exceptions¶
BlueprintNotFoundException
¶
MissingVariableError
¶
TemplateError
¶
Bases: Exception
Base for apogee-ai-templates errors.
TemplateNotFoundException
¶
Domain · Protocols (ports)¶
IBlueprintRepository
¶
IRenderer
¶
Bases: Protocol
render
¶
Python
render(source: str, context: RenderContext) -> str
ITemplateRepository
¶
Infrastructure¶
BlueprintRegistry
¶
Python
BlueprintRegistry(blueprints: Iterable[Blueprint] = ())
InMemoryTemplateRepository
¶
Python
InMemoryTemplateRepository(templates: Iterable[Template] | None = None)
JinjaRenderer
¶
Lazy Jinja2 adapter — install via extras=jinja.
Source code in apogee_ai_templates/infrastructure/renderers/jinja_renderer.py
render
¶
Python
render(source: str, context: RenderContext) -> str
Source code in apogee_ai_templates/infrastructure/renderers/jinja_renderer.py
Python
def render(self, source: str, context: RenderContext) -> str:
self._ensure_env()
try:
template = self._env.from_string(source) # type: ignore[union-attr]
return template.render(**context.variables)
except Exception as exc: # pragma: no cover - depends on Jinja
try:
from jinja2 import UndefinedError # type: ignore
if isinstance(exc, UndefinedError):
raise MissingVariableError(str(exc)) from exc
except ImportError:
pass
raise TemplateError(str(exc)) from exc
SimpleRenderer
¶
{{var}} substitution. No control flow, no escapes — keeps blueprints
readable and deterministic. Strict mode raises MissingVariableError on
unknown placeholder; lenient mode leaves it untouched.
render
¶
Python
render(source: str, context: RenderContext) -> str
Source code in apogee_ai_templates/infrastructure/renderers/simple_renderer.py
Python
def render(self, source: str, context: RenderContext) -> str:
def _resolve(match: re.Match[str]) -> str:
key = match.group(1)
value = context.variables.get(key)
if value is None:
if context.strict:
raise MissingVariableError(key)
return match.group(0)
return str(value)
return _PLACEHOLDER.sub(_resolve, source)