python-amazon-sp-api 1.9.18__py3-none-any.whl → 2.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. {python_amazon_sp_api-1.9.18.data → python_amazon_sp_api-2.0.7.data}/scripts/make_endpoint +2 -2
  2. {python_amazon_sp_api-1.9.18.dist-info → python_amazon_sp_api-2.0.7.dist-info}/METADATA +46 -23
  3. python_amazon_sp_api-2.0.7.dist-info/RECORD +251 -0
  4. {python_amazon_sp_api-1.9.18.dist-info → python_amazon_sp_api-2.0.7.dist-info}/WHEEL +1 -1
  5. {python_amazon_sp_api-1.9.18.dist-info → python_amazon_sp_api-2.0.7.dist-info}/top_level.txt +0 -1
  6. sp_api/__version__.py +1 -1
  7. sp_api/api/__init__.py +18 -1
  8. sp_api/api/application_integrations/application_integrations.py +118 -0
  9. sp_api/api/application_management/application_management.py +2 -1
  10. sp_api/api/catalog/catalog.py +3 -4
  11. sp_api/api/catalog_items/catalog_items.py +3 -6
  12. sp_api/api/customer_feedback/customer_feedback.py +110 -0
  13. sp_api/api/data_kiosk/data_kiosk.py +5 -6
  14. sp_api/api/easy_ship/easy_ship.py +190 -0
  15. sp_api/api/external_fulfillment/external_fulfillment.py +706 -0
  16. sp_api/api/feeds/feeds.py +11 -8
  17. sp_api/api/finances/finances.py +30 -4
  18. sp_api/api/fulfillment_inbound/fulfillment_inbound.py +35 -2
  19. sp_api/api/inventories/inventories.py +2 -7
  20. sp_api/api/listings_items/listings_items.py +3 -24
  21. sp_api/api/messaging/messaging.py +42 -0
  22. sp_api/api/orders/orders.py +7 -0
  23. sp_api/api/product_fees/product_fees.py +31 -74
  24. sp_api/api/products/products.py +80 -2
  25. sp_api/api/products/products_definitions.py +11 -85
  26. sp_api/api/reports/reports.py +65 -97
  27. sp_api/api/sales/sales.py +2 -2
  28. sp_api/asyncio/api/__init__.py +164 -0
  29. sp_api/asyncio/api/amazon_warehousing_and_distribu/__init__.py +9 -0
  30. sp_api/asyncio/api/amazon_warehousing_and_distribu/amazon_warehousing_and_distribu.py +130 -0
  31. sp_api/asyncio/api/aplus_content/__init__.py +5 -0
  32. sp_api/asyncio/api/aplus_content/aplus_content.py +330 -0
  33. sp_api/asyncio/api/application_integrations/__init__.py +5 -0
  34. sp_api/asyncio/api/application_integrations/application_integrations.py +119 -0
  35. sp_api/asyncio/api/application_management/__init__.py +5 -0
  36. sp_api/asyncio/api/application_management/application_management.py +36 -0
  37. sp_api/asyncio/api/authorization/__init__.py +5 -0
  38. sp_api/asyncio/api/authorization/authorization.py +54 -0
  39. sp_api/asyncio/api/catalog/__init__.py +5 -0
  40. sp_api/asyncio/api/catalog/catalog.py +111 -0
  41. sp_api/asyncio/api/catalog_items/__init__.py +6 -0
  42. sp_api/asyncio/api/catalog_items/catalog_items.py +93 -0
  43. sp_api/asyncio/api/clients/__init__.py +1 -0
  44. sp_api/asyncio/api/customer_feedback/__init__.py +5 -0
  45. sp_api/asyncio/api/customer_feedback/customer_feedback.py +111 -0
  46. sp_api/asyncio/api/data_kiosk/__init__.py +5 -0
  47. sp_api/asyncio/api/data_kiosk/data_kiosk.py +236 -0
  48. sp_api/asyncio/api/easy_ship/__init__.py +5 -0
  49. sp_api/asyncio/api/easy_ship/easy_ship.py +191 -0
  50. sp_api/asyncio/api/external_fulfillment/__init__.py +5 -0
  51. sp_api/asyncio/api/external_fulfillment/external_fulfillment.py +706 -0
  52. sp_api/asyncio/api/fba_inbound_eligibility/__init__.py +5 -0
  53. sp_api/asyncio/api/fba_inbound_eligibility/fba_inbound_eligibility.py +96 -0
  54. sp_api/asyncio/api/fba_small_and_light/__init__.py +5 -0
  55. sp_api/asyncio/api/fba_small_and_light/fba_small_and_light.py +213 -0
  56. sp_api/asyncio/api/feeds/feeds.py +260 -0
  57. sp_api/asyncio/api/finances/finances.py +100 -0
  58. sp_api/asyncio/api/fulfillment_inbound/fulfillment_inbound.py +1798 -0
  59. sp_api/asyncio/api/fulfillment_outbound/fulfillment_outbound.py +736 -0
  60. sp_api/asyncio/api/inventories/inventories.py +74 -0
  61. sp_api/asyncio/api/listings_items/__init__.py +0 -0
  62. sp_api/asyncio/api/listings_items/listings_items.py +170 -0
  63. sp_api/asyncio/api/listings_restrictions/__init__.py +0 -0
  64. sp_api/asyncio/api/listings_restrictions/listings_restrictions.py +36 -0
  65. sp_api/asyncio/api/merchant_fulfillment/__init__.py +0 -0
  66. sp_api/asyncio/api/merchant_fulfillment/merchant_fulfillment.py +384 -0
  67. sp_api/asyncio/api/messaging/__init__.py +0 -0
  68. sp_api/asyncio/api/messaging/messaging.py +511 -0
  69. sp_api/asyncio/api/models/__init__.py +4 -0
  70. sp_api/asyncio/api/notifications/__init__.py +0 -0
  71. sp_api/asyncio/api/notifications/notifications.py +295 -0
  72. sp_api/asyncio/api/orders/__init__.py +0 -0
  73. sp_api/asyncio/api/orders/orders.py +362 -0
  74. sp_api/asyncio/api/overrides/__init__.py +1 -0
  75. sp_api/asyncio/api/product_fees/__init__.py +0 -0
  76. sp_api/asyncio/api/product_fees/product_fees.py +194 -0
  77. sp_api/asyncio/api/product_type_definitions/__init__.py +0 -0
  78. sp_api/asyncio/api/product_type_definitions/product_type_definitions.py +75 -0
  79. sp_api/asyncio/api/products/__init__.py +0 -0
  80. sp_api/asyncio/api/products/products.py +405 -0
  81. sp_api/asyncio/api/products/products_definitions.py +11 -0
  82. sp_api/asyncio/api/replenishment/__init__.py +0 -0
  83. sp_api/asyncio/api/replenishment/replenishment.py +121 -0
  84. sp_api/asyncio/api/reports/__init__.py +0 -0
  85. sp_api/asyncio/api/reports/reports.py +439 -0
  86. sp_api/asyncio/api/sales/__init__.py +0 -0
  87. sp_api/asyncio/api/sales/sales.py +93 -0
  88. sp_api/asyncio/api/sellers/__init__.py +0 -0
  89. sp_api/asyncio/api/sellers/sellers.py +70 -0
  90. sp_api/asyncio/api/services/__init__.py +0 -0
  91. sp_api/asyncio/api/services/services.py +218 -0
  92. sp_api/asyncio/api/shipping/__init__.py +0 -0
  93. sp_api/asyncio/api/shipping/shipping.py +459 -0
  94. sp_api/asyncio/api/shipping/shippingV2.py +651 -0
  95. sp_api/asyncio/api/solicitations/__init__.py +0 -0
  96. sp_api/asyncio/api/solicitations/solicitations.py +78 -0
  97. sp_api/asyncio/api/supply_sources/__init__.py +0 -0
  98. sp_api/asyncio/api/supply_sources/supply_sources.py +138 -0
  99. sp_api/asyncio/api/tokens/__init__.py +0 -0
  100. sp_api/asyncio/api/tokens/tokens.py +65 -0
  101. sp_api/asyncio/api/upload/__init__.py +0 -0
  102. sp_api/asyncio/api/upload/upload.py +18 -0
  103. sp_api/asyncio/api/vendor_direct_fulfillment_inventory/__init__.py +0 -0
  104. sp_api/asyncio/api/vendor_direct_fulfillment_inventory/vendor_direct_fulfillment_inventory.py +64 -0
  105. sp_api/asyncio/api/vendor_direct_fulfillment_orders/__init__.py +0 -0
  106. sp_api/asyncio/api/vendor_direct_fulfillment_orders/vendor_direct_fulfillment_orders.py +196 -0
  107. sp_api/asyncio/api/vendor_direct_fulfillment_payments/__init__.py +0 -0
  108. sp_api/asyncio/api/vendor_direct_fulfillment_payments/vendor_direct_fulfillment_payments.py +254 -0
  109. sp_api/asyncio/api/vendor_direct_fulfillment_shipping/__init__.py +0 -0
  110. sp_api/asyncio/api/vendor_direct_fulfillment_shipping/vendor_direct_fulfillment_shipping.py +627 -0
  111. sp_api/asyncio/api/vendor_direct_fulfillment_transactions/__init__.py +0 -0
  112. sp_api/asyncio/api/vendor_direct_fulfillment_transactions/vendor_direct_fulfillment_transactions.py +43 -0
  113. sp_api/asyncio/api/vendor_invoices/__init__.py +0 -0
  114. sp_api/asyncio/api/vendor_invoices/vendor_invoices.py +295 -0
  115. sp_api/asyncio/api/vendor_orders/__init__.py +0 -0
  116. sp_api/asyncio/api/vendor_orders/vendor_orders.py +210 -0
  117. sp_api/asyncio/api/vendor_shipments/__init__.py +0 -0
  118. sp_api/asyncio/api/vendor_shipments/vendor_shipments.py +118 -0
  119. sp_api/asyncio/api/vendor_transaction_status/__init__.py +0 -0
  120. sp_api/asyncio/api/vendor_transaction_status/vendor_transaction_status.py +41 -0
  121. sp_api/asyncio/auth/__init__.py +12 -0
  122. sp_api/asyncio/auth/access_token_client.py +145 -0
  123. sp_api/asyncio/auth/exceptions.py +5 -0
  124. sp_api/asyncio/base/__init__.py +53 -0
  125. sp_api/asyncio/base/_transport_httpx.py +50 -0
  126. sp_api/asyncio/base/base_client.py +8 -0
  127. sp_api/asyncio/base/client.py +169 -0
  128. sp_api/asyncio/util/__init__.py +29 -0
  129. sp_api/asyncio/util/key_maker.py +5 -0
  130. sp_api/asyncio/util/load_all_pages.py +55 -0
  131. sp_api/asyncio/util/load_date_bound.py +53 -0
  132. sp_api/asyncio/util/retry.py +88 -0
  133. sp_api/auth/_core.py +39 -0
  134. sp_api/auth/access_token_client.py +18 -29
  135. sp_api/base/ApiResponse.py +3 -2
  136. sp_api/base/_core.py +110 -0
  137. sp_api/base/_transport_httpx.py +39 -0
  138. sp_api/base/client.py +40 -63
  139. sp_api/base/helpers.py +1 -1
  140. sp_api/base/reportTypes.py +3 -2
  141. sp_api/util/__init__.py +36 -0
  142. sp_api/util/load_all_pages.py +2 -1
  143. sp_api/util/params.py +57 -0
  144. sp_api/util/product_fees.py +40 -0
  145. sp_api/util/products_definitions.py +169 -0
  146. sp_api/util/report_document.py +154 -0
  147. python_amazon_sp_api-1.9.18.dist-info/RECORD +0 -144
  148. tests/api/finances/test_finances.py +0 -19
  149. tests/api/notifications/test_notifications.py +0 -26
  150. tests/api/orders/test_orders.py +0 -122
  151. tests/api/product_fees/product_fees.py +0 -49
  152. tests/api/reports/test_reports.py +0 -127
  153. tests/client/test_auth.py +0 -59
  154. tests/client/test_base.py +0 -163
  155. tests/client/test_credential_provider.py +0 -45
  156. tests/client/test_helpers.py +0 -142
  157. {python_amazon_sp_api-1.9.18.dist-info → python_amazon_sp_api-2.0.7.dist-info/licenses}/LICENSE +0 -0
  158. {tests → sp_api/api/application_integrations}/__init__.py +0 -0
  159. {tests/api → sp_api/api/customer_feedback}/__init__.py +0 -0
  160. {tests/api/finances → sp_api/api/easy_ship}/__init__.py +0 -0
  161. {tests/api/notifications → sp_api/api/external_fulfillment}/__init__.py +0 -0
  162. {tests/api/orders → sp_api/asyncio}/__init__.py +0 -0
  163. {tests/api/product_fees → sp_api/asyncio/api/feeds}/__init__.py +0 -0
  164. {tests/api/reports → sp_api/asyncio/api/finances}/__init__.py +0 -0
  165. {tests/api/sellers → sp_api/asyncio/api/fulfillment_inbound}/__init__.py +0 -0
  166. {tests/client → sp_api/asyncio/api/fulfillment_outbound}/__init__.py +0 -0
  167. /tests/api/sellers/test_sellers.py → /sp_api/asyncio/api/inventories/__init__.py +0 -0
@@ -0,0 +1,11 @@
1
+ from sp_api.util.products_definitions import (
2
+ CompetitiveSummaryIncludedData,
3
+ ItemOffersRequest,
4
+ GetItemOffersBatchRequest,
5
+ ListingOffersRequest,
6
+ GetListingOffersBatchRequest,
7
+ FeaturedOfferExpectedPriceRequest,
8
+ GetFeaturedOfferExpectedPriceBatch,
9
+ CompetitiveSummaryRequest,
10
+ GetCompetitiveSummaryBatch,
11
+ )
File without changes
@@ -0,0 +1,121 @@
1
+ import urllib.parse
2
+
3
+ from sp_api.base import Client, sp_endpoint, fill_query_params, ApiResponse
4
+ from sp_api.asyncio.base import AsyncBaseClient
5
+
6
+
7
+ class Replenishment(AsyncBaseClient):
8
+ """
9
+ Replenishment SP-API Client
10
+ :link:
11
+
12
+ The Selling Partner API for Replenishment (Replenishment API) provides programmatic access to replenishment program metrics and offers. These programs provide recurring delivery of any replenishable item at a frequency chosen by the customer.
13
+
14
+ The Replenishment API is available worldwide wherever Amazon Subscribe & Save is available or is supported. The API is available to vendors and FBA selling partners.
15
+ """
16
+
17
+ @sp_endpoint(
18
+ "/replenishment/2022-11-07/sellingPartners/metrics/search", method="POST"
19
+ )
20
+ async def get_selling_partner_metrics(self, **kwargs) -> ApiResponse:
21
+ """
22
+ get_selling_partner_metrics(self, **kwargs) -> ApiResponse
23
+
24
+ Returns aggregated replenishment program metrics for a selling partner.
25
+
26
+ **Usage Plan:**
27
+
28
+ | Rate (requests per second) | Burst |
29
+ | ---- | ---- |
30
+ | 1 | 1 |
31
+
32
+ The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
33
+
34
+ Args:
35
+
36
+ body: | {'description': 'The request body for the `getSellingPartnerMetrics` operation.',
37
+ 'properties': {'aggregationFrequency': {'$ref': '#/definitions/AggregationFrequency'},
38
+ 'marketplaceId': {'$ref': '#/definitions/MarketplaceId',
39
+ 'description': 'The marketplace identifier. The supported marketplaces for both sellers and vendors are US, CA, ES, UK, FR, IT, IN, DE and JP. The supported marketplaces for vendors only are BR, AU, MX, AE and NL. '
40
+ 'Refer to [Marketplace IDs](https://developer-docs.amazon.com/sp-api/docs/marketplace-ids) to find the identifier for the marketplace.'},
41
+ 'metrics': {'description': 'The list of metrics requested. If no metric value is provided, data for all of the metrics will be returned.',
42
+ 'items': {'$ref': '#/definitions/Metric'},
43
+ 'minItems': 1,
44
+ 'type': 'array',
45
+ 'uniqueItems': True},
46
+ 'programTypes': {'$ref': '#/definitions/ProgramTypes', 'description': 'The list of replenishment program types for which to return metrics.'},
47
+ 'timeInterval': {'$ref': '#/definitions/TimeInterval', 'description': 'A time interval used to compute metrics.'},
48
+ 'timePeriodType': {'$ref': '#/definitions/TimePeriodType'}},
49
+ 'required': ['timeInterval', 'timePeriodType', 'programTypes', 'marketplaceId'],
50
+ 'type': 'object'}
51
+
52
+
53
+ Returns:
54
+ ApiResponse:
55
+ """
56
+
57
+ return await self._request(kwargs.pop("path"), data=kwargs)
58
+
59
+ @sp_endpoint("/replenishment/2022-11-07/offers/metrics/search", method="POST")
60
+ async def list_offer_metrics(self, **kwargs) -> ApiResponse:
61
+ """
62
+ list_offer_metrics(self, **kwargs) -> ApiResponse
63
+
64
+ Returns aggregated replenishment program metrics for a selling partner's offers.
65
+
66
+ **Usage Plan:**
67
+
68
+ | Rate (requests per second) | Burst |
69
+ | ---- | ---- |
70
+ | 1 | 1 |
71
+
72
+ The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
73
+
74
+ Args:
75
+
76
+ body: | {'description': 'The request body for the `listOfferMetrics` operation.',
77
+ 'properties': {'filters': {'$ref': '#/definitions/ListOfferMetricsRequestFilters',
78
+ 'description': 'Use these parameters to filter results. Any result must match all provided parameters. For any parameter that is an array, the result must match at least one element in the provided array.'},
79
+ 'pagination': {'$ref': '#/definitions/ListOfferMetricsRequestPagination', 'description': 'Use these parameters to paginate through the response.'},
80
+ 'sort': {'$ref': '#/definitions/ListOfferMetricsRequestSort', 'description': 'Use these parameters to sort the response.'}},
81
+ 'required': ['pagination', 'filters'],
82
+ 'type': 'object'}
83
+
84
+
85
+ Returns:
86
+ ApiResponse:
87
+ """
88
+
89
+ return await self._request(kwargs.pop("path"), data=kwargs)
90
+
91
+ @sp_endpoint("/replenishment/2022-11-07/offers/search", method="POST")
92
+ async def list_offers(self, **kwargs) -> ApiResponse:
93
+ """
94
+ list_offers(self, **kwargs) -> ApiResponse
95
+
96
+ Returns the details of a selling partner's replenishment program offers. Note that this operation only supports sellers at this time.
97
+
98
+ **Usage Plan:**
99
+
100
+ | Rate (requests per second) | Burst |
101
+ | ---- | ---- |
102
+ | 1 | 1 |
103
+
104
+ The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
105
+
106
+ Args:
107
+
108
+ body: | {'description': 'The request body for the `listOffers` operation.',
109
+ 'properties': {'filters': {'$ref': '#/definitions/ListOffersRequestFilters',
110
+ 'description': 'Use these parameters to filter results. Any result must match all provided parameters. For any parameter that is an array, the result must match at least one element in the provided array.'},
111
+ 'pagination': {'$ref': '#/definitions/ListOffersRequestPagination', 'description': 'Use these parameters to paginate through the response.'},
112
+ 'sort': {'$ref': '#/definitions/ListOffersRequestSort', 'description': 'Use these parameters to sort the response.'}},
113
+ 'required': ['pagination', 'filters'],
114
+ 'type': 'object'}
115
+
116
+
117
+ Returns:
118
+ ApiResponse:
119
+ """
120
+
121
+ return await self._request(kwargs.pop("path"), data=kwargs)
File without changes
@@ -0,0 +1,439 @@
1
+ from datetime import datetime
2
+ from typing import Optional, Union
3
+
4
+ from sp_api.base import (
5
+ Client,
6
+ sp_endpoint,
7
+ fill_query_params,
8
+ ApiResponse,
9
+ Marketplaces,
10
+ )
11
+ from sp_api.asyncio.base import AsyncBaseClient
12
+ from sp_api.util import (
13
+ normalize_csv_param,
14
+ normalize_datetime_kwargs,
15
+ normalize_marketplace_ids,
16
+ should_add_marketplace,
17
+ )
18
+ from sp_api.util.report_document import (
19
+ decode_document,
20
+ decompress_bytes,
21
+ handle_file,
22
+ resolve_character_code,
23
+ stream_to_file_async,
24
+ )
25
+
26
+
27
+ class Reports(AsyncBaseClient):
28
+ """
29
+ Reports SP-API Client
30
+ :link:
31
+
32
+ The Selling Partner API for Reports lets you retrieve and manage a variety of reports that can help selling partners manage their businesses.
33
+ """
34
+
35
+ @sp_endpoint("/reports/2021-06-30/reports", method="GET")
36
+ async def get_reports(self, **kwargs) -> ApiResponse:
37
+ """
38
+ get_reports(self, **kwargs) -> ApiResponse
39
+
40
+ Returns report details for the reports that match the filters that you specify.
41
+
42
+ **Usage Plan:**
43
+
44
+ ====================================== ==============
45
+ Rate (requests per second) Burst
46
+ ====================================== ==============
47
+ 0.0222 10
48
+ ====================================== ==============
49
+
50
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
51
+
52
+ Examples:
53
+ literal blocks::
54
+
55
+ report_types = ["FEE_DISCOUNTS_REPORT", "GET_AFN_INVENTORY_DATA"]
56
+ processing_status = ["IN_QUEUE", "IN_PROGRESS"]
57
+ res = Reports().get_reports(reportTypes=report_types, processingStatuses=processing_status)
58
+
59
+ Args:
60
+ key reportTypes: str[] or ReportType[] | optional A list of report types used to filter reports. When reportTypes is provided, the other filter parameters (processingStatuses, marketplaceIds, createdSince, createdUntil) and pageSize may also be provided. Either reportTypes or nextToken is required.
61
+ key processingStatuses: str[] or ProcessingStatus[] optional A list of processing statuses used to filter reports.
62
+ key marketplaceIds: str[] or Marketplaces[] optional A list of marketplace identifiers used to filter reports. The reports returned will match at least one of the marketplaces that you specify.
63
+ key pageSize: int optional The maximum number of reports to return in a single call.
64
+ key createdSince: str or datetime optional The earliest report creation date and time for reports to include in the response, in ISO 8601 date time format. The default is 90 days ago. Reports are retained for a maximum of 90 days. string (date-time) -
65
+ key createdUntil: str or datetime optional The latest report creation date and time for reports to include in the response, in ISO 8601 date time format. The default is now. string (date-time) -
66
+ key nextToken: str optional A stringget_report_document token returned in the response to your previous request. nextToken is returned when the number of results exceeds the specified pageSize value. To get the next page of results, call the getReports operation and include this token as the only parameter. Specifying nextToken with any other parameters will cause the request to fail. string -
67
+
68
+
69
+ Returns:
70
+ ApiResponse
71
+ """
72
+ normalize_csv_param(kwargs, "reportTypes")
73
+ normalize_csv_param(kwargs, "processingStatuses")
74
+ normalize_marketplace_ids(kwargs, marketplace_cls=Marketplaces)
75
+ normalize_datetime_kwargs(kwargs, ["createdSince", "createdUntil"])
76
+ add_marketplace = should_add_marketplace(kwargs, "nextToken")
77
+ return await self._request(
78
+ kwargs.pop("path"),
79
+ params=kwargs,
80
+ add_marketplace=add_marketplace,
81
+ )
82
+
83
+ @sp_endpoint("/reports/2021-06-30/reports", method="POST")
84
+ async def create_report(self, **kwargs) -> ApiResponse:
85
+ """
86
+ create_report(self, **kwargs) -> ApiResponse
87
+
88
+ See report types at
89
+ :link: https://github.com/amzn/selling-partner-api-docs/blob/main/references/reports-api/reporttype-values.md
90
+
91
+ **Usage Plan:**
92
+
93
+ ====================================== ==============
94
+ Rate (requests per second) Burst
95
+ ====================================== ==============
96
+ 0.0167 15
97
+ ====================================== ==============
98
+
99
+ Examples:
100
+ literal blocks::
101
+
102
+ res = Reports().create_report(
103
+ reportType=ReportType.GET_MERCHANT_LISTINGS_ALL_DATA,
104
+ dataStartTime='2019-12-10T20:11:24.000Z',
105
+ marketplaceIds=[
106
+ "A1PA6795UKMFR9",
107
+ "ATVPDKIKX0DER"
108
+ ])
109
+
110
+ Args:
111
+ key reportOptions: optional Additional information passed to reports. This varies by report type. ReportOptions
112
+ key reportType: required The report type. :link: https://github.com/amzn/selling-partner-api-docs/blob/main/references/reports-api/reporttype-values.md
113
+ key dataStartTime: optional The start of a date and time range, in ISO 8601 date time format, used for selecting the data to report. The default is now. The value must be prior to or equal to the current date and time. Not all report types make use of this. string (date-time)
114
+ key dataEndTime: optional The end of a date and time range, in ISO 8601 date time format, used for selecting the data to report. The default is now. The value must be prior to or equal to the current date and time. Not all report types make use of this. string (date-time)
115
+ key marketplaceIds: optional, defaults to the client's marketplace A list of marketplace identifiers. The report document's contents will contain data for all of the specified marketplaces, unless the report type indicates otherwise. < string > array
116
+
117
+ Returns:
118
+ ApiResponse
119
+ """
120
+ normalize_datetime_kwargs(kwargs, ["dataStartTime", "dataEndTime"])
121
+ return await self._request(kwargs.pop("path"), data=kwargs)
122
+
123
+ @sp_endpoint("/reports/2021-06-30/reports/{}", method="DELETE")
124
+ async def cancel_report(self, reportId, **kwargs) -> ApiResponse:
125
+ """
126
+ cancel_report(self, reportId, **kwargs) -> ApiResponse
127
+
128
+ Cancels the report that you specify. Only reports with processingStatus=IN_QUEUE can be cancelled. Cancelled reports are returned in subsequent calls to the getReport and getReports operations.
129
+
130
+ **Usage Plan:**
131
+
132
+ ====================================== ==============
133
+ Rate (requests per second) Burst
134
+ ====================================== ==============
135
+ 0.0022 10
136
+ ====================================== ==============
137
+
138
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
139
+
140
+ Args:
141
+ reportId:string | * REQUIRED The identifier for the report. This identifier is unique only in combination with a seller ID.
142
+
143
+ Returns:
144
+ ApiResponse:
145
+ """
146
+
147
+ return await self._request(
148
+ fill_query_params(kwargs.pop("path"), reportId), data=kwargs
149
+ )
150
+
151
+ @sp_endpoint("/reports/2021-06-30/reports/{}", method="GET")
152
+ async def get_report(self, reportId, **kwargs) -> ApiResponse:
153
+ """
154
+ get_report(self, report_id, **kwargs)
155
+ Returns report details (including the reportDocumentId, if available) for the report that you specify.
156
+
157
+ **Usage Plan:**
158
+
159
+ ====================================== ==============
160
+ Rate (requests per second) Burst
161
+ ====================================== ==============
162
+ 2 15
163
+ ====================================== ==============
164
+
165
+
166
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
167
+
168
+ Examples:
169
+ literal blocks::
170
+
171
+ Reports().get_report('ID323')
172
+
173
+ Args:
174
+ reportId: str
175
+
176
+ Returns:
177
+ ApiResponse
178
+
179
+ """
180
+
181
+ return await self._request(
182
+ fill_query_params(kwargs.pop("path"), reportId), params=kwargs
183
+ )
184
+
185
+ @sp_endpoint("/reports/2021-06-30/schedules", method="GET")
186
+ async def get_report_schedules(self, **kwargs) -> ApiResponse:
187
+ """
188
+ Returns report schedule details that match the filters that you specify.
189
+
190
+ **Usage Plan:**
191
+
192
+ ====================================== ==============
193
+ Rate (requests per second) Burst
194
+ ====================================== ==============
195
+ 0.0222 10
196
+ ====================================== ==============
197
+
198
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
199
+
200
+ Args:
201
+ key reportTypes: str[] or ReportType[] | required A list of report types used to filter report schedules. Min count : 1. Max count : 10.
202
+
203
+ Returns:
204
+ ApiResponse
205
+ """
206
+ normalize_csv_param(kwargs, "reportTypes")
207
+
208
+ return await self._request(kwargs.pop("path"), params=kwargs)
209
+
210
+ @sp_endpoint("/reports/2021-06-30/schedules", method="POST")
211
+ async def create_report_schedule(self, **kwargs) -> ApiResponse:
212
+ """
213
+ create_report_schedule(self, **kwargs) -> ApiResponse
214
+
215
+ Creates a report schedule. If a report schedule with the same report type and marketplace IDs already exists, it will be cancelled and replaced with this one.
216
+
217
+ **Usage Plan:**
218
+
219
+ ====================================== ==============
220
+ Rate (requests per second) Burst
221
+ ====================================== ==============
222
+ 0.0222 10
223
+ ====================================== ==============
224
+
225
+ Examples:
226
+ literal blocks::
227
+
228
+ Reports().create_report_schedule(reportType='FEE_DISCOUNTS_REPORT',
229
+ period=Schedules.MINUTES_5.value,
230
+ nextReportCreationTime="2019-12-10T20:11:24.000Z",
231
+ marketplaceIds=["A1PA6795UKMFR9", "ATVPDKIKX0DER"])
232
+
233
+ Args:
234
+ key reportType: str
235
+ key marketplaceIds: str
236
+ key reportOptions: dict
237
+ key period: Schedules
238
+ key nextReportCreationTime: str datetime isoformat
239
+
240
+ Returns:
241
+ ApiResponse:
242
+ """
243
+
244
+ return await self._request(kwargs.pop("path"), data=kwargs)
245
+
246
+ @sp_endpoint("/reports/2021-06-30/schedules/{}", method="DELETE")
247
+ async def cancel_report_schedule(self, reportScheduleId, **kwargs) -> ApiResponse:
248
+ """
249
+ cancel_report_schedule(self, reportScheduleId, **kwargs) -> ApiResponse
250
+
251
+ Cancels the report schedule that you specify.
252
+
253
+ **Usage Plan:**
254
+
255
+ ====================================== ==============
256
+ Rate (requests per second) Burst
257
+ ====================================== ==============
258
+ 0.0222 10
259
+ ====================================== ==============
260
+
261
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
262
+
263
+ Examples:
264
+ literal blocks::
265
+
266
+ Reports().cancel_report_schedule('ID')
267
+
268
+ Args:
269
+ reportScheduleId: str
270
+ kwargs:
271
+
272
+ Returns:
273
+ ApiResponse
274
+ """
275
+ return await self._request(
276
+ fill_query_params(kwargs.pop("path"), reportScheduleId), data=kwargs
277
+ )
278
+
279
+ def delete_report_schedule(self, reportScheduleId, **kwargs) -> ApiResponse:
280
+ """
281
+ cancel_report_schedule(self, reportScheduleId, **kwargs) -> ApiResponse
282
+
283
+ Cancels the report schedule that you specify.
284
+
285
+ **Usage Plan:**
286
+
287
+ ====================================== ==============
288
+ Rate (requests per second) Burst
289
+ ====================================== ==============
290
+ 0.0222 10
291
+ ====================================== ==============
292
+
293
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
294
+
295
+ Examples:
296
+ literal blocks::
297
+
298
+ Reports().cancel_report_schedule('ID')
299
+
300
+ Args:
301
+ reportScheduleId: str
302
+ kwargs:
303
+
304
+ Returns:
305
+ ApiResponse
306
+ """
307
+ return self.cancel_report_schedule(reportScheduleId)
308
+
309
+ @sp_endpoint("/reports/2021-06-30/schedules/{}", method="GET")
310
+ async def get_report_schedule(self, reportScheduleId, **kwargs) -> ApiResponse:
311
+ """
312
+ get_report_schedule(self, reportScheduleId, **kwargs) -> ApiResponse
313
+
314
+ Returns report schedule details for the report schedule that you specify.
315
+
316
+ **Usage Plan:**
317
+
318
+ ====================================== ==============
319
+ Rate (requests per second) Burst
320
+ ====================================== ==============
321
+ 0.0222 10
322
+ ====================================== ==============
323
+
324
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
325
+
326
+ Examples:
327
+ literal blocks::
328
+
329
+ Reports().get_report_schedule('ID323')
330
+
331
+ Args:
332
+ reportScheduleId: str | required The identifier for the report schedule. This identifier is unique only in combination with a seller ID.
333
+ kwargs:
334
+
335
+ Returns:
336
+ ApiResponse
337
+ """
338
+ return await self._request(
339
+ fill_query_params(kwargs.pop("path"), reportScheduleId), params=kwargs
340
+ )
341
+
342
+ @sp_endpoint("/reports/2021-06-30/documents/{}", method="GET")
343
+ async def get_report_document(
344
+ self,
345
+ reportDocumentId,
346
+ download: bool = False,
347
+ file=None,
348
+ character_code: Optional[str] = None,
349
+ stream: bool = False,
350
+ timeout: Optional[Union[float,int]] = None,
351
+ **kwargs
352
+ ) -> ApiResponse:
353
+ """
354
+ get_report_document(self, document_id, decrypt: bool = False, file=None, character_code: Optional[str] = None, **kwargs) -> ApiResponse
355
+ Returns the information required for retrieving a report document's contents. This includes a presigned URL for the report document as well as the information required to decrypt the document's contents.
356
+
357
+ If decrypt = True the report will automatically be loaded and decrypted/unpacked
358
+ If file is set to a file (or file like object), the report's contents are written to the file
359
+
360
+
361
+ **Usage Plan:**
362
+
363
+
364
+ ====================================== ==============
365
+ Rate (requests per second) Burst
366
+ ====================================== ==============
367
+ 0.0167 15
368
+ ====================================== ==============
369
+
370
+
371
+
372
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
373
+
374
+ Examples:
375
+ literal blocks::
376
+
377
+ Reports().get_report_document('0356cf79-b8b0-4226-b4b9-0ee058ea5760', download=True, file=file)
378
+
379
+ Args:
380
+ reportDocumentId: str | the document to load
381
+ download: bool | flag to automatically download a report
382
+ file: If passed, will save the document to the file specified.
383
+ Only valid if decrypt=True
384
+ character_code: If passed, will be a file with the specified character code.
385
+ The default is the Content-Encoding in the response while
386
+ obtaining the document from the document URL.
387
+ It fallbacks to 'iso-8859-1' if no encoding was found.
388
+ Only valid if decrypt=True.
389
+ stream: bool | if True and file is provided, stream the document to disk
390
+ timeout: int | optional, the timeout for the request to download the document
391
+
392
+ Returns:
393
+ ApiResponse
394
+ """ # noqa: E501
395
+ res = await self._request(
396
+ fill_query_params(kwargs.pop("path"), reportDocumentId),
397
+ add_marketplace=False,
398
+ )
399
+ if download or file or ("decrypt" in kwargs and kwargs["decrypt"]):
400
+ compression_algorithm = res.payload.get("compressionAlgorithm")
401
+ if stream and file:
402
+ async with self._transport.stream(
403
+ "GET",
404
+ res.payload.get("url"),
405
+ timeout=timeout,
406
+ ) as document_response:
407
+ if not character_code:
408
+ character_code = resolve_character_code(
409
+ document_response.encoding, fallback="iso-8859-1"
410
+ )
411
+ await stream_to_file_async(
412
+ document_response,
413
+ file,
414
+ character_code,
415
+ compression_algorithm,
416
+ )
417
+ else:
418
+ document_response = await self._transport.request(
419
+ "GET",
420
+ res.payload.get("url"),
421
+ timeout=timeout,
422
+ )
423
+ if not character_code:
424
+ character_code = resolve_character_code(
425
+ document_response.encoding, fallback="iso-8859-1"
426
+ )
427
+ document = decompress_bytes(
428
+ document_response.content, compression_algorithm
429
+ )
430
+ decoded_document = decode_document(document, character_code)
431
+ if download:
432
+ res.payload.update(
433
+ {
434
+ "document": decoded_document,
435
+ }
436
+ )
437
+ if file:
438
+ handle_file(file, decoded_document, character_code)
439
+ return res
File without changes
@@ -0,0 +1,93 @@
1
+ import urllib
2
+ from datetime import datetime
3
+
4
+ from sp_api.base import Client, Marketplaces, sp_endpoint, Granularity, ApiResponse
5
+ from sp_api.asyncio.base import AsyncBaseClient
6
+ import logging
7
+ from sp_api.util import encode_kwarg
8
+
9
+
10
+ class Sales(AsyncBaseClient):
11
+ """
12
+ :link: https://github.com/amzn/selling-partner-api-docs/blob/main/references/sales-api/sales.md#parameters
13
+ """
14
+
15
+ @sp_endpoint("/sales/v1/orderMetrics")
16
+ async def get_order_metrics(
17
+ self,
18
+ interval: tuple,
19
+ granularity: Granularity,
20
+ granularityTimeZone: str = None,
21
+ **kwargs
22
+ ) -> ApiResponse:
23
+ """
24
+ get_order_metrics(self, interval: tuple, granularity: Granularity, granularityTimeZone: str = None, **kwargs) -> ApiResponse
25
+
26
+ Returns aggregated order metrics for given interval, broken down by granularity, for given buyer type.
27
+
28
+ **Usage Plan:**
29
+
30
+
31
+ ====================================== ==============
32
+ Rate (requests per second) Burst
33
+ ====================================== ==============
34
+ 0.5 15
35
+ ====================================== ==============
36
+
37
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
38
+
39
+ Examples:
40
+ literal blocks::
41
+
42
+ from sp_api.api import Sales
43
+ from sp_api.base import Granularity
44
+
45
+ Sales().get_order_metrics(interval, Granularity.TOTAL, granularityTimeZone='US/Central')
46
+ Sales().get_order_metrics(interval, Granularity.DAY, granularityTimeZone='US/Central')
47
+ Sales().get_order_metrics(interval, Granularity.TOTAL, granularityTimeZone='US/Central', asin='B008OLKVEW')
48
+ Sales().get_order_metrics(interval, Granularity.DAY, granularityTimeZone='US/Central', asin='B008OLKVEW')
49
+
50
+
51
+ Args:
52
+ key marketplaceIds: [str]
53
+ interval: tuple | A time interval used for selecting order metrics. This takes the form of two dates separated by two hyphens (first date is inclusive; second date is exclusive). Dates are in ISO8601 format and must represent absolute time (either Z notation or offset notation). Example: 2018-09-01T00:00:00-07:00--2018-09-04T00:00:00-07:00 requests order metrics for Sept 1st, 2nd and 3rd in the -07:00 zone. string - Query granularityTimeZone
54
+ granularity: Granularity | The granularity of the grouping of order metrics, based on a unit of time. Specifying granularity=Hour results in a successful request only if the interval specified is less than or equal to 30 days from now. For all other granularities, the interval specified must be less or equal to 2 years from now. Specifying granularity=Total results in order metrics that are aggregated over the entire interval that you specify. If the interval start and end date don’t align with the specified granularity, the head and tail end of the response interval will contain partial data. Example: Day to get a daily breakdown of the request interval, where the day boundary is defined by the granularityTimeZone. enum (Granularity) -
55
+ key buyerType: BuyerType | Filters the results by the buyer type that you specify, B2B (business to business) or B2C (business to customer). Example: B2B, if you want the response to include order metrics for only B2B buyers. Default: enum (BuyerType) "All"
56
+ key fulfillmentNetwork: str | Filters the results by the fulfillment network that you specify, MFN (merchant fulfillment network) or AFN (Amazon fulfillment network). Do not include this filter if you want the response to include order metrics for all fulfillment networks. Example: AFN, if you want the response to include order metrics for only Amazon fulfillment network. string -
57
+ key firstDayOfWeek: str | Specifies the day that the week starts on when granularity=Week, either Monday or Sunday. Default: Monday. Example: Sunday, if you want the week to start on a Sunday. enum (FirstDayOfWeek) "Monday"
58
+ key asin: str | Filters the results by the ASIN that you specify. Specifying both ASIN and SKU returns an error. Do not include this filter if you want the response to include order metrics for all ASINs. Example: B0792R1RSN, if you want the response to include order metrics for only ASIN B0792R1RSN. string -
59
+ key sku: str | Filters the results by the SKU that you specify. Specifying both ASIN and SKU returns an error. Do not include this filter if you want the response to include order metrics for all SKUs. Example: TestSKU, if you want the response to include order metrics for only SKU TestSKU.
60
+ granularityTimeZone: str
61
+
62
+
63
+ Returns:
64
+ ApiResponse
65
+ """
66
+ kwargs.update(
67
+ {
68
+ "interval": "--".join(
69
+ [self._create_datetime_stamp(_interval) for _interval in interval]
70
+ ),
71
+ "granularity": granularity.value,
72
+ }
73
+ )
74
+ if granularityTimeZone:
75
+ kwargs.update({"granularityTimeZone": granularityTimeZone})
76
+ encode_kwarg(kwargs, "sku", lambda value: urllib.parse.quote(value, safe=""))
77
+ return await self._request(kwargs.pop("path"), params=kwargs)
78
+
79
+ @staticmethod
80
+ def _create_datetime_stamp(datetime_obj: datetime or str):
81
+ """
82
+ Create datetimestring
83
+
84
+ Args:
85
+ datetime_obj:
86
+
87
+ Returns:
88
+
89
+ """
90
+ if isinstance(datetime_obj, str):
91
+ return datetime_obj
92
+ fmt = "%Y-%m-%dT%H:%M:%S%z"
93
+ return datetime_obj.astimezone().isoformat(timespec="seconds")
File without changes