From dd9555cfba44ab5534d6c1ee9433bf3439dd0073 Mon Sep 17 00:00:00 2001 From: Mae Evans Date: Mon, 8 Jun 2026 13:19:42 -0600 Subject: [PATCH 1/3] Integrated the business_name input field --- .../USEnrichmentBusinessNameSearchExample.py | 68 +++++++++++++++++++ .../us_enrichment/client.py | 2 +- .../us_enrichment/lookup.py | 3 +- test/us_enrichment/business_summary_test.py | 26 +++++++ 4 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 examples/USEnrichmentBusinessNameSearchExample.py diff --git a/examples/USEnrichmentBusinessNameSearchExample.py b/examples/USEnrichmentBusinessNameSearchExample.py new file mode 100644 index 0000000..cf1a60e --- /dev/null +++ b/examples/USEnrichmentBusinessNameSearchExample.py @@ -0,0 +1,68 @@ +import os + +from smartystreets_python_sdk import BasicAuthCredentials, ClientBuilder +from smartystreets_python_sdk.us_enrichment import BusinessLookup + + +def run(): + 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() + + # Business summary SEARCH path: no smartykey, set freeform (+ optional city) + # and business_name to narrow the search to a specific business. + lookup = BusinessLookup() + lookup.freeform = "1600 amphitheatre pkwy mountain view ca" + lookup.business_name = "Google" + + try: + summary_results = client.send_business_lookup(lookup) + except Exception as err: + print(err) + return + + if not summary_results: + print("No matching businesses returned") + return + + summary = summary_results[0] + if not summary.businesses: + print("No business tenants matched the search") + return + + print("Matching businesses for business_name '{}':".format(lookup.business_name)) + for biz in summary.businesses: + print(" - {} (ID: {})".format(biz.company_name, biz.business_id)) + + first = summary.businesses[0] + print("\nFetching details for business: {} (ID: {})".format(first.company_name, first.business_id)) + + try: + detail_result = client.send_business_detail_lookup(first.business_id) + except Exception as err: + print(err) + return + + if detail_result is None: + print("\nNo detail result returned") + return + + print("\nDetail result:") + print_result(detail_result) + + +def print_result(obj): + for key, value in vars(obj).items(): + if value is None: + continue + if key == 'attributes': + print_result(value) + continue + print("{}: {}".format(key, value)) + print() + + +if __name__ == "__main__": + run() diff --git a/smartystreets_python_sdk/us_enrichment/client.py b/smartystreets_python_sdk/us_enrichment/client.py index 38b079e..ee9a830 100644 --- a/smartystreets_python_sdk/us_enrichment/client.py +++ b/smartystreets_python_sdk/us_enrichment/client.py @@ -158,7 +158,7 @@ def _url_components(lookup): def _address_parameters(lookup): params = {} - for key in ('freeform', 'street', 'city', 'state', 'zipcode', 'features'): + for key in ('freeform', 'business_name', 'street', 'city', 'state', 'zipcode', 'features'): value = getattr(lookup, key, None) if value: params[key] = value diff --git a/smartystreets_python_sdk/us_enrichment/lookup.py b/smartystreets_python_sdk/us_enrichment/lookup.py index 8268767..e4754ed 100644 --- a/smartystreets_python_sdk/us_enrichment/lookup.py +++ b/smartystreets_python_sdk/us_enrichment/lookup.py @@ -28,13 +28,14 @@ def add_exclude_attribute(self, attribute): class Lookup(LookupBase): - def __init__(self, smartykey=None, dataset=None, dataSubset=None, features=None, freeform=None, street=None, city=None, state=None, zipcode=None): + def __init__(self, smartykey=None, dataset=None, dataSubset=None, features=None, freeform=None, business_name=None, street=None, city=None, state=None, zipcode=None): super().__init__() self.smartykey = smartykey self.dataset = dataset self.dataSubset = dataSubset self.features = features self.freeform = freeform + self.business_name = business_name self.street = street self.city = city self.state = state diff --git a/test/us_enrichment/business_summary_test.py b/test/us_enrichment/business_summary_test.py index c141634..8e85bae 100644 --- a/test/us_enrichment/business_summary_test.py +++ b/test/us_enrichment/business_summary_test.py @@ -54,6 +54,32 @@ def test_business_lookup_with_freeform_builds_url(self): capturing.request.parameters['freeform'], ) + def test_business_lookup_with_business_name_builds_search_param(self): + capturing = RequestCapturingSender() + client, _ = self._client(capturing) + + lookup = BusinessLookup() + lookup.freeform = "1600 amphitheatre pkwy mountain view ca" + lookup.business_name = "Google" + client.send_business_lookup(lookup) + + self.assertEqual("search/business", capturing.request.url_components) + self.assertEqual( + "1600 amphitheatre pkwy mountain view ca", + capturing.request.parameters['freeform'], + ) + self.assertEqual("Google", capturing.request.parameters['business_name']) + + def test_business_lookup_omits_empty_business_name(self): + capturing = RequestCapturingSender() + client, _ = self._client(capturing) + + lookup = BusinessLookup() + lookup.freeform = "1600 amphitheatre pkwy mountain view ca" + client.send_business_lookup(lookup) + + self.assertNotIn('business_name', capturing.request.parameters) + def test_rejects_whitespace_smartykey_on_summary_lookup(self): capturing = RequestCapturingSender() client, _ = self._client(capturing) From 914c78bc242890304704870c6fcf35e5b3eea9c0 Mon Sep 17 00:00:00 2001 From: Mae Evans Date: Tue, 9 Jun 2026 10:53:30 -0600 Subject: [PATCH 2/3] Further testing updates --- ...y => us_enrichment_business_name_search_example.py} | 10 ++++------ smartystreets_python_sdk/us_enrichment/client.py | 3 ++- test/us_enrichment/business_summary_test.py | 9 ++------- 3 files changed, 8 insertions(+), 14 deletions(-) rename examples/{USEnrichmentBusinessNameSearchExample.py => us_enrichment_business_name_search_example.py} (81%) diff --git a/examples/USEnrichmentBusinessNameSearchExample.py b/examples/us_enrichment_business_name_search_example.py similarity index 81% rename from examples/USEnrichmentBusinessNameSearchExample.py rename to examples/us_enrichment_business_name_search_example.py index cf1a60e..7140f79 100644 --- a/examples/USEnrichmentBusinessNameSearchExample.py +++ b/examples/us_enrichment_business_name_search_example.py @@ -11,11 +11,9 @@ def run(): credentials = BasicAuthCredentials(auth_id, auth_token) client = ClientBuilder(credentials).build_us_enrichment_api_client() - # Business summary SEARCH path: no smartykey, set freeform (+ optional city) - # and business_name to narrow the search to a specific business. lookup = BusinessLookup() - lookup.freeform = "1600 amphitheatre pkwy mountain view ca" - lookup.business_name = "Google" + lookup.business_name = "delta air" + lookup.city = "atlanta" try: summary_results = client.send_business_lookup(lookup) @@ -24,12 +22,12 @@ def run(): return if not summary_results: - print("No matching businesses returned") + print("No response returned for business name {}".format(lookup.business_name)) return summary = summary_results[0] if not summary.businesses: - print("No business tenants matched the search") + print("Business name {} has no business tenants".format(lookup.business_name)) return print("Matching businesses for business_name '{}':".format(lookup.business_name)) diff --git a/smartystreets_python_sdk/us_enrichment/client.py b/smartystreets_python_sdk/us_enrichment/client.py index ee9a830..a43e17a 100644 --- a/smartystreets_python_sdk/us_enrichment/client.py +++ b/smartystreets_python_sdk/us_enrichment/client.py @@ -107,8 +107,9 @@ def send_lookup(client: Client, lookup, response_class=Response): _is_blank(getattr(lookup, 'smartykey', None)) and _is_blank(getattr(lookup, 'street', None)) and _is_blank(getattr(lookup, 'freeform', None)) + and _is_blank(getattr(lookup, 'business_name', None)) ): - raise SmartyException("Lookup requires one of 'smartykey', 'street', or 'freeform' to be set") + raise SmartyException("Lookup requires one of 'smartykey', 'street', 'freeform', or 'business_name' to be set") request = build_request(lookup) raw = _dispatch(client, request, lookup) diff --git a/test/us_enrichment/business_summary_test.py b/test/us_enrichment/business_summary_test.py index 8e85bae..a454025 100644 --- a/test/us_enrichment/business_summary_test.py +++ b/test/us_enrichment/business_summary_test.py @@ -59,16 +59,11 @@ def test_business_lookup_with_business_name_builds_search_param(self): client, _ = self._client(capturing) lookup = BusinessLookup() - lookup.freeform = "1600 amphitheatre pkwy mountain view ca" - lookup.business_name = "Google" + lookup.business_name = "Style Studio" client.send_business_lookup(lookup) self.assertEqual("search/business", capturing.request.url_components) - self.assertEqual( - "1600 amphitheatre pkwy mountain view ca", - capturing.request.parameters['freeform'], - ) - self.assertEqual("Google", capturing.request.parameters['business_name']) + self.assertEqual("Style Studio", capturing.request.parameters['business_name']) def test_business_lookup_omits_empty_business_name(self): capturing = RequestCapturingSender() From 3582b76c8f63de4ce4371adb1fb62b7c295135e0 Mon Sep 17 00:00:00 2001 From: Mae Evans Date: Thu, 11 Jun 2026 16:33:01 -0600 Subject: [PATCH 3/3] Move business_name to end of input list and wire up enrichment examples --- Makefile | 2 +- smartystreets_python_sdk/us_enrichment/client.py | 2 +- smartystreets_python_sdk/us_enrichment/lookup.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 651d103..f39ad88 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ us_autocomplete_pro_api: PYTHONPATH=. python3 examples/us_autocomplete_pro_example.py us_enrichment_api: - PYTHONPATH=. python3 examples/us_enrichment_example.py + PYTHONPATH=. python3 examples/us_enrichment_example.py && PYTHONPATH=. python3 examples/us_enrichment_etag_example.py && PYTHONPATH=. python3 examples/us_enrichment_business_example.py && PYTHONPATH=. python3 examples/us_enrichment_business_name_search_example.py && PYTHONPATH=. python3 examples/us_enrichment_generic_example.py && PYTHONPATH=. python3 examples/us_enrichment_geo_reference_example.py && PYTHONPATH=. python3 examples/us_enrichment_secondary_example.py && PYTHONPATH=. python3 examples/us_enrichment_secondary_count_example.py us_extract_api: PYTHONPATH=. python3 examples/us_extract_example.py diff --git a/smartystreets_python_sdk/us_enrichment/client.py b/smartystreets_python_sdk/us_enrichment/client.py index a43e17a..7a2e672 100644 --- a/smartystreets_python_sdk/us_enrichment/client.py +++ b/smartystreets_python_sdk/us_enrichment/client.py @@ -159,7 +159,7 @@ def _url_components(lookup): def _address_parameters(lookup): params = {} - for key in ('freeform', 'business_name', 'street', 'city', 'state', 'zipcode', 'features'): + for key in ('freeform', 'street', 'city', 'state', 'zipcode', 'features', 'business_name'): value = getattr(lookup, key, None) if value: params[key] = value diff --git a/smartystreets_python_sdk/us_enrichment/lookup.py b/smartystreets_python_sdk/us_enrichment/lookup.py index e4754ed..5797255 100644 --- a/smartystreets_python_sdk/us_enrichment/lookup.py +++ b/smartystreets_python_sdk/us_enrichment/lookup.py @@ -28,19 +28,19 @@ def add_exclude_attribute(self, attribute): class Lookup(LookupBase): - def __init__(self, smartykey=None, dataset=None, dataSubset=None, features=None, freeform=None, business_name=None, street=None, city=None, state=None, zipcode=None): + def __init__(self, smartykey=None, dataset=None, dataSubset=None, features=None, freeform=None, street=None, city=None, state=None, zipcode=None, business_name=None): super().__init__() self.smartykey = smartykey self.dataset = dataset self.dataSubset = dataSubset self.features = features self.freeform = freeform - self.business_name = business_name self.street = street self.city = city self.state = state self.zipcode = zipcode self.result = [] + self.business_name = business_name class PrincipalLookup(Lookup):