Commit
•
55877ba
1
Parent(s):
71757de
add caching with cashews
Browse files- main.py +3 -0
- requirements.in +3 -1
- requirements.txt +38 -3
main.py
CHANGED
@@ -5,6 +5,7 @@ from contextlib import asynccontextmanager
|
|
5 |
from typing import List
|
6 |
|
7 |
import numpy as np
|
|
|
8 |
from fastapi import FastAPI, HTTPException, Query
|
9 |
from pandas import Timestamp
|
10 |
from pydantic import BaseModel
|
@@ -12,6 +13,7 @@ from starlette.responses import RedirectResponse
|
|
12 |
|
13 |
from data_loader import refresh_data
|
14 |
|
|
|
15 |
logger = logging.getLogger(__name__)
|
16 |
|
17 |
|
@@ -123,6 +125,7 @@ class SearchResponse(BaseModel):
|
|
123 |
results: List[dict]
|
124 |
|
125 |
|
|
|
126 |
@app.get("/search", response_model=SearchResponse)
|
127 |
async def search_datasets(
|
128 |
columns: List[str] = Query(...),
|
|
|
5 |
from typing import List
|
6 |
|
7 |
import numpy as np
|
8 |
+
from cashews import NOT_NONE, cache
|
9 |
from fastapi import FastAPI, HTTPException, Query
|
10 |
from pandas import Timestamp
|
11 |
from pydantic import BaseModel
|
|
|
13 |
|
14 |
from data_loader import refresh_data
|
15 |
|
16 |
+
cache.setup("mem://?check_interval=10&size=10000")
|
17 |
logger = logging.getLogger(__name__)
|
18 |
|
19 |
|
|
|
125 |
results: List[dict]
|
126 |
|
127 |
|
128 |
+
@cache(ttl="1h", condition=NOT_NONE)
|
129 |
@app.get("/search", response_model=SearchResponse)
|
130 |
async def search_datasets(
|
131 |
columns: List[str] = Query(...),
|
requirements.in
CHANGED
@@ -2,4 +2,6 @@ huggingface_hub
|
|
2 |
pandas
|
3 |
python-dotenv
|
4 |
datasets
|
5 |
-
fastapi
|
|
|
|
|
|
2 |
pandas
|
3 |
python-dotenv
|
4 |
datasets
|
5 |
+
fastapi
|
6 |
+
piccolo[sqlite]
|
7 |
+
cashews[dill]
|
requirements.txt
CHANGED
@@ -6,6 +6,8 @@ aiohttp==3.9.5
|
|
6 |
# fsspec
|
7 |
aiosignal==1.3.1
|
8 |
# via aiohttp
|
|
|
|
|
9 |
annotated-types==0.7.0
|
10 |
# via pydantic
|
11 |
anyio==4.4.0
|
@@ -15,6 +17,10 @@ anyio==4.4.0
|
|
15 |
# watchfiles
|
16 |
attrs==23.2.0
|
17 |
# via aiohttp
|
|
|
|
|
|
|
|
|
18 |
certifi==2024.6.2
|
19 |
# via
|
20 |
# httpcore
|
@@ -24,18 +30,28 @@ charset-normalizer==3.3.2
|
|
24 |
# via requests
|
25 |
click==8.1.7
|
26 |
# via
|
|
|
27 |
# typer
|
28 |
# uvicorn
|
|
|
|
|
|
|
|
|
29 |
datasets==2.20.0
|
30 |
# via -r requirements.in
|
31 |
dill==0.3.8
|
32 |
# via
|
|
|
33 |
# datasets
|
34 |
# multiprocess
|
35 |
dnspython==2.6.1
|
36 |
# via email-validator
|
|
|
|
|
37 |
email-validator==2.2.0
|
38 |
-
# via
|
|
|
|
|
39 |
fastapi==0.111.0
|
40 |
# via -r requirements.in
|
41 |
fastapi-cli==0.0.4
|
@@ -73,8 +89,12 @@ idna==3.7
|
|
73 |
# httpx
|
74 |
# requests
|
75 |
# yarl
|
|
|
|
|
76 |
jinja2==3.1.4
|
77 |
-
# via
|
|
|
|
|
78 |
markdown-it-py==3.0.0
|
79 |
# via rich
|
80 |
markupsafe==2.1.5
|
@@ -87,6 +107,8 @@ multidict==6.0.5
|
|
87 |
# yarl
|
88 |
multiprocess==0.70.16
|
89 |
# via datasets
|
|
|
|
|
90 |
numpy==2.0.0
|
91 |
# via
|
92 |
# datasets
|
@@ -96,18 +118,27 @@ orjson==3.10.5
|
|
96 |
# via fastapi
|
97 |
packaging==24.1
|
98 |
# via
|
|
|
99 |
# datasets
|
100 |
# huggingface-hub
|
101 |
pandas==2.2.2
|
102 |
# via
|
103 |
# -r requirements.in
|
104 |
# datasets
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
pyarrow==16.1.0
|
106 |
# via datasets
|
107 |
pyarrow-hotfix==0.6
|
108 |
# via datasets
|
109 |
pydantic==2.7.4
|
110 |
-
# via
|
|
|
|
|
111 |
pydantic-core==2.18.4
|
112 |
# via pydantic
|
113 |
pygments==2.18.0
|
@@ -143,6 +174,8 @@ sniffio==1.3.1
|
|
143 |
# httpx
|
144 |
starlette==0.37.2
|
145 |
# via fastapi
|
|
|
|
|
146 |
tqdm==4.66.4
|
147 |
# via
|
148 |
# datasets
|
@@ -151,8 +184,10 @@ typer==0.12.3
|
|
151 |
# via fastapi-cli
|
152 |
typing-extensions==4.12.2
|
153 |
# via
|
|
|
154 |
# fastapi
|
155 |
# huggingface-hub
|
|
|
156 |
# pydantic
|
157 |
# pydantic-core
|
158 |
# typer
|
|
|
6 |
# fsspec
|
7 |
aiosignal==1.3.1
|
8 |
# via aiohttp
|
9 |
+
aiosqlite==0.20.0
|
10 |
+
# via piccolo
|
11 |
annotated-types==0.7.0
|
12 |
# via pydantic
|
13 |
anyio==4.4.0
|
|
|
17 |
# watchfiles
|
18 |
attrs==23.2.0
|
19 |
# via aiohttp
|
20 |
+
black==24.4.2
|
21 |
+
# via piccolo
|
22 |
+
cashews==7.1.0
|
23 |
+
# via -r requirements.in
|
24 |
certifi==2024.6.2
|
25 |
# via
|
26 |
# httpcore
|
|
|
30 |
# via requests
|
31 |
click==8.1.7
|
32 |
# via
|
33 |
+
# black
|
34 |
# typer
|
35 |
# uvicorn
|
36 |
+
colorama==0.4.6
|
37 |
+
# via
|
38 |
+
# piccolo
|
39 |
+
# targ
|
40 |
datasets==2.20.0
|
41 |
# via -r requirements.in
|
42 |
dill==0.3.8
|
43 |
# via
|
44 |
+
# cashews
|
45 |
# datasets
|
46 |
# multiprocess
|
47 |
dnspython==2.6.1
|
48 |
# via email-validator
|
49 |
+
docstring-parser==0.16
|
50 |
+
# via targ
|
51 |
email-validator==2.2.0
|
52 |
+
# via
|
53 |
+
# fastapi
|
54 |
+
# pydantic
|
55 |
fastapi==0.111.0
|
56 |
# via -r requirements.in
|
57 |
fastapi-cli==0.0.4
|
|
|
89 |
# httpx
|
90 |
# requests
|
91 |
# yarl
|
92 |
+
inflection==0.5.1
|
93 |
+
# via piccolo
|
94 |
jinja2==3.1.4
|
95 |
+
# via
|
96 |
+
# fastapi
|
97 |
+
# piccolo
|
98 |
markdown-it-py==3.0.0
|
99 |
# via rich
|
100 |
markupsafe==2.1.5
|
|
|
107 |
# yarl
|
108 |
multiprocess==0.70.16
|
109 |
# via datasets
|
110 |
+
mypy-extensions==1.0.0
|
111 |
+
# via black
|
112 |
numpy==2.0.0
|
113 |
# via
|
114 |
# datasets
|
|
|
118 |
# via fastapi
|
119 |
packaging==24.1
|
120 |
# via
|
121 |
+
# black
|
122 |
# datasets
|
123 |
# huggingface-hub
|
124 |
pandas==2.2.2
|
125 |
# via
|
126 |
# -r requirements.in
|
127 |
# datasets
|
128 |
+
pathspec==0.12.1
|
129 |
+
# via black
|
130 |
+
piccolo==1.13.0
|
131 |
+
# via -r requirements.in
|
132 |
+
platformdirs==4.2.2
|
133 |
+
# via black
|
134 |
pyarrow==16.1.0
|
135 |
# via datasets
|
136 |
pyarrow-hotfix==0.6
|
137 |
# via datasets
|
138 |
pydantic==2.7.4
|
139 |
+
# via
|
140 |
+
# fastapi
|
141 |
+
# piccolo
|
142 |
pydantic-core==2.18.4
|
143 |
# via pydantic
|
144 |
pygments==2.18.0
|
|
|
174 |
# httpx
|
175 |
starlette==0.37.2
|
176 |
# via fastapi
|
177 |
+
targ==0.4.0
|
178 |
+
# via piccolo
|
179 |
tqdm==4.66.4
|
180 |
# via
|
181 |
# datasets
|
|
|
184 |
# via fastapi-cli
|
185 |
typing-extensions==4.12.2
|
186 |
# via
|
187 |
+
# aiosqlite
|
188 |
# fastapi
|
189 |
# huggingface-hub
|
190 |
+
# piccolo
|
191 |
# pydantic
|
192 |
# pydantic-core
|
193 |
# typer
|