Giter Club home page Giter Club logo

smartystreets-python-sdk's People

Contributors

alrwarner avatar andrewjohnsonsmarty avatar caaz avatar duncanbeutler avatar dwhatcott avatar jtwalsh0 avatar jwnacnud avatar landonsmarty avatar manselmi avatar mdwhatcott avatar melonhead901 avatar mouaying avatar nmaynes avatar ryanlcox1 avatar savannah-ryan avatar smartybryan avatar smartycaroine avatar spencersmarty avatar xansmarty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smartystreets-python-sdk's Issues

send_batch for international_street client

See this problem:
A have a list of merged address (US and international), and I need a method to validate all address of the list in an efficient way, if the list only have US addresses this was't be a problem because i can create a Batch() use the send_batch method in us-street client. The problem is when there are merge addresses on the list

Right now I solved the problem in a way that i don't really like, I made a batch with US addresses and used send_batch method of us_street client, and for international addresses on the list I sent it one by one. Is obvious this way is not the best. So...

Maybe it's a good idea as long as it's possible to add the send_batch method to the international_street client as the us_street client does.

Or even better if there was a common client that receives a merged list of address of different countries and it be able to validate this addresses combining the send_batch methods in both clients

Use python logging instead of print.

Hi, do you have any plans to use logging (standard python library) for all output that your library produce?
Sometimes it is hard to get traceback or any helpful information from there.
Example of information that it can print:

('There was an error processing the request. Retrying in 0 seconds...', <open file '<stderr>', mode 'w' at 0x7fdfa9b1b1e0>)
('There was an error processing the request. Retrying in 1 seconds...', <open file '<stderr>', mode 'w' at 0x7fdfa9b1b1e0>)
('There was an error processing the request. Retrying in 2 seconds...', <open file '<stderr>', mode 'w' at 0x7fdfa9b1b1e0>)
('There was an error processing the request. Retrying in 3 seconds...', <open file '<stderr>', mode 'w' at 0x7fdfa9b1b1e0>)
('There was an error processing the request. Retrying in 4 seconds...', <open file '<stderr>', mode 'w' at 0x7fdfa9b1b1e0>)

or example here.

I can prepare PR if this can help.

'Lookup' object has no attribute 'input_id'

I just got this Exception when trying to run this code...

auth_id = settings.SMARTYSTREETS_ID
auth_token = settings.SMARTYSTREETS_TOKEN
credentials = StaticCredentials(auth_id, auth_token)
client = ClientBuilder(credentials).build_us_street_api_client()

lookup = Lookup(prefix=q)

client.send_lookup(lookup)

The Lookup class doesn't have any property named input_id

I'm using version 4.3.0 of the smartystreets_python_sdk

ClientBuilder(credentials).with_proxy() no longer works

In the examples, using the client with a proxy, like this:

client = ClientBuilder(credentials).with_proxy('localhost:8080', 'user', 'password').build_us_street_api_client()

Worked fine with requests 2.18.4 and urllib3 1.22, but no longer works with the latest versions of requests (2.27.1) and urllib3 (1.26.16). Something about the API for proxy connections must have changed between these versions and will need to be updated in Smarty's ClientBuilder code. Thanks!

Candidate missing input id

I am using the python SDK for a Street lookup. When going through the successful results, the candidate returned is missing the input id given.

An when just looking at the lookup object itself and its input id, it doesn't seem to retain an input id when I set one.

I am using the smartystreets-python-sdk 4.3.0

Returned 'input_id' for invalid address during batch?

I greatly appreciate the us_street_multiple_addresses_example.py example you supplied, but have a question: Is it possible to return the input_id regardless of valid or invalid status? I'd like to flag the source data that an attempt was made, but manual intervention is needed. I'm essentially wanting to do this:

  • grab 10 records
  • create batch and send to smartystreets
  • if result = valid
    ** update database
    ** flag row as 'validated'
  • if result = invalid
    ** flag row as 'unable to validate'

I guess I could store a list of the input_ids submitted during a batch, then remove the validated input_ids and flag the remainder as invalid. It would just be so nice if the invalid address still returned the input_id.

Y'all are making it hard for me to be lazy...unless I just missed something...thus this ticket.

No custom headers for client builder in the Python SDK

In the other language client builder SDKs there is the option for custom headers to be sent through for use in proxies or whatever (example Java ). The python SDK does not have this functionality.

I spoke to Jeffrey Duncan about this as well for reference.

Failure in address verification

Hi guys, this is throwing errors for all our flows with address verification.

Cause

Looks to be changes from ce388d5 at smartystreets_python_sdk/us_street/client.py line 73, lookup.match was replaced with lookup.match.value, which throws the error.

-         add_field(converted_lookup, 'match', lookup.match)
+         add_field(converted_lookup, 'match', lookup.match.value)

Error

AttributeError
'str' object has no attribute 'value'

Code example

client_builder = ClientBuilder(credentials)
client_builder.max_timeout = 3
client = client_builder.with_licenses(
    ["us-core-cloud"]
).build_us_street_api_client()

lookup = Lookup()
lookup.street = address_data["street"]
lookup.city = address_data["city"]
lookup.state = address_data["state"]
lookup.country = address_data["country"]
lookup.zipcode = address_data["zip"]
lookup.match = "enhanced"

try:
    client.send_lookup(lookup)
except exceptions.SmartyException as err:
    # never gets here

us_autocomplete client throws a TypeError if the response is null

Hey guys,

When using the us_autocomplete client, it looks like the response.payload can return {"suggestions": None}, which trips up convert_suggestions. Maybe casting None to an empty list would be appropriate here?

In [100]: lookup = Lookup('4338 Hayman Ave, La Canada, CA 91011')
In [101]:  client.send(lookup)
~/miniconda2/envs/hydra/lib/python3.8/site-packages/smartystreets_python_sdk/us_autocomplete/client.py in send(self, lookup)
     27
     28         result = self.serializer.deserialize(response.payload)
---> 29         suggestions = self.convert_suggestions(result.get('suggestions', []))
     30         lookup.result = suggestions
     31

~/miniconda2/envs/hydra/lib/python3.8/site-packages/smartystreets_python_sdk/us_autocomplete/client.py in convert_suggestions(suggestion_dictionaries)
     55     @staticmethod
     56     def convert_suggestions(suggestion_dictionaries):
---> 57         return [Suggestion(suggestion) for suggestion in suggestion_dictionaries]
     58
     59     @staticmethod

TypeError: 'NoneType' object is not iterable

pip install does not work in python 3.6/3.7

This appears to be related to the library importing itself during setup, to read the version string in __init__.py. Strangely, it works for me on python 2 (but obviously that isn't a sufficient work around).

If requests is already installed in the environment, pip install works. If requests is absent, it fails:

$ pip install smartystreets_python_sdk

Collecting smartystreets_python_sdk
  Downloading https://files.pythonhosted.org/packages/84/5c/c78180adcb787cba08f1f45d083d6ae1177450d63bedf4ab5e388b49a5c4/smartystreets_python_sdk-3.3.2.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-au0p_thk/smartystreets-python-sdk/setup.py", line 1, in <module>
        import smartystreets_python_sdk
      File "/tmp/pip-install-au0p_thk/smartystreets-python-sdk/smartystreets_python_sdk/__init__.py", line 3, in <module>
        from .requests_sender import RequestsSender
      File "/tmp/pip-install-au0p_thk/smartystreets-python-sdk/smartystreets_python_sdk/requests_sender.py", line 1, in <module>
        from requests import Session, Request
    ModuleNotFoundError: No module named 'requests'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-au0p_thk/smartystreets-python-sdk/

Handle the new `dpv_no_stat` in the analysis object

SmartyStreets has an active field. It recently started reporting all addresses as "active" due to problems with the underlying USPS data and now reports that information in the dpv_no_stat field. (See here for more.) This package should provide the new dpv_no_stat field for interested users.

Latest release, 4.8.0, is broken

The latest release, version 4.8.0, appears to be broken because of a packaging/distribution error. The new smartystreets_python_sdk.us_autocomplete_pro package is missing from setup.py:

packages=[
'smartystreets_python_sdk',
'smartystreets_python_sdk_version',
'smartystreets_python_sdk.us_street',
'smartystreets_python_sdk.us_zipcode',
'smartystreets_python_sdk.us_extract',
'smartystreets_python_sdk.us_autocomplete',
'smartystreets_python_sdk.international_street',
'smartystreets_python_sdk.us_reverse_geo',
],

and thus doesn't get installed. ModuleNotFoundErrors occur when trying to use the ClientBuilder, which imports us_autocomplete_pro:

Traceback (most recent call last):
  …
  File "…", line 32, in <module>
    from smartystreets_python_sdk import StaticCredentials, ClientBuilder
  File "…/lib/python3.6/site-packages/smartystreets_python_sdk/__init__.py", line 13, in <module>
    from .client_builder import ClientBuilder
  File "…/lib/python3.6/site-packages/smartystreets_python_sdk/client_builder.py", line 6, in <module>
    from smartystreets_python_sdk.us_autocomplete_pro import Client as USAutocompleteProClient
ModuleNotFoundError: No module named 'smartystreets_python_sdk.us_autocomplete_pro'

A similar issue with a different new module occurred with the 4.7.0 release last year.

Handle seamlessly batch > 100 lookups

Looking at the Client class of US street - and surely the same elsewhere -, there is no provision in the library to handle more than 100 lookups without some additional custom wrapper. User must deal with it and pass in chunks.

It would be useful if the SDK was handling this like so:

  • send in chunks of 100
  • accumulate in one single object all responses

I guess that's what the CLI is doing.

Thoughts ?

`ImportError: cannot import name 'StrEnum' from 'enum' (/usr/local/lib/python3.10/enum.py)` after upgrade

Hey. Sorry for the lack of detail but we are at an app launch event and pushed a last minute change to our backend, and we applied your latest patch which crashed our backend. Here's what I'm seeing in our logs. Nothing else changed besides the version. We are reverting to a previous version.

accounts-c5d5596f9-bxznz Process SpawnProcess-1:
accounts-c5d5596f9-bxznz Traceback (most recent call last):
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/multiprocessing/process.py", line 315, in _bootstrap
accounts-c5d5596f9-bxznz     self.run()
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/multiprocessing/process.py", line 108, in run
accounts-c5d5596f9-bxznz     self._target(*self._args, **self._kwargs)
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/site-packages/uvicorn/subprocess.py", line 76, in subprocess_started
accounts-c5d5596f9-bxznz     target(sockets=sockets)
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/site-packages/uvicorn/server.py", line 60, in run
accounts-c5d5596f9-bxznz     return asyncio.run(self.serve(sockets=sockets))
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
accounts-c5d5596f9-bxznz     return loop.run_until_complete(main)
accounts-c5d5596f9-bxznz   File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/site-packages/uvicorn/server.py", line 67, in serve
accounts-c5d5596f9-bxznz     config.load()
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/site-packages/uvicorn/config.py", line 458, in load
accounts-c5d5596f9-bxznz     self.loaded_app = import_from_string(self.app)
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/site-packages/uvicorn/importer.py", line 24, in import_from_string
accounts-c5d5596f9-bxznz     raise exc from None
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/site-packages/uvicorn/importer.py", line 21, in import_from_string
accounts-c5d5596f9-bxznz     module = importlib.import_module(module_str)
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
accounts-c5d5596f9-bxznz     return _bootstrap._gcd_import(name[level:], package, level)
accounts-c5d5596f9-bxznz   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
accounts-c5d5596f9-bxznz   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
accounts-c5d5596f9-bxznz   File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
accounts-c5d5596f9-bxznz   File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
accounts-c5d5596f9-bxznz   File "<frozen importlib._bootstrap_external>", line 883, in exec_module
accounts-c5d5596f9-bxznz   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
[...]
accounts-c5d5596f9-bxznz     from foo.bar.address_validation_service import AddressValidationService
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/site-packages/foo/bar/address_validation_service.py", line 4, in <module>
accounts-c5d5596f9-bxznz     from smartystreets_python_sdk import ClientBuilder, StaticCredentials
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/site-packages/smartystreets_python_sdk/__init__.py", line 14, in <module>
accounts-c5d5596f9-bxznz     from .client_builder import ClientBuilder
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/site-packages/smartystreets_python_sdk/client_builder.py", line 2, in <module>
accounts-c5d5596f9-bxznz     from smartystreets_python_sdk.us_street import Client as USStreetClient
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/site-packages/smartystreets_python_sdk/us_street/__init__.py", line 5, in <module>
accounts-c5d5596f9-bxznz     from .lookup import Lookup
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/site-packages/smartystreets_python_sdk/us_street/lookup.py", line 1, in <module>
accounts-c5d5596f9-bxznz     from smartystreets_python_sdk.us_street.match_type import MatchType
accounts-c5d5596f9-bxznz   File "/usr/local/lib/python3.10/site-packages/smartystreets_python_sdk/us_street/match_type.py", line 1, in <module>
accounts-c5d5596f9-bxznz     from enum import StrEnum
accounts-c5d5596f9-bxznz ImportError: cannot import name 'StrEnum' from 'enum' (/usr/local/lib/python3.10/enum.py)

Req: enhance freeform address parsing

Granted, not SDK related but couldn't figure out where to post enhancement requests - probably not even github.

Use case:
We have many addresses that have the "ATTN:" element (and variations thereof), that is not relevant for geolocation. It should be ignored when validating.

Take the following address (as recorded in a database):

31390 Viking Pkwy
ATTN: Leonardo Caprio / Jon Slivan
Westlake OH 44145 
United States

The API as of this writing does not like this and returns UNKNOWN/ADDRESS.
We could use a regex to parse and remove the ATTN line but ideally the API would do this (more efficiently).
Once the Attention portion is removed, API works as expected.

Let me know what channel can be best used to report API issues/enhancement requests.

International Autocomplete Lookup - AttributeError: 'str' object has no attribute 'get'

Hi,

When I test the International Autocomplete Lookup SDK (version 4.10.6) with following code:

from smartystreets_python_sdk import StaticCredentials, ClientBuilder
from smartystreets_python_sdk.international_autocomplete import Lookup as InternationalAutocompleteLookup

auth_id = '********'
token = '*********'
credentials = StaticCredentials(auth_id, token)
client = ClientBuilder(credentials).with_licenses(
    ["international-autocomplete-cloud"]).build_international_autocomplete_api_client()
lookup = InternationalAutocompleteLookup('Louis')
lookup.country = "FRA"
suggestions = client.send(lookup)

I got an exception - AttributeError: 'str' object has no attribute 'get'
Following are trackback:

Traceback (most recent call last):
File "/Users/xz/Documents/GitHub/python-tool/smarty_street/main.py", line 102, in
run_international_lookup()
File "/Users/xz/Documents/GitHub/python-tool/smarty_street/main.py", line 77, in run_international_lookup
suggestions = client.send(lookup) # The client will also return the suggestions directly
File "/Users/xz/Documents/GitHub/python-tool/.venv/lib/python3.9/site-packages/smartystreets_python_sdk/international_autocomplete/client.py", line 29, in send
suggestions = self.convert_suggestions(result or [])
File "/Users/xz/Documents/GitHub/python-tool/.venv/lib/python3.9/site-packages/smartystreets_python_sdk/international_autocomplete/client.py", line 47, in convert_suggestions
return [Suggestion(suggestion) for suggestion in suggestion_dictionaries]
File "/Users/xz/Documents/GitHub/python-tool/.venv/lib/python3.9/site-packages/smartystreets_python_sdk/international_autocomplete/client.py", line 47, in
return [Suggestion(suggestion) for suggestion in suggestion_dictionaries]
File "/Users/xz/Documents/GitHub/python-tool/.venv/lib/python3.9/site-packages/smartystreets_python_sdk/international_autocomplete/suggestion.py", line 3, in init
self.street = obj.get('street', None)
AttributeError: 'str' object has no attribute 'get'

PS: The US AutoComplete Lookup is working fine

Latest release, 4.7.0, is broken

The latest release, version 4.7.0, appears to be broken because of a packaging/distribution error. The new smartystreets_python_sdk.us_reverse_geo package is missing from setup.py:

packages=[
'smartystreets_python_sdk',
'smartystreets_python_sdk_version',
'smartystreets_python_sdk.us_street',
'smartystreets_python_sdk.us_zipcode',
'smartystreets_python_sdk.us_extract',
'smartystreets_python_sdk.us_autocomplete',
'smartystreets_python_sdk.international_street',
],

and thus doesn't get installed. ModuleNotFoundErrors occur when trying to use the ClientBuilder, which imports us_reverse_geo:

Traceback (most recent call last):
  …
  File "…", line 32, in <module>
    from smartystreets_python_sdk import StaticCredentials, ClientBuilder
  File "…/lib/python3.6/site-packages/smartystreets_python_sdk/__init__.py", line 13, in <module>
    from .client_builder import ClientBuilder
  File "…/lib/python3.6/site-packages/smartystreets_python_sdk/client_builder.py", line 6, in <module>
    from smartystreets_python_sdk.us_reverse_geo import Client as USReverseGeoClient
ModuleNotFoundError: No module named 'smartystreets_python_sdk.us_reverse_geo'

client.py uses "is not" to check equality with a literal

In the Python sdk, version 4.7.2, client.py will raise a SyntaxWarning on Python 3.8.x. The add_parameter method uses the syntax is not which checks for identity not equality.

@staticmethod
    def add_parameter(request, key, value):
        if value and value is not 'none':
            request.parameters[key] = value

The code should be updated to:

@staticmethod
    def add_parameter(request, key, value):
        if value and value != 'none':
            request.parameters[key] = value

I am happy to create a PR to fix this issue. From what I can see the syntax appears in at least 4 places.

  • us_extract
  • us_autocomplete
  • us_reverse_geo
  • international_street

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.