fixed dockerfile, added fastapi

This commit is contained in:
2025-11-24 16:35:06 +03:00
parent 908b2e870d
commit 23e8b71776
5 changed files with 64 additions and 81 deletions

40
src/app.py Normal file
View File

@@ -0,0 +1,40 @@
from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from fastapi import FastAPI
from starlette.requests import Request
from starlette.responses import Response
from fastapi_cache import FastAPICache
from fastapi_cache.backends.redis import RedisBackend
from fastapi_cache.decorator import cache
from redis import asyncio as aioredis
from openbabel import pybel
@asynccontextmanager
async def lifespan(_: FastAPI) -> AsyncIterator[None]:
redis = aioredis.from_url("redis://localhost")
FastAPICache.init(RedisBackend(redis), prefix="fastapi-cache")
yield
app = FastAPI(lifespan=lifespan)
@app.get("/informats")
async def get_informats():
return pybel.informats
@app.get("/")
@cache(expire=60)
async def index():
return dict(hello="world")