Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sergioteula committed Jul 13, 2021
2 parents 5ce054f + 3107f05 commit 956f639
Show file tree
Hide file tree
Showing 226 changed files with 20,654 additions and 8,295 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Custom folders and files to ignore
.vscode/
.DS_Store
secrets.py


# Byte-compiled / optimized / DLL files
Expand Down
128 changes: 0 additions & 128 deletions PRODUCT.md

This file was deleted.

148 changes: 62 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,124 +1,100 @@
Amazon Product Advertising API 5.0 wrapper for Python
=======================================================
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.
# Amazon Product Advertising API 5.0 wrapper for Python

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.

[![PyPI](https://img.shields.io/pypi/v/python-amazon-paapi?color=%231182C2&label=PyPI)](https://pypi.org/project/python-amazon-paapi/)
[![Python](https://img.shields.io/badge/Python-2.x%20%7C%203.x-%23FFD140)](https://www.python.org/)
[![Python](https://img.shields.io/badge/Python->3.6-%23FFD140)](https://www.python.org/)
[![License](https://img.shields.io/badge/License-MIT-%23e83633)](https://github.com/sergioteula/python-amazon-paapi/blob/master/LICENSE)
[![Support](https://img.shields.io/badge/Support-Good-brightgreen)](https://github.com/sergioteula/python-amazon-paapi/issues)
[![Amazon API](https://img.shields.io/badge/Amazon%20API-5.0-%23FD9B15)](https://webservices.amazon.com/paapi5/documentation/)

> If you are still using the old version, go [here](https://github.com/sergioteula/python-amazon-paapi/blob/master/amazon/README).
Features
--------
## Features

* Object oriented interface for simple usage.
* Get information about a product through its ASIN or URL.
* Get item variations or search for products on Amazon.
* Get browse nodes information.
* Get multiple results at once without the 10 items limitation from Amazon.
* Configurable throttling to avoid requests exceptions.
* Built-in serializer for Django REST framework.
* Support for [all available countries](https://github.com/sergioteula/python-amazon-paapi/blob/master/amazon/paapi.py#L31).
* Reorganized product information [structure](https://github.com/sergioteula/python-amazon-paapi/blob/master/PRODUCT.md) for simple use.
* Ask for new features through the [issues](https://github.com/sergioteula/python-amazon-paapi/issues) section.
* Join our [Telegram group](https://t.me/PythonAmazonPAAPI) for support or development.
- Object oriented interface for simple usage.
- Get information about a product through its ASIN or URL.
- Get item variations or search for products on Amazon.
- Get browse nodes information.
- Get multiple results at once without the 10 items limitation from Amazon.
- Configurable throttling to avoid requests exceptions.
- Type hints to help you coding.
- Support for [all available countries](https://github.com/sergioteula/python-amazon-paapi/blob/master/amazon/paapi.py#L31).
- Ask for new features through the [issues](https://github.com/sergioteula/python-amazon-paapi/issues) section.
- Join our [Telegram group](https://t.me/PythonAmazonPAAPI) for support or development.

Installation
-------------
## Installation

You can install or upgrade the module with:

pip install python-amazon-paapi --upgrade

If you get `ModuleNotFoundError`, try installing this:

pip install amightygirl.paapi5-python-sdk
## Usage guide

Usage guide
-----------
**Basic usage:**

````python
from amazon.paapi import AmazonAPI
amazon = AmazonAPI(KEY, SECRET, TAG, COUNTRY)
product = amazon.get_product('B01N5IB20Q')
print(product.title)
````
```python
from amazon_paapi import AmazonApi
amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY)
item = amazon.get_items('B01N5IB20Q')[0]
print(item.item_info.title.display_value) # Item title
```

**Get multiple product information:**
**Get multiple items information:**

````python
product = amazon.get_products('B01N5IB20Q,B01F9G43WU')
print(product[0].images.large)
print(product[1].prices.price.value)
````
```python
items = amazon.get_items(['B01N5IB20Q', 'B01F9G43WU'])
for item in items:
print(item.images.primary.large.url) # Primary image url
print(item.offers.listings[0].price.amount) # Current price
```

**Use URL insted of ASIN:**

````python
product = amazon.get_product('https://www.amazon.com/dp/B01N5IB20Q')
````
```python
item = amazon.get_items('https://www.amazon.com/dp/B01N5IB20Q')
```

**Get product variations:**
**Get item variations:**

````python
product = amazon.get_variations('B01N5IB20Q')
print(product[0].title)
````
```python
variations = amazon.get_variations('B01N5IB20Q')
for item in variations.items:
print(item.detail_page_url) # Affiliate url
```

**Search product:**
**Search items:**

````python
product = amazon.search_products(item_count=25, keywords='speaker')
print(product[14].url)
````
```python
search_result = amazon.search_items(keywords='nintendo')
for item in search_result.items:
print(item.item_info.product_info.color) # Item color
```

**Get browse node information:**

````python
node = amazon.get_browsenodes(browse_nodes=browsenodes_list)
````
```python
browse_nodes = amazon.get_browse_nodes(['667049031', '599385031'])
for browse_node in browse_nodes:
print(browse_node.display_name) # The name of the node
```

**Get the ASIN from a URL:**
**Get the ASIN from URL:**

````python
from amazon.tools import get_asin
```python
from amazon_paapi import get_asin
asin = get_asin('https://www.amazon.com/dp/B01N5IB20Q')
````
```

**Throttling:**

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.

````python
amazon = AmazonAPI(KEY, SECRET, TAG, COUNTRY, throttling=0.5) # Max one request every two seconds
amazon = AmazonAPI(KEY, SECRET, TAG, COUNTRY, throttling=False) # Unlimited requests per second
````

**Serializer for Django:**

We provide a serializer for Django REST framework, which speeds up your API
implementation.

````python
from amazon.serializers import AmazonProductSerializer
from rest_framework import serializers

serialized_product = AmazonProductSerializer(product)
serialized_product.data
````

If you want to serialize a list of products:
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.

````python
serialized_products = AmazonProductSerializer(products, many=True)
serialized_products.data
````
```python
amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY, throttling=4) # Makes 1 request every 4 seconds
amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY, throttling=0) # No wait time between requests
```

For more information on how to work with serializers, check the documentation for
[Django REST framework](https://www.django-rest-framework.org/api-guide/serializers/).
## License

License
-------------
Copyright © 2020 Sergio Abad. See [license](https://github.com/sergioteula/python-amazon-paapi/blob/master/LICENSE) for details.
Copyright © 2021 Sergio Abad. See [license](https://github.com/sergioteula/python-amazon-paapi/blob/master/LICENSE) for details.
Loading

0 comments on commit 956f639

Please sign in to comment.