Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/sciwyrm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
from typing import Annotated

import uvicorn
from fastapi import Depends, FastAPI, Request, Response
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse
Expand All @@ -22,10 +23,17 @@
app = FastAPI()


@app.get("/notebook/templates", response_description="Available templates")
@app.get("/livez", response_description="The service is alive")
async def livez() -> str:
"""Return 200 if the serve is alive."""
return "ok"


@app.get("/templates", response_description="Available templates")
async def list_templates(
config: Annotated[AppConfig, Depends(app_config)]
) -> list[notebook.TemplateSummary]:
"""Return a list of all available templates."""
"""Return a list of available notebook templates."""
return notebook.available_templates(config)

Expand Down Expand Up @@ -56,7 +64,7 @@ async def template_schema(


@app.post("/notebook", response_model=dict, response_description="Rendered notebook")
async def format_notebook(
async def format_notebook_from_json(
request: Request,
templates: Annotated[Jinja2Templates, Depends(get_templates)],
spec: notebook.NotebookSpecWithConfig = Depends(_inject_app_config), # noqa: B008
Expand All @@ -70,3 +78,7 @@ async def format_notebook(
nb = json.loads(formatted.body)
notebook.insert_notebook_metadata(nb, spec)
return JSONResponse(nb)


if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
Loading