|
1 | | -Amazon Product Advertising API 5.0 wrapper for Python |
2 | | -======================================================= |
3 | | -A simple Python wrapper for the [last version of the Amazon Product Advertising API](https://webservices.amazon.com/paapi5/documentation/quick-start/using-sdk.html). This module allows to get product information from Amazon using the official API in an easier way. |
| 1 | +# Amazon Product Advertising API 5.0 wrapper for Python |
| 2 | + |
| 3 | +A simple Python wrapper for the [last version of the Amazon Product Advertising API](https://webservices.amazon.com/paapi5/documentation/quick-start/using-sdk.html). This module allows interacting with Amazon using the official API in an easier way. |
4 | 4 |
|
5 | 5 | [](https://pypi.org/project/python-amazon-paapi/) |
6 | | -[](https://www.python.org/) |
| 6 | +[](https://www.python.org/) |
7 | 7 | [](https://github.com/sergioteula/python-amazon-paapi/blob/master/LICENSE) |
8 | 8 | [](https://github.com/sergioteula/python-amazon-paapi/issues) |
9 | 9 | [](https://webservices.amazon.com/paapi5/documentation/) |
10 | 10 |
|
| 11 | +> If you are still using the old version, go [here](https://github.com/sergioteula/python-amazon-paapi/blob/master/amazon/README). |
11 | 12 |
|
12 | | -Features |
13 | | --------- |
| 13 | +## Features |
14 | 14 |
|
15 | | -* Object oriented interface for simple usage. |
16 | | -* Get information about a product through its ASIN or URL. |
17 | | -* Get item variations or search for products on Amazon. |
18 | | -* Get browse nodes information. |
19 | | -* Get multiple results at once without the 10 items limitation from Amazon. |
20 | | -* Configurable throttling to avoid requests exceptions. |
21 | | -* Built-in serializer for Django REST framework. |
22 | | -* Support for [all available countries](https://github.com/sergioteula/python-amazon-paapi/blob/master/amazon/paapi.py#L31). |
23 | | -* Reorganized product information [structure](https://github.com/sergioteula/python-amazon-paapi/blob/master/PRODUCT.md) for simple use. |
24 | | -* Ask for new features through the [issues](https://github.com/sergioteula/python-amazon-paapi/issues) section. |
25 | | -* Join our [Telegram group](https://t.me/PythonAmazonPAAPI) for support or development. |
| 15 | +- Object oriented interface for simple usage. |
| 16 | +- Get information about a product through its ASIN or URL. |
| 17 | +- Get item variations or search for products on Amazon. |
| 18 | +- Get browse nodes information. |
| 19 | +- Get multiple results at once without the 10 items limitation from Amazon. |
| 20 | +- Configurable throttling to avoid requests exceptions. |
| 21 | +- Type hints to help you coding. |
| 22 | +- Support for [all available countries](https://github.com/sergioteula/python-amazon-paapi/blob/master/amazon/paapi.py#L31). |
| 23 | +- Ask for new features through the [issues](https://github.com/sergioteula/python-amazon-paapi/issues) section. |
| 24 | +- Join our [Telegram group](https://t.me/PythonAmazonPAAPI) for support or development. |
26 | 25 |
|
27 | | -Installation |
28 | | -------------- |
| 26 | +## Installation |
29 | 27 |
|
30 | 28 | You can install or upgrade the module with: |
31 | 29 |
|
32 | 30 | pip install python-amazon-paapi --upgrade |
33 | 31 |
|
34 | | -If you get `ModuleNotFoundError`, try installing this: |
35 | | - |
36 | | - pip install amightygirl.paapi5-python-sdk |
| 32 | +## Usage guide |
37 | 33 |
|
38 | | -Usage guide |
39 | | ------------ |
40 | 34 | **Basic usage:** |
41 | 35 |
|
42 | | -````python |
43 | | -from amazon.paapi import AmazonAPI |
44 | | -amazon = AmazonAPI(KEY, SECRET, TAG, COUNTRY) |
45 | | -product = amazon.get_product('B01N5IB20Q') |
46 | | -print(product.title) |
47 | | -```` |
| 36 | +```python |
| 37 | +from amazon_paapi import AmazonApi |
| 38 | +amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY) |
| 39 | +item = amazon.get_items('B01N5IB20Q')[0] |
| 40 | +print(item.item_info.title.display_value) # Item title |
| 41 | +``` |
48 | 42 |
|
49 | | -**Get multiple product information:** |
| 43 | +**Get multiple items information:** |
50 | 44 |
|
51 | | -````python |
52 | | -product = amazon.get_products('B01N5IB20Q,B01F9G43WU') |
53 | | -print(product[0].images.large) |
54 | | -print(product[1].prices.price.value) |
55 | | -```` |
| 45 | +```python |
| 46 | +items = amazon.get_items(['B01N5IB20Q', 'B01F9G43WU']) |
| 47 | +for item in items: |
| 48 | + print(item.images.primary.large.url) # Primary image url |
| 49 | + print(item.offers.listings[0].price.amount) # Current price |
| 50 | +``` |
56 | 51 |
|
57 | 52 | **Use URL insted of ASIN:** |
58 | 53 |
|
59 | | -````python |
60 | | -product = amazon.get_product('https://www.amazon.com/dp/B01N5IB20Q') |
61 | | -```` |
| 54 | +```python |
| 55 | +item = amazon.get_items('https://www.amazon.com/dp/B01N5IB20Q') |
| 56 | +``` |
62 | 57 |
|
63 | | -**Get product variations:** |
| 58 | +**Get item variations:** |
64 | 59 |
|
65 | | -````python |
66 | | -product = amazon.get_variations('B01N5IB20Q') |
67 | | -print(product[0].title) |
68 | | -```` |
| 60 | +```python |
| 61 | +variations = amazon.get_variations('B01N5IB20Q') |
| 62 | +for item in variations.items: |
| 63 | + print(item.detail_page_url) # Affiliate url |
| 64 | +``` |
69 | 65 |
|
70 | | -**Search product:** |
| 66 | +**Search items:** |
71 | 67 |
|
72 | | -````python |
73 | | -product = amazon.search_products(item_count=25, keywords='speaker') |
74 | | -print(product[14].url) |
75 | | -```` |
| 68 | +```python |
| 69 | +search_result = amazon.search_items(keywords='nintendo') |
| 70 | +for item in search_result.items: |
| 71 | + print(item.item_info.product_info.color) # Item color |
| 72 | +``` |
76 | 73 |
|
77 | 74 | **Get browse node information:** |
78 | 75 |
|
79 | | -````python |
80 | | -node = amazon.get_browsenodes(browse_nodes=browsenodes_list) |
81 | | -```` |
| 76 | +```python |
| 77 | +browse_nodes = amazon.get_browse_nodes(['667049031', '599385031']) |
| 78 | +for browse_node in browse_nodes: |
| 79 | + print(browse_node.display_name) # The name of the node |
| 80 | +``` |
82 | 81 |
|
83 | | -**Get the ASIN from a URL:** |
| 82 | +**Get the ASIN from URL:** |
84 | 83 |
|
85 | | -````python |
86 | | -from amazon.tools import get_asin |
| 84 | +```python |
| 85 | +from amazon_paapi import get_asin |
87 | 86 | asin = get_asin('https://www.amazon.com/dp/B01N5IB20Q') |
88 | | -```` |
| 87 | +``` |
89 | 88 |
|
90 | 89 | **Throttling:** |
91 | 90 |
|
92 | | -Throttling value must be `greater than 0` or `False` to disable it. This value throttles requests to a maximum of one request every `1 / value` seconds. Note that this value is a per-worker throttling, so applications with multiple workers may make more requests per second. Throttling value is [set by default](https://github.com/sergioteula/python-amazon-paapi/blob/master/amazon/paapi.py#L36) to `0.8` or one request every 1.25 seconds. |
93 | | - |
94 | | -````python |
95 | | -amazon = AmazonAPI(KEY, SECRET, TAG, COUNTRY, throttling=0.5) # Max one request every two seconds |
96 | | -amazon = AmazonAPI(KEY, SECRET, TAG, COUNTRY, throttling=False) # Unlimited requests per second |
97 | | -```` |
98 | | - |
99 | | -**Serializer for Django:** |
100 | | - |
101 | | -We provide a serializer for Django REST framework, which speeds up your API |
102 | | -implementation. |
103 | | - |
104 | | -````python |
105 | | -from amazon.serializers import AmazonProductSerializer |
106 | | -from rest_framework import serializers |
107 | | - |
108 | | -serialized_product = AmazonProductSerializer(product) |
109 | | -serialized_product.data |
110 | | -```` |
111 | | - |
112 | | -If you want to serialize a list of products: |
| 91 | +Throttling value represents the wait time in seconds between API calls, being the default value 1 second. Use it to avoid reaching Amazon request limits. |
113 | 92 |
|
114 | | -````python |
115 | | -serialized_products = AmazonProductSerializer(products, many=True) |
116 | | -serialized_products.data |
117 | | -```` |
| 93 | +```python |
| 94 | +amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY, throttling=4) # Makes 1 request every 4 seconds |
| 95 | +amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY, throttling=0) # No wait time between requests |
| 96 | +``` |
118 | 97 |
|
119 | | -For more information on how to work with serializers, check the documentation for |
120 | | -[Django REST framework](https://www.django-rest-framework.org/api-guide/serializers/). |
| 98 | +## License |
121 | 99 |
|
122 | | -License |
123 | | -------------- |
124 | | -Copyright © 2020 Sergio Abad. See [license](https://github.com/sergioteula/python-amazon-paapi/blob/master/LICENSE) for details. |
| 100 | +Copyright © 2021 Sergio Abad. See [license](https://github.com/sergioteula/python-amazon-paapi/blob/master/LICENSE) for details. |
0 commit comments