-
Notifications
You must be signed in to change notification settings - Fork 1
/
3_bureau_api.py
66 lines (54 loc) · 1.64 KB
/
3_bureau_api.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
"""An example of connecting Users to Credit Reports from a
third part API.
In this example, we are getting Credit Reports for our
users through a third party API. This example shows how
you can run arbitrary python code (and connect to third
party APIs) in a python resolver.
"""
import os
import requests
from chalk import online
from chalk.features import features, has_many, DataFrame, Primary
@features
class CreditReport:
# if a feature doesn't have an id field, the Primary key must be specified
report_id: Primary[str]
user_id: "User.id"
# The raw report, which we'll save as a plain string
# to parse and extract later.
report: str
@features
class User:
id: int
first_name: str
last_name: str
# Adds the pii tag to the ssn feature (https://docs.chalk.ai/docs/feature-discovery#tags)
# :tags: pii
ssn: str
city: str
state: str
credit_report: DataFrame[CreditReport]
# Inject a secret through the Chalk dashboard (https://docs.chalk.ai/docs/env-vars)
url = os.getenv("MY_VENDOR_URL")
@online
def get_credit_report(
first_name: User.first_name,
last_name: User.last_name,
city: User.city,
state: User.state,
id: User.id,
) -> CreditReport:
"""
This resolver populates the credit report feature for a user by making a request to
a third party API.
"""
res = requests.get(
f"{url}/transunion/credit-report",
json={
"firstName": first_name,
"lastName": last_name,
"city": city,
"state": state,
},
).json()
return CreditReport(user_id=id, report_id=res["pdfReportId"], report=res["data"])