forked from nanotaboada/python-samples-fastapi-restful
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
27 lines (21 loc) · 927 Bytes
/
main.py
File metadata and controls
27 lines (21 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# ------------------------------------------------------------------------------
# Main
# ------------------------------------------------------------------------------
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi_cache import FastAPICache
from fastapi_cache.backends.inmemory import InMemoryBackend
from routes import player_route
@asynccontextmanager
async def lifespan_context_manager(_):
"""
Context manager for the FastAPI app lifespan.
Initializes FastAPICache with an InMemoryBackend for the duration of the app's lifespan.
"""
FastAPICache.init(InMemoryBackend())
yield
app = FastAPI(lifespan=lifespan_context_manager,
title="python-samples-fastapi-restful",
description="🧪 Proof of Concept for a RESTful API made with Python 3 and FastAPI",
version="1.0.0",)
app.include_router(player_route.api_router)