A Python wrapper for the Amazon Product Advertising API.
Project description
This module offers a light-weight access to the latest version of the Amazon Product Advertising API without getting in your way.
The Amazon API itself provides programmatic access to Amazon’s product selection and discovery functionality. It has search and look up capabilities, provides information on products and other features such as Customer Reviews, Similar Products, Wish Lists and New and Used listings. More information about the API can be found at https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html
Basic usage
In order to use this API you’ll obviously need an Amazon Associates Web Service account for which you must with Amazon at http://aws.amazon.com. Each account contains an AWSAccessKeyId and a SecretKey.
Here is an example how to use the API to search for books of a certain publisher:
AWS_KEY = '...' SECRET_KEY = '...' api = API(AWS_KEY, SECRET_KEY, 'de') node = api.item_search('Books', Publisher='Galileo Press')
The node object returned is a lxml.objectified element. All its attributes can be accessed the pythonic way:
total_results = node.Items.TotalResults.pyval total_pages = node.Items.TotalPages.pyval # get all books from result set and # print author and title for book in node.Items.Item: print '%s: "%s"' % (book.ItemAttributes.Author, book.ItemAttributes.Title)
Please refer to the more extensive documentation for more details.
Status
This module is still undergoing development. All operations can be used with the API’s call(Operation=...) method. Additionally, there is a number of convenience methods that include for instance additional error checking. These are currently limited to:
ItemLookup
ItemSearch
SimilarityLookup
BrowseNodeLookup
More functionality is to follow as development progresses.
Installation
In order to install python-amazon-product-api you can use:
pip install python-amazon-product-api
or download the source package from http://pypi.python.org/pypi/python-amazon-product-api, untar it and run
python setup.py install
You’ll also find binaries there to make your life easier if you happen to use a Windows system. If not, please send me an e-mail and complain loudly!
Development
The development version is available bitbucket.org. Feel free to clone the repository and add your own features.
hg clone http://bitbucket.org/basti/python-amazon-product-api/
Patches are always welcome! Please make sure that your change does not break the tests!
License
This module is release under the BSD License. You can find the full text of the license in the LICENSE file.
Changelog
0.2.5 (2011-09-19) “Buttercup”
Support for XSLT requests.
Support for Associate tags thanks to Kilian Valkhof.
New API versions 2010-12-01, 2010-11-01, 2010-10-01, 2010-09-01 and 2010-08-06 added.
Fixed #16: Cannot install module under Python 2.4 without pycrypto being installed first.
tox (and hudson) are now used for testing all supported Python versions (which includes Python 2.7 now, too).
Test server is replaced with pytest-localserver.
Fixed #18: Throttling no longer block CPU (Thanks to Benoit C).
Added response-caching API (in amazonproduct.contrib.caching) to ease development (Thanks to Dmitry Chaplinsky for the idea).
API explicitly warns about deprecated operations.
Added new exceptions InvalidClientTokenId and MissingClientTokenId.
REQUESTS_PER_SECONDS can now be floats as well (e.g. 2500/3600.0).
Added test options options --api-version, --locale and --refetch.
0.2.4.1 (2010-06-23)
Bugfix release! High time I get some continuous integration set up!
Fixed #13: The module did not run under Python 2.4. Ooops!
0.2.4 (2010-06-13)
Locale parameter is now required at initialisation.
# before you could write api = API(AWS_KEY, SECRET_KEY) # now you have to specify your locale api = API(AWS_KEY, SECRET_KEY, 'de')
Custom test server (tests.server.TestServer) added. It runs on localhost and mimicks the Amazon webservice by replaying local XML files.
Testing now supports multiple locales. Please not that you have to run python setup.py test to run the unittests.
ResultPaginator now also works with XPath expressions for attributes (Bug reported Giacomo Lacava).
Custom lookup for XML elements (during parsing) ensures that <ItemId/> and <ASIN> are now always objectify.StringElement (Bug reported by Brian Browning).
Fixed #11: Module can now be installed library without lxml being installed first.
Regular expressions for parsing error messages can now deal with the Japanese version.
0.2.3 (2010-03-20)
Tests run now for all API versions. Test cases can now be told which versions to use (class attribute api_versions set to i.e. ['2009-10-01']).
A custom AWS response processor can now be defined. For instance, here is one using xml.minidom instead of lxml:
def minidom_response_parser(fp): root = parse(fp) # parse errors for error in root.getElementsByTagName('Error'): code = error.getElementsByTagName('Code')[0].firstChild.nodeValue msg = error.getElementsByTagName('Message')[0].firstChild.nodeValue raise AWSError(code, msg) return root api = API(AWS_KEY, SECRET_KEY, processor=minidom_response_parser) root = api.item_lookup('0718155157') print root.toprettyxml() # ...
Fixed #3: Support for API Version 2009-11-01.
Fixed #4: When using a bad parameter combination, an InvalidParameterCombination exception is raised.
Fixed #5: InvalidSearchIndex is raised when unknown SearchIndex is specified.
Fixed #7: Specifying API versions works now for more than just one test per test case.
The setup.py command has been empowered a bit with the following additional options: test, build_sphinx, upload_sphinx.
ResultPaginator attributes _get_current_page_numer, _get_total_results and _get_total_page_numer are now private.
0.2.2 (2010-01-30)
browse_node_lookup operation added.
help operation added.
list_lookup and list_search operations added.
Default timeout for API calls is set to 5 sec.
Test cases for correct parsing of XML responses added. Local XML files are used for testing (if available) stored in separate directories according to API version. These can be overwritten when config value OVERWRITE_TESTS is set to True.
InvalidItemId exception is replaced by more general InvalidParameterValue exception.
0.2.1 (2009-11-20)
Support for Python 2.4 added.
Fixed #2: ResultPaginator now returns None if the XPath expression doesn’t find the node it’s looking for.
0.2.0 (2009-11-07) “Westley”
This is the first public release. We’re now available via the Cheeseshop! http://pypi.python.org/pypi/python-amazon-product-api
The module is no longer a package. Please use import amazonproduct (instead of import amazon.product) now.
SimilarityLookup is now supported.
Updated to support version 2009-10-01.
Documentation added (made with http://sphinx.pocoo.org).
New artwork.
0.1 (2009-09-30) “Fezzik”
Initial release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for python-amazon-product-api-0.2.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 192c5fc17c2a753d7c688e6931e31dfeb2c95312c24481a66d518cddfd7832c0 |
|
MD5 | 86206766f8741d2f3ff477fec1e106bd |
|
BLAKE2b-256 | e20650ead8d4a817670ce264b64bef0e3448a5f12b179ee5953ff2cab0f1a6cb |