-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathus_enrichment_example.py
More file actions
80 lines (58 loc) · 3.02 KB
/
us_enrichment_example.py
File metadata and controls
80 lines (58 loc) · 3.02 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
from smartystreets_python_sdk import SharedCredentials, BasicAuthCredentials, exceptions, ClientBuilder
from smartystreets_python_sdk.us_enrichment.lookup import Lookup as EnrichmentLookup
def run():
# key = "Your SmartyStreets Key here"
# hostname = "Your Hostname here"
# We recommend storing your secret keys in environment variables instead---it's safer!
# for client-side requests (browser/mobile), use this code:
# key = os.environ['SMARTY_AUTH_WEB']
# hostname = os.environ['SMARTY_WEBSITE_DOMAIN']
#
# credentials = SharedCredentials(key, hostname)
# for server-to-server requests, use this code:
auth_id = os.environ['SMARTY_AUTH_ID']
auth_token = os.environ['SMARTY_AUTH_TOKEN']
credentials = BasicAuthCredentials(auth_id, auth_token)
client = ClientBuilder(credentials).build_us_enrichment_api_client()
# client = ClientBuilder(credentials).with_custom_header({'User-Agent': 'smartystreets (python@0.0.0)', 'Content-Type': 'application/json'}).build_us_enrichment_api_client()
# client = ClientBuilder(credentials).with_http_proxy('localhost:8080', 'user', 'password').build_us_street_api_client()
# Uncomment the line above to try it with a proxy instead
smarty_key = "87844267"
lookup = EnrichmentLookup()
freeform_lookup = EnrichmentLookup()
lookup.smartykey = smarty_key
# lookup.street = "56 Union Ave"
# lookup.city = "Somerville"
# lookup.state = "NJ"
# lookup.zipcode = "08876"
lookup.features = "financial"
# Uncomment the below lines to add attributes to the "include" parameter
# lookup.add_include_attribute('assessed_improvement_percent')
# lookup.add_include_attribute('assessed_improvement_value')
# Uncomment the below lines to add attributes to the "exclude" parameter
# lookup.add_exclude_attribute('assessed_land_value')
# lookup.add_exclude_attribute('assessed_value')
# Uncomment the below line to add a custom parameter
# lookup.add_custom_parameter("parameter", "value")
freeform_lookup.freeform = "56 Union Ave Somerville NJ 08876"
try:
# use the below line to send a lookup with a smarty key
# results = client.send_property_principal_lookup(smarty_key)
# Or, uncomment the below line to send a lookup with an address in components
results = client.send_property_principal_lookup(lookup)
# Or, uncomment the below line to send a lookup with an address in freeform
# results = client.send_property_principal_lookup(freeform_lookup)
# results = client.send_generic_lookup(smarty_key, 'property', 'principal')
# Uncomment the line above to try it as a generic lookup instead
except Exception as err:
print(err)
return
if not results:
print("No results found. This means the Smartykey or address is likely not valid, or does not have data in this dataset")
return
top_result = results[0]
print("Here is your result!")
print(top_result)
if __name__ == "__main__":
run()