diff --git a/pyproject.toml b/pyproject.toml index 9a2030fc..9ba03153 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,10 +3,13 @@ name = "lightspeed-stack" version = "0.1.0" description = "LLM tooling stack" authors = [] -dependencies = [] requires-python = ">=3.11.1,<=3.12.10" readme = "README.md" license = {file = "LICENSE"} +dependencies = [ + "fastapi>=0.115.6", + "uvicorn>=0.32.1", +] [project.urls] Homepage = "https://github.com/lightspeed-core/lightspeed-stack" @@ -19,3 +22,6 @@ distribution = true dev = [ "black>=25.1.0" ] + +[tool.pdm.scripts] +start = "pdm run make run" diff --git a/src/app/__init__.py b/src/app/__init__.py new file mode 100644 index 00000000..0c4860b1 --- /dev/null +++ b/src/app/__init__.py @@ -0,0 +1 @@ +"""REST API service based on FastAPI.""" diff --git a/src/app/endpoints/info.py b/src/app/endpoints/info.py new file mode 100644 index 00000000..b843f683 --- /dev/null +++ b/src/app/endpoints/info.py @@ -0,0 +1,18 @@ +"""Handler for REST API call to provide info.""" + +import asyncio +import logging +from typing import Any, Optional + +from fastapi import APIRouter, Request + +logger = logging.getLogger(__name__) +router = APIRouter(tags=["info"]) + + +@router.get("/info") +def info_endpoint_handler(request: Request) -> dict: + return { + "foo": 1, + "bar": 2, + } diff --git a/src/app/main.py b/src/app/main.py new file mode 100644 index 00000000..607d3413 --- /dev/null +++ b/src/app/main.py @@ -0,0 +1,15 @@ +from fastapi import FastAPI, Request, Response +from app import routers +import version + +app = FastAPI( + title="Swagger service - OpenAPI", + description=f" service API specification.", + version=version.__version__, + license_info={ + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html", + }, +) + +routers.include_routers(app) diff --git a/src/app/routers.py b/src/app/routers.py new file mode 100644 index 00000000..f071347c --- /dev/null +++ b/src/app/routers.py @@ -0,0 +1,16 @@ +"""REST API routers.""" + +from fastapi import FastAPI + +from app.endpoints import ( + info, +) + + +def include_routers(app: FastAPI) -> None: + """Include FastAPI routers for different endpoints. + + Args: + app: The `FastAPI` app instance. + """ + app.include_router(info.router, prefix="/v1") diff --git a/src/lightspeed-stack.py b/src/lightspeed-stack.py index 478915ff..33414c24 100644 --- a/src/lightspeed-stack.py +++ b/src/lightspeed-stack.py @@ -1,4 +1,8 @@ """Lightspeed stack.""" +from runners.uvicorn import start_uvicorn +import version + if __name__ == "__main__": print("Lightspeed stack") + start_uvicorn() diff --git a/src/runners/uvicorn.py b/src/runners/uvicorn.py new file mode 100644 index 00000000..fde90d84 --- /dev/null +++ b/src/runners/uvicorn.py @@ -0,0 +1,23 @@ +"""Uvicorn runner.""" + +import logging + +import uvicorn + +logger: logging.Logger = logging.getLogger(__name__) + + +def start_uvicorn() -> None: + """Start Uvicorn-based REST API service.""" + logger.info("Starting Uvicorn") + + host = "localhost" + port = 8080 + workers = 1 + + uvicorn.run( + "app.main:app", + host=host, + port=port, + workers=workers, + ) diff --git a/src/version.py b/src/version.py new file mode 100644 index 00000000..19242fdf --- /dev/null +++ b/src/version.py @@ -0,0 +1,4 @@ +"""Service version that is read by project manager tools.""" + +# this should be the only version value used in all source codes!!! +__version__ = "0.0.1"