Skip to content

Commit 4375f17

Browse files
committed
Added get_product for single requests
1 parent 991995e commit 4375f17

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Basic usage:
3434

3535
from amazon.paapi import AmazonAPI
3636
amazon = AmazonAPI(KEY, SECRET, TAG, COUNTRY)
37-
product = amazon.get_products('B01N5IB20Q')
37+
product = amazon.get_product('B01N5IB20Q')
3838
print(product.title)
3939

4040
Get multiple product information:
@@ -45,7 +45,7 @@ Get multiple product information:
4545

4646
Use URL insted of ASIN:
4747

48-
product = amazon.get_products('https://www.amazon.com/dp/B01N5IB20Q')
48+
product = amazon.get_product('https://www.amazon.com/dp/B01N5IB20Q')
4949

5050
Get the ASIN from a URL:
5151

@@ -54,6 +54,9 @@ Get the ASIN from a URL:
5454

5555
Changelog
5656
-------------
57+
Version 2.1.1
58+
- Added get_product for single requests.
59+
5760
Version 2.1.0
5861
- Changed get_product method name to get_products.
5962
- Removed Amazon 10 products limitation.

amazon/paapi.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,10 +559,7 @@ def get_products(self, product_ids: [str, list], condition=Condition.ANY):
559559
condition (class, optional): Specify the product condition. Defaults to ANY.
560560
561561
Returns:
562-
class instance: An instance of the class Product containing all the available
563-
information when only 1 product is returned.
564-
list of class instances: A list containing 1 instance of the class Product for
565-
each returned product.
562+
list of instances: A list containing 1 instance for each product.
566563
"""
567564
api = DefaultApi(access_key=self.key,
568565
secret_key=self.secret,
@@ -667,3 +664,19 @@ class instance: An instance of the class Product containing all the available
667664
return results
668665
else:
669666
return None
667+
668+
def get_product(self, product_id: str, condition=Condition.ANY):
669+
"""Find product information for a specific product on Amazon.
670+
671+
Args:
672+
product_id (string): One item id like ASIN or product URL.
673+
condition (class, optional): Specify the product condition. Defaults to ANY.
674+
675+
Returns:
676+
class instance: An instance containing all the available information for the product.
677+
"""
678+
if isinstance(product_id, list):
679+
raise Exception('product_id should be a string with an ASIN or product URL')
680+
if isinstance(product_id, str):
681+
product_id = product_id.split(',')[0].strip()
682+
return self.get_products(product_id, condition=condition)[0]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name='python-amazon-paapi',
8-
version='2.1.0',
8+
version='2.1.1',
99
author='Sergio Abad',
1010
author_email='sergio.abad@bytelix.com',
1111
description='Amazon Product Advertising API 5.0 wrapper for Python',

0 commit comments

Comments
 (0)