A simple Python wrapper for the Amazon.com Product Advertising API ⛺

Overview

Amazon Simple Product API

A simple Python wrapper for the Amazon.com Product Advertising API.

Build Status Documentation Status Coverage Status PyPI version PyPI - License PyPI - Downloads PyPI - Python Version Code Shelter

Features

  • An object oriented interface to Amazon products
  • Supports both item search and item lookup
  • Compatible with Google App Engine

Dependencies

Before you get started, make sure you have:

  • Installed Bottlenose (pip install bottlenose)
  • Installed lxml (pip install lxml)
  • Installed dateutil (pip install python-dateutil)
  • An Amazon Product Advertising account
  • An AWS account

Installation

 pip install python-amazon-simple-product-api

Usage

Lookup:

 >>> from amazon.api import AmazonAPI
 >>> amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)
 >>> product = amazon.lookup(ItemId='B00EOE0WKQ')
 >>> product.title
 'Amazon Fire Phone, 32GB (AT&T)'
 >>> product.price_and_currency
 (199.0, 'USD')
 >>> product.ean
 '0848719035209'
 >>> product.large_image_url
 'http://ecx.images-amazon.com/images/I/51BrZzpkWrL.jpg'
 >>> product.get_attribute('Publisher')
 'Amazon'
 >>> product.get_attributes(['ItemDimensions.Width', 'ItemDimensions.Height'])
 {'ItemDimensions.Width': '262', 'ItemDimensions.Height': '35'}

(the API wrapper also supports many other product attributes)

Lookup on amazon.de instead of amazon.com by setting the region:

 >>> from amazon.api import AmazonAPI
 >>> import bottlenose.api
 >>> region_options = bottlenose.api.SERVICE_DOMAINS.keys()
 >>> region_options
 ['US', 'FR', 'CN', 'UK', 'IN', 'CA', 'DE', 'JP', 'IT', 'ES']
 >>> amazon_de = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG, region="DE")
 >>> product = amazon_de.lookup(ItemId='B0051QVF7A')
 >>> product.title
 u'Kindle, WLAN, 15 cm (6 Zoll) E Ink Display, deutsches Men\xfc'
 >>> product.price_and_currency
 (99.0, 'EUR')

Bulk lookup requests are also supported:

 >>> from amazon.api import AmazonAPI
 >>> amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)
 >>> products = amazon.lookup(ItemId='B00KC6I06S,B005DOK8NW,B00TSUGXKE')
 >>> len(products)
 5
 >>> products[0].asin
 'B0051QVESA'

If you'd rather get an empty list intead of exceptions use lookup_bulk() instead.

Search:

 >>> from amazon.api import AmazonAPI
 >>> amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)
 >>> products = amazon.search(Keywords='kindle', SearchIndex='All')
 >>> for i, product in enumerate(products):
 >>>     print "{0}. '{1}'".format(i, product.title)
 0. 'Kindle, Wi-Fi, 6" E Ink Display - includes Special Offers & Sponsored Screensavers'
 1. 'Kindle Fire, Full Color 7" Multi-touch Display, Wi-Fi'
 2. 'Kindle US Power Adapter (Not included with Kindle or Kindle Touch)'
 3. 'Kindle Touch, Wi-Fi, 6" E Ink Display - includes Special Offers & Sponsored Screensavers'
 4. 'Kindle Keyboard 3G, Free 3G + Wi-Fi, 6" E Ink Display - includes Special Offers & Sponsored Screensavers'
 5. 'Kindle Touch 3G, Free 3G + Wi-Fi, 6" E Ink Display - includes Special Offers & Sponsored Screensavers'
 ...
 49. 'Kindle Wireless Reading Device (6" Display, U.S. Wireless)'

The search method returns an iterable that will iterate through all products, on all pages available. Additional pages are retrieved automatically as needed. Keep in mind that Amazon limits the number of pages it makes available.

Valid values of SearchIndex are: 'All','Apparel','Appliances','ArtsAndCrafts','Automotive', 'Baby','Beauty','Blended','Books','Classical','Collectibles','DVD','DigitalMusic','Electronics', 'GiftCards','GourmetFood','Grocery','HealthPersonalCare','HomeGarden','Industrial','Jewelry', 'KindleStore','Kitchen','LawnAndGarden','Marketplace','MP3Downloads','Magazines','Miscellaneous', 'Music','MusicTracks','MusicalInstruments','MobileApps','OfficeProducts','OutdoorLiving','PCHardware', 'PetSupplies','Photo','Shoes','Software','SportingGoods','Tools','Toys','UnboxVideo','VHS','Video', 'VideoGames','Watches','Wireless','WirelessAccessories'

There is also a convenience method to search and return a list of the first N results:

 >>> from amazon.api import AmazonAPI
 >>> amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)
 >>> products = amazon.search_n(1, Keywords='kindle', SearchIndex='All')
 >>> len(products)
 1
 >>> products[0].title
 'Kindle, Wi-Fi, 6" E Ink Display - includes Special Offers & Sponsored Screensavers'

Similarity Lookup:

 >>> from amazon.api import AmazonAPI
 >>> amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)
 >>> products = amazon.similarity_lookup(ItemId='B0051QVESA,B005DOK8NW')
 >>> len(products)
 4

Browse Node Lookup:

 >>> from amazon.api import AmazonAPI
 >>> amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)
 >>> bn = amazon.browse_node_lookup(BrowseNodeId=2642129011)
 >>> bn.name
 'eBook Readers'

Create and manipulate Carts:

 >>> from amazon.api import AmazonAPI
 >>> amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)     
 >>> product = amazon.lookup(ItemId="B0016J8AOC")
 >>> item = {'offer_id': product.offer_id, 'quantity': 1}
 >>> cart = amazon.cart_create(item)
 >>> fetched_cart = amazon.cart_get(cart.cart_id, cart.hmac)
 >>> another_product = amazon.lookup(ItemId='0312098286')
 >>> another_item = {'offer_id': another_product.offer_id, 'quantity': 1}
 >>> another_cart = amazon.cart_add(another_item, cart.cart_id, cart.hmac)     
 >>> cart_item_id = None
 >>> for item in cart:
 >>>     cart_item_id = item.cart_item_id
 >>> modify_item = {'cart_item_id': cart_item_id, 'quantity': 3}
 >>> modified_cart = amazon.cart_modify(item, cart.cart_id, cart.hmac)     
 >>> cleared_cart = amazon.cart_clear(cart.cart_id, cart.hmac)

For the 'Books' SearchIndex a Power Search option is avaialble:

 >>> products = amazon.search(Power="subject:history and (spain or mexico) and not military and language:spanish",SearchIndex='Books')

For more information about these calls, please consult the Product Advertising API Developer Guide.

Tests

To run the test suite please follow these steps:

  • Make sure Nose is installed: (pip install nose)
  • Create a local file named: test_settings.py with the following variables set to the relevant values: AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG
  • Run nosetests

Pull Requests

  • All code should be unit tested
  • All tests must pass
  • Source code should be PEP8 complient
  • Coverage shouldn't decrease
  • All Pull Requests should be rebased against master before submitting the PR

This project is looking for core contributors. Please message me.

License

Copyright © 2012 Yoav Aviram

See LICENSE for details.

Owner
Yoav Aviram
Business Innovator, Entrepreneur, Investor, Independent Academic, Activist
Yoav Aviram
Stop writing scripts to interact with your APIs. Call them as CLIs instead.

Zum Stop writing scripts to interact with your APIs. Call them as CLIs instead. Zum (German word roughly meaning "to the" or "to" depending on the con

Daniel Leal 84 Nov 17, 2022
Benachrichtigungs-Bot für das niedersächische Impfportal / Notification bot for the lower saxony vaccination portal

Ein kleines Wochenend-Projekt von mir. Der Bot überwacht die REST-API des niedersächsischen Impfportals auf freie Impfslots und sendet eine Benachrichtigung mit deinem bevorzugtem Service. Ab da gilt

sibalzer 37 May 11, 2022
A simple telegram bot to forward files from one channel to other.

Forward_2.0 Bot to forward messages from one channel to other without admin permission in source channel. Can be used for both private and Public chan

SUBIN 56 Dec 29, 2022
A simple Python script using Telethon to log all (or some) messages a user or bot account can see on Telegram.

telegram-logger A simple Python script using Telethon to log all (or some) messages a user or bot account can see on Telegram. Requirements Python 3.6

Richard 13 Oct 06, 2022
Easy to use API Wrapper for somerandomapi.ml.

Overview somerandomapi is an API Wrapper for some-random-api.ml Examples Asynchronous from somerandomapi import Animal

Myxi 1 Dec 31, 2021
Accurately dump Commodore 64 tapes

TrueTape64 A cheap, easy to build adapter to interface a Commodore 1530 (C2N) Datasette to your PC to dump and preserve your aging Commodore 64 softwa

francesco 38 Dec 03, 2022
A python API wrapper for temp-mail.org

temp-mail Python API Wrapper for temp-mail.ru service. Temp-mail is a service which lets you use anonymous emails for free. You can view full API spec

Denis Veselov 91 Nov 19, 2022
Reads and prints information from the website MalAPI.io

MalAPIReader Reads and prints information from the website MalAPI.io optional arguments:

Squiblydoo 16 Nov 10, 2022
Wetterdienst - Open weather data for humans

We are a group of like-minded people trying to make access to weather data in Python feel like a warm summer breeze, similar to other projects like rdwd for the R language, which originally drew our

226 Jan 04, 2023
Python API wrapper around Trello's API

A wrapper around the Trello API written in Python. Each Trello object is represented by a corresponding Python object. The attributes of these objects

Richard Kolkovich 904 Jan 02, 2023
Métamorphose Renamer v2

Métamorphose 2 Métamorphose is a graphical mass renaming program for files and folders. These are the command line options: -h, --help Show hel

Métamorphose 129 Dec 30, 2022
Discord RPC for Notion written in Python

Discord RPC for Notion This is a program that allows you to add your Notion workspace activities to your Discord profile. This project is currently un

Thuliumitation 1 Feb 10, 2022
A Simple Telegram Bot By @AsmSafone to Download Files From Mega.nz and Upload It to Telegram

MegaDL-Bot A Simple Telegram Bot By @AsmSafone to Download Files From Mega.nz and Upload It to Telegram Features No Login Required All Mega.nz File Li

SAF ONE 92 Dec 02, 2022
This is a simple Python bot to identify sentiments in tweets

Twitter-Sentiment 👋 Hi There! 📱 This is a simple Python bot to identify sentiments in tweets 👨‍💻 This project was made for study, and pratice. You

Guilherme Silva 1 Oct 28, 2021
Automatically updates the twitter banner with the images of 5 latest followers, using tweepy python

Auto twitter banner Automatically updates the twitter banner every few seconds with follower profile pics on it Here's how it looks! Installation git

Dhravya Shah 7 Jul 04, 2022
Telegram music & video bot direct play music

Telegram music & video bot direct play music

noinoi-X 1 Dec 28, 2021
Snipe fair coin launches. Contact @dannsniper on telegram for whitelist

Pancakeswap-sniper Pancakeswap Sniper bot Full version of Pancakeswap sniping bot used to snipe during fair coin launches. With advanced options and a

36 Nov 01, 2021
A Git Alert Bot - Github Integration for Pyrogram & Telethon

Yet Another GitAlertBot Inspired From @Pokurt's GitGram Run Bot: Local Host Git Clone Repo : For Telethon Version : git clone https://github.com/DevsE

DevsExpo 23 Oct 21, 2022
DragDev Maintained Instance Of discord.py

discord.py - DragDev Flavour A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python. The Future of discord.py

DragDev Studios 3 Aug 27, 2022
A really easy way to display your spotify listening status on spotify.

Spotify playing README A really easy way to display your spotify listening status on READMEs and Websites too! Demo Here's the embed from the site. Cu

Sunrit Jana 21 Nov 06, 2022