radical-api/api.py

32 lines
710 B
Python
Raw Normal View History

import importlib
import logging
2021-08-17 02:51:42 +00:00
from pathlib import Path
from fastapi import FastAPI
2021-08-17 02:51:42 +00:00
logger = logging.getLogger("api")
2021-08-17 02:51:42 +00:00
api = FastAPI()
api_data = {"version": "2021.12.1.5", "author": "Riley Housden"}
2021-08-17 02:51:42 +00:00
def load_module(name: str):
module = importlib.import_module(name)
api.include_router(module.router)
logger.info(f"Loaded module: {module.__name__}")
2021-08-17 02:51:42 +00:00
for m_path in Path("routers").glob("*"):
if "__pycache__" in m_path.parts or "__init__" == m_path.stem:
continue
load_module(str(m_path).replace("/", ".").replace(".py", ""))
2021-08-17 02:51:42 +00:00
@api.get("/")
def quack():
return api_data
if __name__ == "__main__":
import uvicorn
api_data["version"] += "-dev"
uvicorn.run(api)