-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhttp_server.py
More file actions
44 lines (33 loc) · 1.17 KB
/
http_server.py
File metadata and controls
44 lines (33 loc) · 1.17 KB
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
from pydantic import BaseModel
import iarray as ia
from fastapi import FastAPI, Response, HTTPException
import numpy as np
from iarray import iarray_ext as ext
app = FastAPI()
class Get_block(BaseModel):
array_id: str
nchunk: int
start: int
nitems: int
size: int
@app.get("/v1/catalog/")
async def catalog():
return list(ia.global_catalog.keys())
@app.get("/v1/meta/")
async def meta(array_id: str):
cat = ia.global_catalog
if array_id not in cat.keys():
raise HTTPException(status_code=404, detail=array_id + " not in catalog")
arr = cat[array_id]
return {"shape": arr.shape, "chunks": arr.chunks, "blocks": arr.blocks, "dtype": np.dtype(arr.dtype).str}
@app.post("/v1/blocks/")
async def blocks(params: Get_block):
cat = ia.global_catalog
if params.array_id not in cat.keys():
raise HTTPException(status_code=404, detail=cat[params.array_id] + " not in catalog")
iarr = cat[params.array_id]
try:
res = ext._server_job(iarr, params.nchunk, params.start, params.nitems, params.size)
except:
raise HTTPException(status_code=500, detail="could not get the block")
return Response(content=res)