Skip to content

Commit d2fb048

Browse files
feat: Add /write-to-online-store method to the python feature server (#2423)
Signed-off-by: Tomas Pereira de Vasconcelos <tomasvasconcelos1@gmail.com>
1 parent 70d4a13 commit d2fb048

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

sdk/python/feast/feature_server.py

+32
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1+
import json
12
import traceback
3+
import warnings
24

5+
import pandas as pd
36
import uvicorn
47
from fastapi import FastAPI, HTTPException, Request
58
from fastapi.logger import logger
69
from fastapi.params import Depends
710
from google.protobuf.json_format import MessageToDict, Parse
11+
from pydantic import BaseModel
812

913
import feast
1014
from feast import proto_json
1115
from feast.protos.feast.serving.ServingService_pb2 import GetOnlineFeaturesRequest
1216

1317

18+
class WriteToFeatureStoreRequest(BaseModel):
19+
feature_view_name: str
20+
df: dict
21+
allow_registry_cache: bool = True
22+
23+
1424
def get_app(store: "feast.FeatureStore"):
1525
proto_json.patch()
1626

@@ -58,6 +68,28 @@ def get_online_features(body=Depends(get_body)):
5868
# Raise HTTPException to return the error message to the client
5969
raise HTTPException(status_code=500, detail=str(e))
6070

71+
@app.post("/write-to-online-store")
72+
def write_to_online_store(body=Depends(get_body)):
73+
warnings.warn(
74+
"write_to_online_store is an experimental feature. "
75+
"This API is unstable and it could be changed in the future. "
76+
"We do not guarantee that future changes will maintain backward compatibility.",
77+
RuntimeWarning,
78+
)
79+
try:
80+
request = WriteToFeatureStoreRequest(**json.loads(body))
81+
df = pd.DataFrame(request.df)
82+
store.write_to_online_store(
83+
feature_view_name=request.feature_view_name,
84+
df=df,
85+
allow_registry_cache=request.allow_registry_cache,
86+
)
87+
except Exception as e:
88+
# Print the original exception on the server side
89+
logger.exception(traceback.format_exc())
90+
# Raise HTTPException to return the error message to the client
91+
raise HTTPException(status_code=500, detail=str(e))
92+
6193
return app
6294

6395

0 commit comments

Comments
 (0)