amazon-creatorsapi-python-sdk 1.0.0__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 (108) hide show
  1. amazon_creatorsapi_python_sdk-1.0.0.dist-info/METADATA +99 -0
  2. amazon_creatorsapi_python_sdk-1.0.0.dist-info/RECORD +108 -0
  3. amazon_creatorsapi_python_sdk-1.0.0.dist-info/WHEEL +5 -0
  4. amazon_creatorsapi_python_sdk-1.0.0.dist-info/licenses/LICENSE.txt +202 -0
  5. amazon_creatorsapi_python_sdk-1.0.0.dist-info/licenses/NOTICE.txt +2 -0
  6. amazon_creatorsapi_python_sdk-1.0.0.dist-info/top_level.txt +1 -0
  7. creatorsapi_python_sdk/__init__.py +127 -0
  8. creatorsapi_python_sdk/api/__init__.py +5 -0
  9. creatorsapi_python_sdk/api/default_api.py +2412 -0
  10. creatorsapi_python_sdk/api_client.py +912 -0
  11. creatorsapi_python_sdk/api_response.py +21 -0
  12. creatorsapi_python_sdk/auth/__init__.py +21 -0
  13. creatorsapi_python_sdk/auth/oauth2_config.py +123 -0
  14. creatorsapi_python_sdk/auth/oauth2_token_manager.py +120 -0
  15. creatorsapi_python_sdk/configuration.py +455 -0
  16. creatorsapi_python_sdk/exceptions.py +204 -0
  17. creatorsapi_python_sdk/models/__init__.py +110 -0
  18. creatorsapi_python_sdk/models/access_denied_exception_response_content.py +97 -0
  19. creatorsapi_python_sdk/models/access_denied_reason.py +45 -0
  20. creatorsapi_python_sdk/models/availability.py +44 -0
  21. creatorsapi_python_sdk/models/browse_node.py +116 -0
  22. creatorsapi_python_sdk/models/browse_node_ancestor.py +103 -0
  23. creatorsapi_python_sdk/models/browse_node_child.py +96 -0
  24. creatorsapi_python_sdk/models/browse_node_info.py +106 -0
  25. creatorsapi_python_sdk/models/browse_nodes_result.py +100 -0
  26. creatorsapi_python_sdk/models/by_line_info.py +111 -0
  27. creatorsapi_python_sdk/models/classifications.py +101 -0
  28. creatorsapi_python_sdk/models/condition.py +44 -0
  29. creatorsapi_python_sdk/models/content_info.py +113 -0
  30. creatorsapi_python_sdk/models/content_rating.py +96 -0
  31. creatorsapi_python_sdk/models/contributor.py +98 -0
  32. creatorsapi_python_sdk/models/customer_reviews.py +98 -0
  33. creatorsapi_python_sdk/models/deal_details.py +102 -0
  34. creatorsapi_python_sdk/models/delivery_flag.py +46 -0
  35. creatorsapi_python_sdk/models/dimension_based_attribute.py +111 -0
  36. creatorsapi_python_sdk/models/error_data.py +94 -0
  37. creatorsapi_python_sdk/models/external_ids.py +106 -0
  38. creatorsapi_python_sdk/models/feed.py +98 -0
  39. creatorsapi_python_sdk/models/get_browse_nodes_request_content.py +107 -0
  40. creatorsapi_python_sdk/models/get_browse_nodes_resource.py +44 -0
  41. creatorsapi_python_sdk/models/get_browse_nodes_response_content.py +106 -0
  42. creatorsapi_python_sdk/models/get_feed_request_content.py +93 -0
  43. creatorsapi_python_sdk/models/get_feed_response_content.py +92 -0
  44. creatorsapi_python_sdk/models/get_items_request_content.py +124 -0
  45. creatorsapi_python_sdk/models/get_items_resource.py +76 -0
  46. creatorsapi_python_sdk/models/get_items_response_content.py +106 -0
  47. creatorsapi_python_sdk/models/get_report_request_content.py +93 -0
  48. creatorsapi_python_sdk/models/get_report_response_content.py +92 -0
  49. creatorsapi_python_sdk/models/get_variations_request_content.py +135 -0
  50. creatorsapi_python_sdk/models/get_variations_resource.py +79 -0
  51. creatorsapi_python_sdk/models/get_variations_response_content.py +106 -0
  52. creatorsapi_python_sdk/models/image_size.py +96 -0
  53. creatorsapi_python_sdk/models/image_type.py +111 -0
  54. creatorsapi_python_sdk/models/images.py +105 -0
  55. creatorsapi_python_sdk/models/internal_server_exception_response_content.py +94 -0
  56. creatorsapi_python_sdk/models/item.py +138 -0
  57. creatorsapi_python_sdk/models/item_info.py +156 -0
  58. creatorsapi_python_sdk/models/items_result.py +100 -0
  59. creatorsapi_python_sdk/models/language_type.py +94 -0
  60. creatorsapi_python_sdk/models/languages.py +104 -0
  61. creatorsapi_python_sdk/models/list_feeds_response_content.py +100 -0
  62. creatorsapi_python_sdk/models/list_reports_response_content.py +100 -0
  63. creatorsapi_python_sdk/models/manufacture_info.py +106 -0
  64. creatorsapi_python_sdk/models/money.py +96 -0
  65. creatorsapi_python_sdk/models/multi_valued_attribute.py +96 -0
  66. creatorsapi_python_sdk/models/offer_availability_v2.py +98 -0
  67. creatorsapi_python_sdk/models/offer_condition_v2.py +96 -0
  68. creatorsapi_python_sdk/models/offer_listing_v2.py +133 -0
  69. creatorsapi_python_sdk/models/offer_loyalty_points_v2.py +92 -0
  70. creatorsapi_python_sdk/models/offer_merchant_info_v2.py +94 -0
  71. creatorsapi_python_sdk/models/offer_price_v2.py +113 -0
  72. creatorsapi_python_sdk/models/offer_saving_basis.py +101 -0
  73. creatorsapi_python_sdk/models/offer_savings.py +98 -0
  74. creatorsapi_python_sdk/models/offer_type.py +45 -0
  75. creatorsapi_python_sdk/models/offers_v2.py +100 -0
  76. creatorsapi_python_sdk/models/product_info.py +124 -0
  77. creatorsapi_python_sdk/models/rating.py +92 -0
  78. creatorsapi_python_sdk/models/refinement.py +104 -0
  79. creatorsapi_python_sdk/models/refinement_bin.py +94 -0
  80. creatorsapi_python_sdk/models/report_metadata.py +98 -0
  81. creatorsapi_python_sdk/models/resource_not_found_exception_response_content.py +98 -0
  82. creatorsapi_python_sdk/models/saving_basis_type.py +46 -0
  83. creatorsapi_python_sdk/models/search_items_request_content.py +242 -0
  84. creatorsapi_python_sdk/models/search_items_resource.py +77 -0
  85. creatorsapi_python_sdk/models/search_items_response_content.py +106 -0
  86. creatorsapi_python_sdk/models/search_refinements.py +110 -0
  87. creatorsapi_python_sdk/models/search_result.py +110 -0
  88. creatorsapi_python_sdk/models/single_boolean_valued_attribute.py +96 -0
  89. creatorsapi_python_sdk/models/single_integer_valued_attribute.py +96 -0
  90. creatorsapi_python_sdk/models/single_string_valued_attribute.py +96 -0
  91. creatorsapi_python_sdk/models/sort_by.py +48 -0
  92. creatorsapi_python_sdk/models/technical_info.py +102 -0
  93. creatorsapi_python_sdk/models/throttle_exception_response_content.py +98 -0
  94. creatorsapi_python_sdk/models/trade_in_info.py +98 -0
  95. creatorsapi_python_sdk/models/trade_in_price.py +96 -0
  96. creatorsapi_python_sdk/models/unauthorized_exception_reason.py +51 -0
  97. creatorsapi_python_sdk/models/unauthorized_exception_response_content.py +97 -0
  98. creatorsapi_python_sdk/models/unit_based_attribute.py +98 -0
  99. creatorsapi_python_sdk/models/validation_exception_field.py +94 -0
  100. creatorsapi_python_sdk/models/validation_exception_reason.py +48 -0
  101. creatorsapi_python_sdk/models/validation_exception_response_content.py +107 -0
  102. creatorsapi_python_sdk/models/variation_attribute.py +94 -0
  103. creatorsapi_python_sdk/models/variation_dimension.py +98 -0
  104. creatorsapi_python_sdk/models/variation_summary.py +104 -0
  105. creatorsapi_python_sdk/models/variations_result.py +106 -0
  106. creatorsapi_python_sdk/models/website_sales_rank.py +98 -0
  107. creatorsapi_python_sdk/py.typed +0 -0
  108. creatorsapi_python_sdk/rest.py +262 -0
@@ -0,0 +1,98 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License").
7
+ You may not use this file except in compliance with the License.
8
+ A copy of the License is located at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ or in the "license" file accompanying this file. This file is distributed
13
+ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14
+ express or implied. See the License for the specific language governing
15
+ permissions and limitations under the License.
16
+
17
+ """ # noqa: E501
18
+
19
+
20
+
21
+ from __future__ import annotations
22
+ import pprint
23
+ import re # noqa: F401
24
+ import json
25
+
26
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr
27
+ from typing import Any, ClassVar, Dict, List, Optional
28
+ from typing import Optional, Set
29
+ from typing_extensions import Self
30
+
31
+ class VariationDimension(BaseModel):
32
+ """
33
+ The container for variation dimension which represent a dimension and all its possible values.
34
+ """ # noqa: E501
35
+ display_name: Optional[StrictStr] = Field(default=None, description="Display name of the variation dimension, suitable for presentation to users.", alias="displayName")
36
+ locale: Optional[StrictStr] = Field(default=None, description="Locale of the variation dimension display name.")
37
+ name: Optional[StrictStr] = Field(default=None, description="Name of the variation dimension (e.g., 'Size', 'Color').")
38
+ values: Optional[List[StrictStr]] = Field(default=None, description="List of possible values for this variation dimension.")
39
+ __properties: ClassVar[List[str]] = ["displayName", "locale", "name", "values"]
40
+
41
+ model_config = ConfigDict(
42
+ populate_by_name=True,
43
+ validate_assignment=True,
44
+ protected_namespaces=(),
45
+ )
46
+
47
+
48
+ def to_str(self) -> str:
49
+ """Returns the string representation of the model using alias"""
50
+ return pprint.pformat(self.model_dump(by_alias=True))
51
+
52
+ def to_json(self) -> str:
53
+ """Returns the JSON representation of the model using alias"""
54
+ return self.model_dump_json(by_alias=True, exclude_unset=True)
55
+
56
+ @classmethod
57
+ def from_json(cls, json_str: str) -> Optional[Self]:
58
+ """Create an instance of VariationDimension from a JSON string"""
59
+ return cls.from_dict(json.loads(json_str))
60
+
61
+ def to_dict(self) -> Dict[str, Any]:
62
+ """Return the dictionary representation of the model using alias.
63
+
64
+ This has the following differences from calling pydantic's
65
+ `self.model_dump(by_alias=True)`:
66
+
67
+ * `None` is only added to the output dict for nullable fields that
68
+ were set at model initialization. Other fields with value `None`
69
+ are ignored.
70
+ """
71
+ excluded_fields: Set[str] = set([
72
+ ])
73
+
74
+ _dict = self.model_dump(
75
+ by_alias=True,
76
+ exclude=excluded_fields,
77
+ exclude_none=True,
78
+ )
79
+ return _dict
80
+
81
+ @classmethod
82
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
83
+ """Create an instance of VariationDimension from a dict"""
84
+ if obj is None:
85
+ return None
86
+
87
+ if not isinstance(obj, dict):
88
+ return cls.model_validate(obj)
89
+
90
+ _obj = cls.model_validate({
91
+ "displayName": obj.get("displayName"),
92
+ "locale": obj.get("locale"),
93
+ "name": obj.get("name"),
94
+ "values": obj.get("values")
95
+ })
96
+ return _obj
97
+
98
+
@@ -0,0 +1,104 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License").
7
+ You may not use this file except in compliance with the License.
8
+ A copy of the License is located at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ or in the "license" file accompanying this file. This file is distributed
13
+ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14
+ express or implied. See the License for the specific language governing
15
+ permissions and limitations under the License.
16
+
17
+ """ # noqa: E501
18
+
19
+
20
+
21
+ from __future__ import annotations
22
+ import pprint
23
+ import re # noqa: F401
24
+ import json
25
+
26
+ from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt
27
+ from typing import Any, ClassVar, Dict, List, Optional, Union
28
+ from creatorsapi_python_sdk.models.variation_dimension import VariationDimension
29
+ from typing import Optional, Set
30
+ from typing_extensions import Self
31
+
32
+ class VariationSummary(BaseModel):
33
+ """
34
+ The container for Variations Summary response. It consists of metadata of variations response like page numbers, number of variations, Price range and Variation Dimensions.
35
+ """ # noqa: E501
36
+ page_count: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Number of pages in the variation result set.", alias="pageCount")
37
+ variation_count: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Total number of variations available for the product. This represents the complete count of all child ASINs across all pages. Use this value along with pageCount to understand the full scope of available variations.", alias="variationCount")
38
+ variation_dimensions: Optional[List[VariationDimension]] = Field(default=None, description="List of variation dimensions associated with the product. Variation dimensions define the attributes on which products vary (e.g., size, color). Each dimension includes: - Display name and locale for presentation - Dimension name (internal identifier) - List of all possible values for that dimension For example, a clothing item might have two dimensions: 'Size' with values ['S', 'M', 'L'] and 'Color' with values ['Red', 'Blue', 'Green']. These dimensions help users understand how variations differ from each other.", alias="variationDimensions")
39
+ __properties: ClassVar[List[str]] = ["pageCount", "variationCount", "variationDimensions"]
40
+
41
+ model_config = ConfigDict(
42
+ populate_by_name=True,
43
+ validate_assignment=True,
44
+ protected_namespaces=(),
45
+ )
46
+
47
+
48
+ def to_str(self) -> str:
49
+ """Returns the string representation of the model using alias"""
50
+ return pprint.pformat(self.model_dump(by_alias=True))
51
+
52
+ def to_json(self) -> str:
53
+ """Returns the JSON representation of the model using alias"""
54
+ return self.model_dump_json(by_alias=True, exclude_unset=True)
55
+
56
+ @classmethod
57
+ def from_json(cls, json_str: str) -> Optional[Self]:
58
+ """Create an instance of VariationSummary from a JSON string"""
59
+ return cls.from_dict(json.loads(json_str))
60
+
61
+ def to_dict(self) -> Dict[str, Any]:
62
+ """Return the dictionary representation of the model using alias.
63
+
64
+ This has the following differences from calling pydantic's
65
+ `self.model_dump(by_alias=True)`:
66
+
67
+ * `None` is only added to the output dict for nullable fields that
68
+ were set at model initialization. Other fields with value `None`
69
+ are ignored.
70
+ """
71
+ excluded_fields: Set[str] = set([
72
+ ])
73
+
74
+ _dict = self.model_dump(
75
+ by_alias=True,
76
+ exclude=excluded_fields,
77
+ exclude_none=True,
78
+ )
79
+ # override the default output from pydantic by calling `to_dict()` of each item in variation_dimensions (list)
80
+ _items = []
81
+ if self.variation_dimensions:
82
+ for _item_variation_dimensions in self.variation_dimensions:
83
+ if _item_variation_dimensions:
84
+ _items.append(_item_variation_dimensions.to_dict())
85
+ _dict['variationDimensions'] = _items
86
+ return _dict
87
+
88
+ @classmethod
89
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
90
+ """Create an instance of VariationSummary from a dict"""
91
+ if obj is None:
92
+ return None
93
+
94
+ if not isinstance(obj, dict):
95
+ return cls.model_validate(obj)
96
+
97
+ _obj = cls.model_validate({
98
+ "pageCount": obj.get("pageCount"),
99
+ "variationCount": obj.get("variationCount"),
100
+ "variationDimensions": [VariationDimension.from_dict(_item) for _item in obj["variationDimensions"]] if obj.get("variationDimensions") is not None else None
101
+ })
102
+ return _obj
103
+
104
+
@@ -0,0 +1,106 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License").
7
+ You may not use this file except in compliance with the License.
8
+ A copy of the License is located at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ or in the "license" file accompanying this file. This file is distributed
13
+ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14
+ express or implied. See the License for the specific language governing
15
+ permissions and limitations under the License.
16
+
17
+ """ # noqa: E501
18
+
19
+
20
+
21
+ from __future__ import annotations
22
+ import pprint
23
+ import re # noqa: F401
24
+ import json
25
+
26
+ from pydantic import BaseModel, ConfigDict, Field
27
+ from typing import Any, ClassVar, Dict, List, Optional
28
+ from creatorsapi_python_sdk.models.item import Item
29
+ from creatorsapi_python_sdk.models.variation_summary import VariationSummary
30
+ from typing import Optional, Set
31
+ from typing_extensions import Self
32
+
33
+ class VariationsResult(BaseModel):
34
+ """
35
+ The container for Variations response. It consists of items and variation summary. Items contains the list of product variations with their attributes (e.g., different colors, sizes). VariationSummary provides metadata about the complete set of variations including pagination info, price range, and the dimensions along which products vary.
36
+ """ # noqa: E501
37
+ items: Optional[List[Item]] = Field(default=None, description="List of Item which is a container for item information.")
38
+ variation_summary: Optional[VariationSummary] = Field(default=None, alias="variationSummary")
39
+ __properties: ClassVar[List[str]] = ["items", "variationSummary"]
40
+
41
+ model_config = ConfigDict(
42
+ populate_by_name=True,
43
+ validate_assignment=True,
44
+ protected_namespaces=(),
45
+ )
46
+
47
+
48
+ def to_str(self) -> str:
49
+ """Returns the string representation of the model using alias"""
50
+ return pprint.pformat(self.model_dump(by_alias=True))
51
+
52
+ def to_json(self) -> str:
53
+ """Returns the JSON representation of the model using alias"""
54
+ return self.model_dump_json(by_alias=True, exclude_unset=True)
55
+
56
+ @classmethod
57
+ def from_json(cls, json_str: str) -> Optional[Self]:
58
+ """Create an instance of VariationsResult from a JSON string"""
59
+ return cls.from_dict(json.loads(json_str))
60
+
61
+ def to_dict(self) -> Dict[str, Any]:
62
+ """Return the dictionary representation of the model using alias.
63
+
64
+ This has the following differences from calling pydantic's
65
+ `self.model_dump(by_alias=True)`:
66
+
67
+ * `None` is only added to the output dict for nullable fields that
68
+ were set at model initialization. Other fields with value `None`
69
+ are ignored.
70
+ """
71
+ excluded_fields: Set[str] = set([
72
+ ])
73
+
74
+ _dict = self.model_dump(
75
+ by_alias=True,
76
+ exclude=excluded_fields,
77
+ exclude_none=True,
78
+ )
79
+ # override the default output from pydantic by calling `to_dict()` of each item in items (list)
80
+ _items = []
81
+ if self.items:
82
+ for _item_items in self.items:
83
+ if _item_items:
84
+ _items.append(_item_items.to_dict())
85
+ _dict['items'] = _items
86
+ # override the default output from pydantic by calling `to_dict()` of variation_summary
87
+ if self.variation_summary:
88
+ _dict['variationSummary'] = self.variation_summary.to_dict()
89
+ return _dict
90
+
91
+ @classmethod
92
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
93
+ """Create an instance of VariationsResult from a dict"""
94
+ if obj is None:
95
+ return None
96
+
97
+ if not isinstance(obj, dict):
98
+ return cls.model_validate(obj)
99
+
100
+ _obj = cls.model_validate({
101
+ "items": [Item.from_dict(_item) for _item in obj["items"]] if obj.get("items") is not None else None,
102
+ "variationSummary": VariationSummary.from_dict(obj["variationSummary"]) if obj.get("variationSummary") is not None else None
103
+ })
104
+ return _obj
105
+
106
+
@@ -0,0 +1,98 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License").
7
+ You may not use this file except in compliance with the License.
8
+ A copy of the License is located at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ or in the "license" file accompanying this file. This file is distributed
13
+ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14
+ express or implied. See the License for the specific language governing
15
+ permissions and limitations under the License.
16
+
17
+ """ # noqa: E501
18
+
19
+
20
+
21
+ from __future__ import annotations
22
+ import pprint
23
+ import re # noqa: F401
24
+ import json
25
+
26
+ from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr
27
+ from typing import Any, ClassVar, Dict, List, Optional, Union
28
+ from typing import Optional, Set
29
+ from typing_extensions import Self
30
+
31
+ class WebsiteSalesRank(BaseModel):
32
+ """
33
+ Container for Website Sales Rank associated with a product. Includes BrowseNodeId, DisplayName, ContextFreeName and SalesRank information.
34
+ """ # noqa: E501
35
+ context_free_name: Optional[StrictStr] = Field(default=None, alias="contextFreeName")
36
+ display_name: Optional[StrictStr] = Field(default=None, alias="displayName")
37
+ id: Optional[StrictStr] = None
38
+ sales_rank: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="salesRank")
39
+ __properties: ClassVar[List[str]] = ["contextFreeName", "displayName", "id", "salesRank"]
40
+
41
+ model_config = ConfigDict(
42
+ populate_by_name=True,
43
+ validate_assignment=True,
44
+ protected_namespaces=(),
45
+ )
46
+
47
+
48
+ def to_str(self) -> str:
49
+ """Returns the string representation of the model using alias"""
50
+ return pprint.pformat(self.model_dump(by_alias=True))
51
+
52
+ def to_json(self) -> str:
53
+ """Returns the JSON representation of the model using alias"""
54
+ return self.model_dump_json(by_alias=True, exclude_unset=True)
55
+
56
+ @classmethod
57
+ def from_json(cls, json_str: str) -> Optional[Self]:
58
+ """Create an instance of WebsiteSalesRank from a JSON string"""
59
+ return cls.from_dict(json.loads(json_str))
60
+
61
+ def to_dict(self) -> Dict[str, Any]:
62
+ """Return the dictionary representation of the model using alias.
63
+
64
+ This has the following differences from calling pydantic's
65
+ `self.model_dump(by_alias=True)`:
66
+
67
+ * `None` is only added to the output dict for nullable fields that
68
+ were set at model initialization. Other fields with value `None`
69
+ are ignored.
70
+ """
71
+ excluded_fields: Set[str] = set([
72
+ ])
73
+
74
+ _dict = self.model_dump(
75
+ by_alias=True,
76
+ exclude=excluded_fields,
77
+ exclude_none=True,
78
+ )
79
+ return _dict
80
+
81
+ @classmethod
82
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
83
+ """Create an instance of WebsiteSalesRank from a dict"""
84
+ if obj is None:
85
+ return None
86
+
87
+ if not isinstance(obj, dict):
88
+ return cls.model_validate(obj)
89
+
90
+ _obj = cls.model_validate({
91
+ "contextFreeName": obj.get("contextFreeName"),
92
+ "displayName": obj.get("displayName"),
93
+ "id": obj.get("id"),
94
+ "salesRank": obj.get("salesRank")
95
+ })
96
+ return _obj
97
+
98
+
File without changes
@@ -0,0 +1,262 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License").
7
+ You may not use this file except in compliance with the License.
8
+ A copy of the License is located at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ or in the "license" file accompanying this file. This file is distributed
13
+ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14
+ express or implied. See the License for the specific language governing
15
+ permissions and limitations under the License.
16
+
17
+ """ # noqa: E501
18
+
19
+
20
+ import io
21
+ import json
22
+ import re
23
+ import ssl
24
+
25
+ import urllib3
26
+
27
+ from creatorsapi_python_sdk.exceptions import ApiException, ApiValueError
28
+
29
+ SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
30
+ RESTResponseType = urllib3.HTTPResponse
31
+
32
+
33
+ def is_socks_proxy_url(url):
34
+ if url is None:
35
+ return False
36
+ split_section = url.split("://")
37
+ if len(split_section) < 2:
38
+ return False
39
+ else:
40
+ return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
41
+
42
+
43
+ class RESTResponse(io.IOBase):
44
+
45
+ def __init__(self, resp) -> None:
46
+ self.response = resp
47
+ self.status = resp.status
48
+ self.reason = resp.reason
49
+ self.data = None
50
+
51
+ def read(self):
52
+ if self.data is None:
53
+ self.data = self.response.data
54
+ return self.data
55
+
56
+ def getheaders(self):
57
+ """Returns a dictionary of the response headers."""
58
+ return self.response.headers
59
+
60
+ def getheader(self, name, default=None):
61
+ """Returns a given response header."""
62
+ return self.response.headers.get(name, default)
63
+
64
+
65
+ class RESTClientObject:
66
+
67
+ def __init__(self, configuration) -> None:
68
+ # urllib3.PoolManager will pass all kw parameters to connectionpool
69
+ # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
70
+ # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
71
+ # Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501
72
+
73
+ # cert_reqs
74
+ if configuration.verify_ssl:
75
+ cert_reqs = ssl.CERT_REQUIRED
76
+ else:
77
+ cert_reqs = ssl.CERT_NONE
78
+
79
+ pool_args = {
80
+ "cert_reqs": cert_reqs,
81
+ "ca_certs": configuration.ssl_ca_cert,
82
+ "cert_file": configuration.cert_file,
83
+ "key_file": configuration.key_file,
84
+ }
85
+ if configuration.assert_hostname is not None:
86
+ pool_args['assert_hostname'] = (
87
+ configuration.assert_hostname
88
+ )
89
+
90
+ if configuration.retries is not None:
91
+ pool_args['retries'] = configuration.retries
92
+
93
+ if configuration.tls_server_name:
94
+ pool_args['server_hostname'] = configuration.tls_server_name
95
+
96
+
97
+ if configuration.socket_options is not None:
98
+ pool_args['socket_options'] = configuration.socket_options
99
+
100
+ if configuration.connection_pool_maxsize is not None:
101
+ pool_args['maxsize'] = configuration.connection_pool_maxsize
102
+
103
+ # https pool manager
104
+ self.pool_manager: urllib3.PoolManager
105
+
106
+ if configuration.proxy:
107
+ if is_socks_proxy_url(configuration.proxy):
108
+ from urllib3.contrib.socks import SOCKSProxyManager
109
+ pool_args["proxy_url"] = configuration.proxy
110
+ pool_args["headers"] = configuration.proxy_headers
111
+ self.pool_manager = SOCKSProxyManager(**pool_args)
112
+ else:
113
+ pool_args["proxy_url"] = configuration.proxy
114
+ pool_args["proxy_headers"] = configuration.proxy_headers
115
+ self.pool_manager = urllib3.ProxyManager(**pool_args)
116
+ else:
117
+ self.pool_manager = urllib3.PoolManager(**pool_args)
118
+
119
+ def request(
120
+ self,
121
+ method,
122
+ url,
123
+ headers=None,
124
+ body=None,
125
+ post_params=None,
126
+ _request_timeout=None
127
+ ):
128
+ """Perform requests.
129
+
130
+ :param method: http request method
131
+ :param url: http request url
132
+ :param headers: http request headers
133
+ :param body: request json body, for `application/json`
134
+ :param post_params: request post parameters,
135
+ `application/x-www-form-urlencoded`
136
+ and `multipart/form-data`
137
+ :param _request_timeout: timeout setting for this request. If one
138
+ number provided, it will be total request
139
+ timeout. It can also be a pair (tuple) of
140
+ (connection, read) timeouts.
141
+ """
142
+ method = method.upper()
143
+ assert method in [
144
+ 'GET',
145
+ 'HEAD',
146
+ 'DELETE',
147
+ 'POST',
148
+ 'PUT',
149
+ 'PATCH',
150
+ 'OPTIONS'
151
+ ]
152
+
153
+ if post_params and body:
154
+ raise ApiValueError(
155
+ "body parameter cannot be used with post_params parameter."
156
+ )
157
+
158
+ post_params = post_params or {}
159
+ headers = headers or {}
160
+
161
+ timeout = None
162
+ if _request_timeout:
163
+ if isinstance(_request_timeout, (int, float)):
164
+ timeout = urllib3.Timeout(total=_request_timeout)
165
+ elif (
166
+ isinstance(_request_timeout, tuple)
167
+ and len(_request_timeout) == 2
168
+ ):
169
+ timeout = urllib3.Timeout(
170
+ connect=_request_timeout[0],
171
+ read=_request_timeout[1]
172
+ )
173
+
174
+ try:
175
+ # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
176
+ if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
177
+
178
+ # no content type provided or payload is json
179
+ content_type = headers.get('Content-Type')
180
+ if (
181
+ not content_type
182
+ or re.search('json', content_type, re.IGNORECASE)
183
+ ):
184
+ request_body = None
185
+ if body is not None:
186
+ request_body = json.dumps(body)
187
+ r = self.pool_manager.request(
188
+ method,
189
+ url,
190
+ body=request_body,
191
+ timeout=timeout,
192
+ headers=headers,
193
+ preload_content=False
194
+ )
195
+ elif content_type == 'application/x-www-form-urlencoded':
196
+ r = self.pool_manager.request(
197
+ method,
198
+ url,
199
+ fields=post_params,
200
+ encode_multipart=False,
201
+ timeout=timeout,
202
+ headers=headers,
203
+ preload_content=False
204
+ )
205
+ elif content_type == 'multipart/form-data':
206
+ # must del headers['Content-Type'], or the correct
207
+ # Content-Type which generated by urllib3 will be
208
+ # overwritten.
209
+ del headers['Content-Type']
210
+ # Ensures that dict objects are serialized
211
+ post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a,b) for a, b in post_params]
212
+ r = self.pool_manager.request(
213
+ method,
214
+ url,
215
+ fields=post_params,
216
+ encode_multipart=True,
217
+ timeout=timeout,
218
+ headers=headers,
219
+ preload_content=False
220
+ )
221
+ # Pass a `string` parameter directly in the body to support
222
+ # other content types than JSON when `body` argument is
223
+ # provided in serialized form.
224
+ elif isinstance(body, str) or isinstance(body, bytes):
225
+ r = self.pool_manager.request(
226
+ method,
227
+ url,
228
+ body=body,
229
+ timeout=timeout,
230
+ headers=headers,
231
+ preload_content=False
232
+ )
233
+ elif headers['Content-Type'] == 'text/plain' and isinstance(body, bool):
234
+ request_body = "true" if body else "false"
235
+ r = self.pool_manager.request(
236
+ method,
237
+ url,
238
+ body=request_body,
239
+ preload_content=False,
240
+ timeout=timeout,
241
+ headers=headers)
242
+ else:
243
+ # Cannot generate the request from given parameters
244
+ msg = """Cannot prepare a request message for provided
245
+ arguments. Please check that your arguments match
246
+ declared content type."""
247
+ raise ApiException(status=0, reason=msg)
248
+ # For `GET`, `HEAD`
249
+ else:
250
+ r = self.pool_manager.request(
251
+ method,
252
+ url,
253
+ fields={},
254
+ timeout=timeout,
255
+ headers=headers,
256
+ preload_content=False
257
+ )
258
+ except urllib3.exceptions.SSLError as e:
259
+ msg = "\n".join([type(e).__name__, str(e)])
260
+ raise ApiException(status=0, reason=msg)
261
+
262
+ return RESTResponse(r)