-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path4_override_max_staleness.py
38 lines (30 loc) · 1.06 KB
/
4_override_max_staleness.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
import requests
from chalk import online
from chalk.client import ChalkClient
from chalk.features import feature, features
@features
class User:
id: int
name: str
fico_score: int = feature(max_staleness="30d")
@online
def get_fico_score(name: User.name) -> User.fico_score:
return requests.get(...).json()["score"]
if __name__ == "__main__":
# By default, the staleness will be taken to be the value given
# on the feature class. In this case, user.fico_score is cached
# for 30 days. But if you have a model that needs fresher data,
# you can specify the desired staleness at the time of making
# the query. For example, here we request a staleness of only
# 10 minutes.
ChalkClient().query(
input={User.name: "Katherine Johnson"},
output=[User.fico_score],
staleness={User.fico_score: "10m"},
)
# If you didn't specify the staleness, the default staleness
# of 30 days would apply
ChalkClient().query(
input={User.name: "Katherine Johnson"},
output=[User.fico_score],
)