lob / lob-python Goto Github PK
View Code? Open in Web Editor NEWPython Wrapper for Lob API
Home Page: lob.com
License: MIT License
Python Wrapper for Lob API
Home Page: lob.com
License: MIT License
Posting here because the /examples repo doesn't have issues enabled.
When using the example 4x6 back template (https://github.com/lob/examples/blob/master/postcards/4x6-back.html), the recipient address / Postage Indicia section is not aligned with the area specified in the template.
I've included a screenshot of the postcard created using the template. I set a black border on the ink-free div in the template to judge where I can place assets. The white address box is about a centimeter off from where it should be according to the template's CSS.
This is obviously easy enough to fix in CSS, but I'm not sure who to trust: the template or the postcard created in test mode.
It seems that version 2.3.2 that was uploaded to pypi was messed up somehow, presumably by my messing with the version string and trying to make the version more DRY. https://pypi.python.org/pypi/lob/2.3.2
My changes installed successfully to our devpi pypi server at my work, so I'm not sure how to debug this. I'm guessing the easiest solution would be to just revert to using a string literal in setup.py. pypi.python.org seems sort of confused about whether it's 2.3.2 or not (note the missing "Py Version"):
/tmp $ virtualenv foo && source foo/bin/activate
...
(foo)/tmp $ pip install lob==2.3.2
Downloading/unpacking lob==2.3.2
Could not find a version that satisfies the requirement lob==2.3.2 (from versions: 2.3, 2.2, 2.1, 2.0, 1.0)
Cleaning up...
No distributions matching the version for lob==2.3.2
Storing debug log for failure in /Users/lucaswiman/.pip/pip.log
(foo)/tmp $ pip install lob==2.3.1
Downloading/unpacking lob==2.3.1
Could not find a version that satisfies the requirement lob==2.3.1 (from versions: 2.3, 2.2, 2.1, 2.0, 1.0)
Cleaning up...
No distributions matching the version for lob==2.3.1
Storing debug log for failure in /Users/lucaswiman/.pip/pip.log
(foo)/tmp $ pip install lob
Downloading/unpacking lob
Downloading lob-2.3.tar.gz
Running setup.py (path:/private/tmp/foo/build/lob/setup.py) egg_info for package lob
Downloading/unpacking requests (from lob)
Downloading requests-2.3.0-py2.py3-none-any.whl (452kB): 452kB downloaded
Installing collected packages: lob, requests
Running setup.py install for lob
Successfully installed lob requests
Cleaning up...
(foo)/tmp $ pip freeze
lob==2.3
missing states and countries
Hi,
I noticed that the latest release to PYPI was back in July of 2013. The version (1.0) does not support file uploads using the files
keyword argument, a feature we are relying on. Would it be possible for you to push a new release that contains the current changes in master?
Thanks,
Charlie
Hello, on my development and staging servers I'm using my publishable API key from production to make US Verification requests (so that they're "real" without actually affecting the real world in any way), while I'm using my secret API key from testing to make Letter requests (so that they don't actually affect the real world).
The only ways I've found to do this are to either subclass the related Resource
classes in a way that feels invasive, or to change the value of lob.api_key
to its appropriate value before making the request (paying attention to thread safety since it's a global variable). I currently use the latter strategy, but both of these mechanisms feel suboptimal, and I'm curious if there's some other way to do this that I've missed, or if you'd accept PRs to make it easier to do this.
After your planned maintenance the other day, can you update /lob/api_requestor.py
, parse_response
to support 503
? Otherwise payload = resp.json()
throws.
Right now, having trouble ingesting our code coverage data into coveralls due to the python code coverage we use not outputting a lcov.info
file. We need to look into either finding a way to output a lcov.info
file with our current code coverage package or switch to another code coverage service that will ingest xml.
Hi, I'm trying to send a simple PDF file using the Lob Python SDK, but I'm running into errors. The key issue seems to be that the file
param of LetterEditable will only accept a Python str
value, which doesn't allow for in-memory PDFs.
It also does not upload local files like the API documents say it should. Uploading raw HTML works, but we need to upload PDF files.
Ideally I would like to pass an in-memory file, e.g. bytes or io.BytesIO. Here's what I see when I try to pass that:
lob_python.exceptions.ApiTypeError: Invalid type for variable 'file'. Required value type is str and passed type was bytes at ['file']
That error is being generated in lob_python, letter_editable.py:362:
self.file = file
because on line 120:
'file': (str,), # noqa: E501
and this is enforced via __setitem__
in ModelNormal
and set_attribute
in OpenApiModel
.
Notes:
file_upload_type
parameter, that would accept 'file-like-stream', 'html', 'url', etc. Then allow each of those in the file parameter.from lob_python.models import MultipleComponentsList Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/nick/Code/lob/lob-python/lob_python/models/__init__.py", line 44, in <module> from lob_python.model.campaign import Campaign File "/home/nick/Code/lob/lob-python/lob_python/model/campaign.py", line 32, in <module> from lob_python.model.campaign_creative import CampaignCreative File "/home/nick/Code/lob/lob-python/lob_python/model/campaign_creative.py", line 110 'details': (, PostcardDetailsWritable, type(None)), # noqa: E501 ^ SyntaxError: expression expected after dictionary key and ':'
from lob_python.models import MultipleComponents Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/nick/Code/lob/lob-python/lob_python/models/__init__.py", line 44, in <module> from lob_python.model.campaign import Campaign File "/home/nick/Code/lob/lob-python/lob_python/model/campaign.py", line 32, in <module> from lob_python.model.campaign_creative import CampaignCreative File "/home/nick/Code/lob/lob-python/lob_python/model/campaign_creative.py", line 110 'details': (, PostcardDetailsWritable, type(None)), # noqa: E501
This dict is autogenerated from OpenAPI, but also if you refactor the code, a circular import appears:
This is needed to keep the wrapper consistent with the API and will result in a minor version change
Maybe I'm doing something wrong, but it appears that the code for Postcard doesn't match the documentation in lob or any of the examples in the examples folder.
ipython says the function signature (in lob-python v1.0.0, v1.1, and v1.2) is
lob.Postcard.create(cls, name, to, message=None, back=None, from_address=None, **kwargs)
meaning the example code like this doesn't work at all:
response = lob.Postcard.create(
to_address={
'name': 'John Doe',
'address_line1': '404 Building Apt. 404',
'address_line2': '',
'address_city': 'New York',
'address_state': 'NY',
'address_zip': '10025',
'address_country': 'US',
},
from_address=None,
front='http://example.com/front.png',
back='http://example.com/back.png',
metadata={
'id': r.id,
'specialty': 'abcdefg',
}
)
Traceback (most recent call last):
File "<input>", line 20, in <module>
TypeError: create() takes at least 3 arguments (3 given)
Forcing the format results in other weird errors:
response = lob.Postcard.create(
name='My Test Postcard Mailer',
to={
'name': 'John Doe',
'address_line1': '404 Building Apt. 404',
'address_line2': '',
'address_city': 'New York',
'address_state': 'NY',
'address_zip': '10025',
'address_country': 'US',
},
from_address=None,
front='http://example.com/front.png',
back='http://example.com/back.png',
metadata={
'id': r.id,
'specialty': 'abcdefg',
}
)
InvalidRequestError: [{u'status_code': 422, u'message': u'metadata must be an object'}]
So then I tried
class MetaData:
def __init__(self, *args, **kwargs):
for k, v in kwargs.iteritems():
setattr(self, k, v)
lob.Postcard.create(..., metadata=Metadata(**{'id': r.id, 'specialty': 'abcdefg'}), ...)
still doesn't work:
AttributeError: MetaData instance has no attribute '__len__'
Any suggestions?
afternoon. we seem to be getting an error on the preceding line. any help would be appreciated!
Hello,
Do you maintain a change-log somewhere for this library? It is hard to follow the commit history.
Thanks
Hey guys,
Sometimes we receive a HTTP 504 response error that is not appropriately being caught. In parse_response
when you call payload = resp.json()
, it will throw a ValueError("No JSON object could be decoded")
error.
What I'm thinking of adding before payload = resp.json()
:
if resp.status_code == 504:
raise error.APIConnectionError(resp.content,
resp.content, resp.status_code, resp)
Thoughts? Happy to submit a PR if you think this is good.
# Python 3.4
metadata = {'key1': '...', 'key2': '....'}
results = lob.BankAccount.list(offset=0, limit=100, include=['total_count'], metadata=metadata)
File "/usr/local/lib/python3.4/dist-packages/lob/resource.py", line 100, in list
for key, value in params.items():
RuntimeError: dictionary changed size during iteration
https://github.com/lob/lob-python/blob/master/lob/resource.py#L103
Hi all, thanks for the upgrades to the client!
The last version the client on pypi is 4.5.4, the version on main is version 5 which is a major version bump. Since there are no release notes and pypi is still hosting the previous version of the client, it's unclear on whether version 5 is ready for public consumption already? If it is, would you be able to upload it to pypi?
If I'm not mistaken you should be able to add release notes after the fact here: https://github.com/lob/lob-python/releases/tag/v5.0.0
Im trying to get this to work but i am receiving many different errors. Is it possible that the version is outdated?
I got this error applying the example in the readme:
raise get_type_error(input_value, path_to_item, valid_classes,
lob_python.exceptions.ApiTypeError: Invalid type for variable 'description'. Required value type is one of [NoneType, str] and passed type was ResourceDescription at ['description']
I am having issues running the examples locally on a mac.
I had to change files be opened like this:
"open('postcard_front.html', 'r')"
instead of
"s.path.dirname(file) + '/postcard_front.html'"
to get it to work.
This does not work:
lob.Postcard.list(metadata = { 'campaign': 'NEWYORK2015' })
I get this error when trying to import lob on AWS Lambda: Unable to import module 'lambda_function': No module named lob.resource
One thing I'm doing that might be throwing it off is I'm installing the libraries in a subdirectory using this command: pip install -t libs/ lob
. There is an __init.py__
file in that libs
directory, and that allows me to import other libraries successfully (PyMySQL, braintree, etc.) using from libs import blah
. But lob doesn't seem to like being imported that way.
I've attached a .zip of my file structure for reference.
Current Library does not allow for multi-part file uploads. We are going to be switching the request lib to urllib2 to allow for this.
Hello! I'm using your package in production and would like to provide a timeout value to my Lob requests so that our server doesn't hang. After perusing your source code, it doesn't seem like there's any obvious way to do this, but I'm wondering if I'm missing something, or if you'd accept a PR to add such functionality?
Getting a failure while attempting to retrieve bank account information in the test
environment.
with lob_python.ApiClient(configuration) as lob_client:
bank_account_id = "xxxxxxxxxx"
accounts_api = BankAccountsApi(lob_client)
The issue seems to appear when using PNG
signature, and occurs due to incorrect regex used to validate signature_url
here: https://github.com/lob/lob-python/blob/main/lob_python/model/bank_account.py#L87
Our signature_url looks like so:
https://lob-assets.com/bank-accounts/bank_xxxxxxxxxx_signature.png?ve.....
The regular expression is looking for "thumb" which doesn't appear (there may be additional issues with it).
('signature_url',): {
'regex': {
'pattern': r'^https:\/\/lob-assets\.com\/(letters|postcards|bank-accounts|checks|self-mailers|cards)\/[a-z]{3,4}_[a-z0-9]{15,16}(\.pdf|_thumb_[a-z]+_[0-9]+\.png)\?(version=[a-z0-9-]*&)?expires=[0-9]{10}&signature=[a-zA-Z0-9-_]+$', # noqa: E501
},
},
This prevents sending of checks as well as the check api seems to use the same validation somewhere in the code path
When I import the CreativeWritable
class to use it in a api call, I get back the following error:
Traceback (most recent call last):
File "/Users/sean/dev/minimal-reproduction/main.py", line 1, in <module>
from lob_python.model.creative_writable import CreativeWritable
File "/Users/sean/dev/minimal-reproduction/venv/lib/python3.10/site-packages/lob_python/model/creative_writable.py", line 102
'details': (, PostcardDetailsWritable, type(None)), # noqa: E501
^
SyntaxError: invalid syntax
contents of main.py
:
from lob_python.model.creative_writable import CreativeWritable
I have tried importing this class in a python 3.8 project and got the same result. The provided reproduction was done with python 3.10.
Full command line reproduction:
user@machine minimal-reproduction % python3 -m venv venv
user@machine minimal-reproduction % source venv/bin/activate
(venv) user@machine minimal-reproduction % pip install lob-python
Collecting lob-python
Using cached lob-python-5.1.0.tar.gz (172 kB)
Preparing metadata (setup.py) ... done
Collecting urllib3>=1.25.3
Using cached urllib3-1.26.14-py2.py3-none-any.whl (140 kB)
Collecting python-dateutil
Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting six>=1.5
Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: urllib3, six, python-dateutil, lob-python
DEPRECATION: lob-python is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
Running setup.py install for lob-python ... done
Successfully installed lob-python-5.1.0 python-dateutil-2.8.2 six-1.16.0 urllib3-1.26.14
(venv) user@machine minimal-reproduction % pip list
Package Version
--------------- -------
lob-python 5.1.0
pip 22.3.1
python-dateutil 2.8.2
setuptools 65.6.3
six 1.16.0
urllib3 1.26.14
(venv) user@machine minimal-reproduction % python -c "from lob_python.model.creative_writable import CreativeWritable"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/sean/dev/minimal-reproduction/venv/lib/python3.10/site-packages/lob_python/model/creative_writable.py", line 102
'details': (, PostcardDetailsWritable, type(None)), # noqa: E501
^
SyntaxError: invalid syntax
Please let me know if you need more information. Thank you.
https://github.com/lob/lob-python/blob/main/lob_python/model_utils.py#L918
This line does not correctly determine whether a number is a valid amount. With the imprecision of floating point arithmetic, there will be many cases where dividing a valid amount
by 0.01
will result in a non-integer:
>>> 0.14 / 0.01
14.000000000000002
>>> (0.14 / 0.01).is_integer()
False
I scripted a quick test and it seems like 10-20% of valid numbers will fail this check.
Additionally, when I ran into a failed validation, the check was still sent even though the SDK errored.
Hello,
I'm relatively new to Python development, and when I try to import lob
into a Python3 project I get
File "/usr/local/opt/pyenv/versions/3.4.2/lib/python3.4/site-packages/lob/__init__.py", line 5, in <module>
from lob.resource import (Address, Area, BankAccount, Check, Country, Job,
File "/usr/local/opt/pyenv/versions/3.4.2/lib/python3.4/site-packages/lob/resource.py", line 62
except KeyError, err:
^
SyntaxError: invalid syntax
Is this because this is a python 2 package? Is there any easy way to port it to python 3?
Thanks
Hi,
I plan to integrate Lob service into our app which partially write in Python and Google App Engine. Does this lib fully compatible with GAE?
Best,
Bao Le
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.