-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·66 lines (55 loc) · 1.97 KB
/
main.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/python3
# fast api
from contextlib import asynccontextmanager
from fastapi import Depends, FastAPI, Security
from fastapi.middleware.cors import CORSMiddleware
from fastapi_limiter import FastAPILimiter
from fastapi_limiter.depends import RateLimiter
from thedig.__about__ import __author__, __copyright__, __email__, __license__, __summary__, __title__, __version__
from thedig.api import ar, router
from thedig.api.config import settings, setup_cache
# import other apis
from thedig.api.logsetup import setup_logger_from_settings
from thedig.security import get_api_key
@asynccontextmanager
async def lifespan(app: FastAPI):
setup_logger_from_settings(log_level=settings.log_level)
ar.cache = await setup_cache(settings, db=settings.cache_redis_db_person)
ar.cache_expiration = settings.cache_expiration_person
await FastAPILimiter.init(await setup_cache(settings, db=settings.cache_redis_db))
yield
# routing composition
app = FastAPI(
debug=bool(settings.log_level == "DEBUG"),
title=__title__,
summary=__summary__,
version=__version__,
contact={"name": f"{__author__} - {__copyright__}", "email": __email__},
license_info={"name": __license__},
dependencies=[
Security(get_api_key),
Depends(RateLimiter(times=settings.max_requests_times, seconds=settings.max_requests_seconds)),
],
lifespan=lifespan,
terms_of_service="https://github.com/ankaboot-source/thedig/",
openapi_tags=[
{
"name": "archaeology",
"description": "🧩➜👤 enrich __iteratively__ data,\
every enriched data could be potentially used to excavator more data",
},
{
"name": "person",
"description": "Enrich **person**",
},
{
"name": "company",
"description": "Extract **company** related info.",
},
],
)
app.add_middleware(
CORSMiddleware,
allow_credentials=True,
)
app.include_router(router)