Skip to content

Commit 20de236

Browse files
authored
Merge pull request #141 from sergioteula/implement-offers-v2
Implement offers v2
2 parents fcd1c21 + 2f23718 commit 20de236

File tree

122 files changed

+3618
-338
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+3618
-338
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [5.2.0] - 2026-01-11
9+
10+
### Added
11+
12+
- Support for OffersV2 resources with new model classes ([#141](https://github.com/sergioteula/python-amazon-paapi/pull/141))
13+
814
## [5.1.0] - 2026-01-11
915

1016
### Added

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ A simple Python wrapper for the [Amazon Product Advertising API 5.0](https://web
1414
- 🔍 **Product search** by keywords, categories, or browse nodes
1515
- 📦 **Product details** via ASIN or Amazon URL
1616
- 🔄 **Item variations** support (size, color, etc.)
17+
- 💰 **OffersV2 support** for enhanced pricing and offer details
1718
- 🌍 **20+ countries** supported ([full list](https://github.com/sergioteula/python-amazon-paapi/blob/master/amazon_paapi/models/regions.py))
1819
-**Batch requests** to get multiple items without the 10-item limit
1920
- 🛡️ **Built-in throttling** to avoid API rate limits
@@ -40,6 +41,18 @@ print(item.item_info.title.display_value)
4041

4142
## Usage Examples
4243

44+
### Using OffersV2 resources
45+
46+
OffersV2 provides enhanced pricing and offer details. All resources are included by default, so OffersV2 data is available without any additional configuration:
47+
48+
```python
49+
item = amazon.get_items('B01N5IB20Q')[0]
50+
if item.offers_v2 and item.offers_v2.listings:
51+
listing = item.offers_v2.listings[0]
52+
print(listing.price.money.amount) # Price amount
53+
print(listing.merchant_info.name) # Merchant name
54+
```
55+
4356
### Get Multiple Products
4457

4558
```python

amazon_paapi/models/item_result.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,99 @@ class ApiBrowseNodeInfo(sdk_models.BrowseNodeInfo):
340340
website_sales_rank: ApiWebsiteSalesRank
341341

342342

343+
class ApiMoney(sdk_models.Money):
344+
"""Money representation for OffersV2 price fields."""
345+
346+
amount: float
347+
currency: str
348+
display_amount: str
349+
350+
351+
class ApiOfferAvailabilityV2(sdk_models.OfferAvailabilityV2):
352+
"""OffersV2 availability information."""
353+
354+
max_order_quantity: int
355+
message: str
356+
min_order_quantity: int
357+
type: str
358+
359+
360+
class ApiOfferConditionV2(sdk_models.OfferConditionV2):
361+
"""OffersV2 condition information."""
362+
363+
condition_note: str
364+
sub_condition: str
365+
value: str
366+
367+
368+
class ApiDealDetails(sdk_models.DealDetails):
369+
"""Deal details for OffersV2 listings."""
370+
371+
access_type: str
372+
badge: str
373+
early_access_duration_in_milliseconds: int
374+
end_time: str
375+
percent_claimed: int
376+
start_time: str
377+
378+
379+
class ApiOfferLoyaltyPointsV2(sdk_models.OfferLoyaltyPointsV2):
380+
"""OffersV2 loyalty points information."""
381+
382+
points: int
383+
384+
385+
class ApiOfferMerchantInfoV2(sdk_models.OfferMerchantInfoV2):
386+
"""OffersV2 merchant information."""
387+
388+
id: str
389+
name: str
390+
391+
392+
class ApiOfferSavingBasis(sdk_models.OfferSavingBasis):
393+
"""Saving basis information for OffersV2."""
394+
395+
money: ApiMoney
396+
saving_basis_type: str
397+
saving_basis_type_label: str
398+
399+
400+
class ApiOfferSavingsV2(sdk_models.OfferSavingsV2):
401+
"""OffersV2 savings information."""
402+
403+
money: ApiMoney
404+
percentage: int
405+
406+
407+
class ApiOfferPriceV2(sdk_models.OfferPriceV2):
408+
"""OffersV2 price information."""
409+
410+
money: ApiMoney
411+
price_per_unit: ApiMoney
412+
saving_basis: ApiOfferSavingBasis
413+
savings: ApiOfferSavingsV2
414+
415+
416+
class ApiListingsV2(sdk_models.OfferListingV2):
417+
"""OffersV2 listing with all details."""
418+
419+
availability: ApiOfferAvailabilityV2
420+
condition: ApiOfferConditionV2
421+
deal_details: ApiDealDetails
422+
is_buy_box_winner: bool
423+
loyalty_points: ApiOfferLoyaltyPointsV2
424+
merchant_info: ApiOfferMerchantInfoV2
425+
price: ApiOfferPriceV2
426+
type: sdk_models.OfferType
427+
violates_map: bool
428+
429+
430+
class ApiOffersV2(sdk_models.OffersV2):
431+
"""Container for OffersV2 listings."""
432+
433+
listings: list[ApiListingsV2]
434+
435+
343436
class Item(sdk_models.Item):
344437
"""Amazon product item with all details."""
345438

@@ -350,6 +443,7 @@ class Item(sdk_models.Item):
350443
images: ApiImages
351444
item_info: ApiItemInfo
352445
offers: ApiOffers
446+
offers_v2: ApiOffersV2
353447
parent_asin: str
354448
rental_offers: sdk_models.RentalOffers
355449
score: float

amazon_paapi/sdk/__init__.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import absolute_import
66

77
"""
8-
Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
8+
Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
99
1010
Licensed under the Apache License, Version 2.0 (the "License").
1111
You may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@
3838
from .configuration import Configuration
3939
# import models into sdk package
4040
from .models.availability import Availability
41+
from .models.big_decimal import BigDecimal
4142
from .models.browse_node import BrowseNode
4243
from .models.browse_node_ancestor import BrowseNodeAncestor
4344
from .models.browse_node_child import BrowseNodeChild
@@ -50,6 +51,7 @@
5051
from .models.content_rating import ContentRating
5152
from .models.contributor import Contributor
5253
from .models.customer_reviews import CustomerReviews
54+
from .models.deal_details import DealDetails
5355
from .models.delivery_flag import DeliveryFlag
5456
from .models.dimension_based_attribute import DimensionBasedAttribute
5557
from .models.duration_price import DurationPrice
@@ -79,25 +81,39 @@
7981
from .models.min_price import MinPrice
8082
from .models.min_reviews_rating import MinReviewsRating
8183
from .models.min_saving_percent import MinSavingPercent
84+
from .models.money import Money
8285
from .models.multi_valued_attribute import MultiValuedAttribute
8386
from .models.offer_availability import OfferAvailability
87+
from .models.offer_availability_v2 import OfferAvailabilityV2
8488
from .models.offer_condition import OfferCondition
8589
from .models.offer_condition_note import OfferConditionNote
90+
from .models.offer_condition_v2 import OfferConditionV2
8691
from .models.offer_count import OfferCount
8792
from .models.offer_delivery_info import OfferDeliveryInfo
8893
from .models.offer_listing import OfferListing
94+
from .models.offer_listing_v2 import OfferListingV2
95+
from .models.offer_listings import OfferListings
96+
from .models.offer_listings_v2 import OfferListingsV2
8997
from .models.offer_loyalty_points import OfferLoyaltyPoints
98+
from .models.offer_loyalty_points_v2 import OfferLoyaltyPointsV2
9099
from .models.offer_merchant_info import OfferMerchantInfo
100+
from .models.offer_merchant_info_v2 import OfferMerchantInfoV2
91101
from .models.offer_price import OfferPrice
102+
from .models.offer_price_v2 import OfferPriceV2
92103
from .models.offer_program_eligibility import OfferProgramEligibility
93104
from .models.offer_promotion import OfferPromotion
105+
from .models.offer_saving_basis import OfferSavingBasis
94106
from .models.offer_savings import OfferSavings
107+
from .models.offer_savings_v2 import OfferSavingsV2
95108
from .models.offer_shipping_charge import OfferShippingCharge
96109
from .models.offer_sub_condition import OfferSubCondition
97110
from .models.offer_summary import OfferSummary
111+
from .models.offer_type import OfferType
98112
from .models.offers import Offers
113+
from .models.offers_v2 import OffersV2
99114
from .models.partner_type import PartnerType
100115
from .models.price import Price
116+
from .models.price_type import PriceType
101117
from .models.product_advertising_api_client_exception import ProductAdvertisingAPIClientException
102118
from .models.product_advertising_api_service_exception import ProductAdvertisingAPIServiceException
103119
from .models.product_info import ProductInfo
@@ -107,6 +123,8 @@
107123
from .models.refinement_bin import RefinementBin
108124
from .models.rental_offer_listing import RentalOfferListing
109125
from .models.rental_offers import RentalOffers
126+
from .models.saving_basis_type import SavingBasisType
127+
from .models.search_index import SearchIndex
110128
from .models.search_items_request import SearchItemsRequest
111129
from .models.search_items_resource import SearchItemsResource
112130
from .models.search_items_response import SearchItemsResponse

amazon_paapi/sdk/api/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import absolute_import
66

77
"""
8-
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
8+
Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
99
1010
Licensed under the Apache License, Version 2.0 (the "License").
1111
You may not use this file except in compliance with the License.
@@ -25,6 +25,5 @@
2525
https://webservices.amazon.com/paapi5/documentation/index.html # noqa: E501
2626
"""
2727

28-
2928
# import apis into api package
30-
from .default_api import DefaultApi
29+
from ..api.default_api import DefaultApi

amazon_paapi/sdk/api/default_api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import absolute_import
66

77
"""
8-
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
8+
Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
99
1010
Licensed under the Apache License, Version 2.0 (the "License").
1111
You may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@
2525
https://webservices.amazon.com/paapi5/documentation/index.html # noqa: E501
2626
"""
2727

28-
2928
import re # noqa: F401
3029

3130
# python 2 and python 3 compatibility library

amazon_paapi/sdk/api_client.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import absolute_import
66

77
"""
8-
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
8+
Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
99
1010
Licensed under the Apache License, Version 2.0 (the "License").
1111
You may not use this file except in compliance with the License.
@@ -95,21 +95,16 @@ def __init__(self,
9595
self.default_headers[header_name] = header_value
9696
self.cookie = cookie
9797
# Set default User-Agent.
98-
self.user_agent = 'paapi5-python-sdk/1.0.0'
98+
self.user_agent = 'paapi5-python-sdk/1.2.4'
9999

100100
self.access_key = access_key
101101
self.secret_key = secret_key
102102
self.host = host
103103
self.region = region
104104

105105
def __del__(self):
106-
try:
107-
self.pool.close()
108-
self.pool.join()
109-
except (OSError, TypeError):
110-
# Ignore errors during interpreter shutdown when file descriptors
111-
# or other resources may already be deallocated
112-
pass
106+
self.pool.close()
107+
self.pool.join()
113108

114109
@property
115110
def user_agent(self):
@@ -529,7 +524,7 @@ def update_params_for_auth(self, headers, querys, auth_settings, api_name, metho
529524
"""
530525
if not auth_settings:
531526
service = 'ProductAdvertisingAPI'
532-
utc_timestamp = datetime.datetime.utcnow()
527+
utc_timestamp = datetime.datetime.now(datetime.timezone.utc)
533528
headers['x-amz-target'] = 'com.amazon.paapi5.v1.ProductAdvertisingAPIv1.' + api_name
534529
headers['content-encoding'] = 'amz-1.0'
535530
headers['Content-Type'] = 'application/json; charset=utf-8'

amazon_paapi/sdk/auth/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
"""
3131

3232
# import auth into sdk package
33-
from .sign_helper import AWSV4Auth
33+
from ..auth.sign_helper import AWSV4Auth

amazon_paapi/sdk/configuration.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import absolute_import
66

77
"""
8-
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
8+
Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
99
1010
Licensed under the Apache License, Version 2.0 (the "License").
1111
You may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@
2525
https://webservices.amazon.com/paapi5/documentation/index.html # noqa: E501
2626
"""
2727

28-
2928
import copy
3029
import logging
3130
import multiprocessing
@@ -228,6 +227,6 @@ def to_debug_report(self):
228227
return "Python SDK Debug Report:\n"\
229228
"OS: {env}\n"\
230229
"Python Version: {pyversion}\n"\
231-
"Version of the API: 1.0.0\n"\
232-
"SDK Package Version: 1.0.0".\
230+
"Version of the API: 5.0.0\n"\
231+
"SDK Package Version: 1.2.4".\
233232
format(env=sys.platform, pyversion=sys.version)

0 commit comments

Comments
 (0)