Skip to content

Commit d828e81

Browse files
committed
Merge branch 'developer'
2 parents 674a702 + cd411bf commit d828e81

8 files changed

Lines changed: 193 additions & 10 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ A simple Python wrapper for the [last version of the Amazon Product Advertising
88
[![Support](https://img.shields.io/badge/Support-Good-brightgreen)](https://github.com/sergioteula/python-amazon-paapi/issues)
99
[![Amazon API](https://img.shields.io/badge/Amazon%20API-5.0-%23FD9B15)](https://webservices.amazon.com/paapi5/documentation/)
1010

11-
> If you are still using the old version, go [here](https://github.com/sergioteula/python-amazon-paapi/blob/master/amazon/README.md) for documentation.
11+
> If you are still using the old version, go [here](https://github.com/sergioteula/python-amazon-paapi/blob/master/amazon/README.md) for documentation or check our
12+
[migration guide](https://github.com/sergioteula/python-amazon-paapi/docs/pages/migration-guide.md).
1213

1314
## Features
1415

docs/amazon_paapi.errors.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
amazon\_paapi.errors package
1+
Exceptions Module
22
============================
33

44
.. automodule:: amazon_paapi.errors.exceptions

docs/amazon_paapi.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
amazon\_paapi package
1+
AmazonApi Module
22
=====================
33

4-
.. automodule:: amazon_paapi.api
4+
This is the main class that provides authentication and methods for accessing the Amazon Product
5+
Advertising API. Instance it with your credentials and configuration.
6+
7+
.. autoclass:: amazon_paapi.api.AmazonApi
58
:members:
69
:undoc-members:
710
:show-inheritance:

docs/amazon_paapi.tools.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
amazon\_paapi.tools package
1+
Tools Module
22
===========================
33

44
.. automodule:: amazon_paapi.tools.asin

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
# ones.
3333
extensions = [
3434
'sphinx.ext.autodoc',
35-
'sphinx.ext.napoleon'
35+
'sphinx.ext.napoleon',
36+
'myst_parser'
3637
]
3738

3839
# Don't show type hints in the signature - that just makes it hardly readable

docs/index.rst

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,32 @@
66
Welcome to Python Amazon PAAPI's documentation!
77
===============================================
88

9-
Reference
10-
=========
9+
A simple Python wrapper for the last version of the Amazon Product Advertising API. This module allows
10+
interacting with Amazon using the official API in an easier way.
1111

12-
Below you can access the documentation for the main class, as well as errors and tools. To check some
13-
usage examples please go to the `readme <https://github.com/sergioteula/python-amazon-paapi>`_ on GitHub.
12+
Reference
13+
---------
1414

1515
.. toctree::
1616

1717
amazon_paapi
1818
amazon_paapi.errors
1919
amazon_paapi.tools
20+
21+
Usage guide
22+
---------------
23+
24+
.. toctree::
25+
:maxdepth: 1
26+
27+
./pages/usage-guide.md
28+
29+
Migration guide
30+
---------------
31+
32+
If you are still using version 3.x or lower, it is highly recommended upgrading to the latest version.
33+
34+
.. toctree::
35+
:maxdepth: 1
36+
37+
./pages/migration-guide.md

docs/pages/migration-guide.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Migration guide
2+
3+
This guide explains how to proceed with the migration from version 3.x to version 4.x of your current code.
4+
If you are still using the old version, it is highly recommended to update, since you wont get any future
5+
updates nor new features.
6+
7+
## Changelog summary
8+
9+
- Added type hinting to help you code.
10+
- Added compatibility with all arguments from the official API.
11+
- Now the full information from the API is returned, instead of a trimmed version.
12+
- Added custom exceptions to help with error handling.
13+
- Added models for some attributes.
14+
- Adjusted all methods and models to meet Amazon API standards.
15+
- Changed module name from amazon to amazon_paapi to avoid module clashes.
16+
- Compatibility with Python 3.6 or later.
17+
18+
## How to upgrade?
19+
20+
Upgrading to the last version of this module is as easy as running this pip command:
21+
22+
pip install python-amazon-paapi --upgrade
23+
24+
## What should I change in my current code?
25+
26+
### Imports
27+
28+
First of all, you should change your import of the AmazonApi class:
29+
30+
```python
31+
from amazon.paapi import AmazonApi -> from amazon_paapi import AmazonApi
32+
from amazon.tools import get_asin -> from amazon_paapi import get_asin
33+
```
34+
35+
### Methods
36+
37+
Some of the methods has been renamed and the parameters has changed to follow the official Amazon API standards.
38+
So in order to adapt your code, you should first update your methods as follow:
39+
40+
```python
41+
get_product() -> get_items()
42+
get_products() -> get_items()
43+
search_products() -> search_items()
44+
get_browsenodes() -> get_browse_nodes()
45+
```
46+
47+
As you can check, `get_product` has been deprecated and now `get_items` is also used for getting only one result.
48+
So if you were using this method, you should keep in mind that the new method will return an array containing the
49+
result. An easy way of handling this could be:
50+
51+
```python
52+
result = get_product(asin) -> result = get_items(asin)[0]
53+
```
54+
55+
Regarding parameters, you can check the [AmazonApi documentation](/amazon_paapi) for the complete reference.
56+
57+
### Results
58+
59+
Results has been changed from previous version, so you will need to adapt how you process them. This change
60+
follows the official Amazon Product Advertising API documentation, so you can
61+
[check it](https://webservices.amazon.com/paapi5/documentation/operations.html) for reference. Just note that
62+
documentation uses `CamelCase` names, but this module uses `snake_case`:
63+
64+
ItemInfo.ContentInfo -> item_info.content_info
65+
Offers.Listings.Price -> offers.listings.price
66+
67+
Type hints has been added to the new version, so it is highly recommended to use an IDE that includes code
68+
completion features, like [Visual Studio Code](https://code.visualstudio.com/).
69+
70+
### Throttling
71+
72+
Throttling parameter now represents the seconds to wait between API calls instead of the frequency. So make sure
73+
to adapt the value to your needs.
74+
75+
```python
76+
amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY, throttling=4) # Makes 1 request every 4 seconds
77+
amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY, throttling=0) # No wait time between requests
78+
```
79+
80+
### Serializer for Django
81+
82+
The serializer for Django is not available for this new version. If you want to help with the migration, send a
83+
pull request and will be added on future updates.
84+
85+
### I need more help
86+
87+
You can always ask for help in our [Telegram group](https://t.me/PythonAmazonPAAPI) or raise an issue on
88+
[Github](https://github.com/sergioteula/python-amazon-paapi/issues) for help. If you find that this
89+
guide could be improved somehow, feel free to send a pull request with your changes.

docs/pages/usage-guide.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Installation
2+
3+
You can install or upgrade the module with:
4+
5+
pip install python-amazon-paapi --upgrade
6+
7+
# Usage guide
8+
9+
**Basic usage:**
10+
11+
```python
12+
from amazon_paapi import AmazonApi
13+
amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY)
14+
item = amazon.get_items('B01N5IB20Q')[0]
15+
print(item.item_info.title.display_value) # Item title
16+
```
17+
18+
**Get multiple items information:**
19+
20+
```python
21+
items = amazon.get_items(['B01N5IB20Q', 'B01F9G43WU'])
22+
for item in items:
23+
print(item.images.primary.large.url) # Primary image url
24+
print(item.offers.listings[0].price.amount) # Current price
25+
```
26+
27+
**Use URL insted of ASIN:**
28+
29+
```python
30+
item = amazon.get_items('https://www.amazon.com/dp/B01N5IB20Q')
31+
```
32+
33+
**Get item variations:**
34+
35+
```python
36+
variations = amazon.get_variations('B01N5IB20Q')
37+
for item in variations.items:
38+
print(item.detail_page_url) # Affiliate url
39+
```
40+
41+
**Search items:**
42+
43+
```python
44+
search_result = amazon.search_items(keywords='nintendo')
45+
for item in search_result.items:
46+
print(item.item_info.product_info.color) # Item color
47+
```
48+
49+
**Get browse node information:**
50+
51+
```python
52+
browse_nodes = amazon.get_browse_nodes(['667049031', '599385031'])
53+
for browse_node in browse_nodes:
54+
print(browse_node.display_name) # The name of the node
55+
```
56+
57+
**Get the ASIN from URL:**
58+
59+
```python
60+
from amazon_paapi import get_asin
61+
asin = get_asin('https://www.amazon.com/dp/B01N5IB20Q')
62+
```
63+
64+
**Throttling:**
65+
66+
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.
67+
68+
```python
69+
amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY, throttling=4) # Makes 1 request every 4 seconds
70+
amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY, throttling=0) # No wait time between requests
71+
```

0 commit comments

Comments
 (0)