-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathinternational_postal_code_example.py
More file actions
69 lines (53 loc) · 2.63 KB
/
Copy pathinternational_postal_code_example.py
File metadata and controls
69 lines (53 loc) · 2.63 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
import os
from smartystreets_python_sdk import BasicAuthCredentials, ClientBuilder, SharedCredentials
from smartystreets_python_sdk.international_postal_code import Lookup
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_international_postal_code_api_client()
# Documentation for input fields can be found at:
# https://smartystreets.com/docs/cloud/international-postal-code-api
lookup = Lookup()
lookup.input_id = "ID-8675309"
lookup.locality = "Sao Paulo"
lookup.administrative_area = "SP"
lookup.country = "Brazil"
lookup.postal_code = "02516"
candidates = client.send(lookup) # The candidates are also stored in the lookup's 'results' field.
print("Results:")
print()
for idx, candidate in enumerate(candidates):
print("Candidate: {}".format(idx))
if candidate.input_id:
print(" input_id: {}".format(candidate.input_id))
if candidate.country_iso_3:
print(" country_iso_3: {}".format(candidate.country_iso_3))
if candidate.locality:
print(" locality: {}".format(candidate.locality))
if candidate.dependent_locality:
print(" dependent_locality: {}".format(candidate.dependent_locality))
if candidate.double_dependent_locality:
print(" double_dependent_locality: {}".format(candidate.double_dependent_locality))
if candidate.sub_administrative_area:
print(" sub_administrative_area: {}".format(candidate.sub_administrative_area))
if candidate.administrative_area:
print(" administrative_area: {}".format(candidate.administrative_area))
if candidate.super_administrative_area:
print(" super_administrative_area: {}".format(candidate.super_administrative_area))
if candidate.postal_code:
print(" postal_code: {}".format(candidate.postal_code))
if candidate.postal_code_extra:
print(" postal_code_extra: {}".format(candidate.postal_code_extra))
print()
if __name__ == "__main__":
run()