Python Amazon SP Api Readthedocs Io en v0.1.4
Python Amazon SP Api Readthedocs Io en v0.1.4
Michael Primke
1 Installation 1
2 Credentials 3
2.1 Environment Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Config File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 From Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3 Client Usage 7
4 Endpoints 9
4.1 Catalog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.2 Feeds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.3 Finances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.4 Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.5 Orders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.6 Product Fees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.7 Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.8 Reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.9 Sales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.10 Sellers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.11 Inventories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Index 23
i
ii
CHAPTER
ONE
INSTALLATION
1
PYTHON-AMAZON-SP-API
2 Chapter 1. Installation
CHAPTER
TWO
CREDENTIALS
You can pass your credentials multiple ways, use one of them. The order of searching for credentials is:
1. Parameters passed from code
2. Environment variables
3. Config File
You can (but don’t have to) suffix each of these variables with _<account> if you want to set multiple accounts via
env variables.
Orders().get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())
3
PYTHON-AMAZON-SP-API
Orders(account='ANOTHER_ACCOUNT').get_orders(CreatedAfter=(datetime.utcnow() -
˓→timedelta(days=7)).isoformat())
2.1.3 Note
The refresh token can be passed directly to the client, too. You don’t need to pass the whole credentials if all that
changes is the refresh token.
Orders(account='ANOTHER_ACCOUNT', refresh_token='<refresh_token_for_this_request>').
˓→get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())
An example config file is provided in this repository, it supports multiple accounts. The programm looks for a file
called credentials.yml1
The config is parsed by confused2 , see their docs for more in depth information. Search paths are:
macOS: ~/.config/python-sp-api
Other Unix: ~/.config/python-sp-api
Windows: %APPDATA%\python-sp-api where the APPDATA environment variable falls back to
˓→%HOME%\AppData\Roaming if undefined
If you’re only using one account, place it under default. You can pass the account’s name to the client to use any other
account used in the credentials.yml1 file.
version: '1.0'
default:
refresh_token: ''
lwa_app_id: ''
lwa_client_secret: ''
aws_secret_key: ''
aws_access_key: ''
role_arn: ''
another_account:
refresh_token: ''
lwa_app_id: ''
lwa_client_secret: ''
aws_secret_key: ''
aws_access_key: ''
role_arn: ''
1 https://github.com/saleweaver/python-amazon-sp-api/blob/master/credentials.yml
2 https://confuse.readthedocs.io/en/latest/usage.html#search-paths
4 Chapter 2. Credentials
PYTHON-AMAZON-SP-API
Orders().get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())
You can use every account’s name from the config file for account
Orders(account=another_account).get_orders(CreatedAfter=(datetime.utcnow() -
˓→timedelta(days=7)).isoformat())
Note
The refresh token can be passed directly to the client, too. You don’t need to pass the whole credentials if all that
changes is the refresh token.
Orders(account='another_account', refresh_token='<refresh_token_for_this_request>').
˓→get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())
2.2.3 References
You can override/set credentials from code by passing a dict to the client.
If you pass a value in credentials, other credentials from env variables or from a config file will be ignored.
Required fields:
credentials=dict(
refresh_token='<refresh_token>',
lwa_app_id='<lwa_app_id>',
lwa_client_secret='<lwa_client_secret>',
aws_secret_key='<aws_secret_access_key>',
aws_access_key='<aws_access_key_id>',
role_arn='<role_arn>',
)
2.3.1 Usage
Orders(credentials=credentials).get_orders(CreatedAfter=(datetime.utcnow() -
˓→timedelta(days=7)).isoformat())
6 Chapter 2. Credentials
CHAPTER
THREE
CLIENT USAGE
All endpoint’s clients have the following signature and default values:
SomeClient(
marketplace=Marketplaces.US, *,
refresh_token=None,
account='default',
credentials=None
)
7
PYTHON-AMAZON-SP-API
FOUR
ENDPOINTS
4.1 Catalog
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
Parameters
• asin – str
• MarketplaceId (key) – str
• **kwargs –
Returns
Return type GetCatalogItemResponse
list_items(self, **kwargs) → ListCatalogItemsResponse
Returns a list of items and their attributes, based on a search query or item identifiers that you specify.
When based on a search query, provide the Query parameter and optionally, the QueryContextId parameter.
When based on item identifiers, provide a single appropriate parameter based on the identifier type, and
specify the associated item value. MarketplaceId is always required.
Usage Plan:
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
Parameters
9
PYTHON-AMAZON-SP-API
4.2 Feeds
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
Parameters
• feed_type – https://github.com/amzn/selling-partner-api-docs/blob/main/references/
feeds-api/feedType_string_array_values.md
• input_feed_document_id – str
• **kwargs –
Returns
Return type CreateFeedResponse
create_feed_document(self, file: File or FileLike, content_type='text/tsv', **kwargs) → Create-
FeedDocumentResponse
Creates a feed document for the feed type that you specify. This method also encrypts and uploads the file
you specify.
Usage Plan:
10 Chapter 4. Endpoints
PYTHON-AMAZON-SP-API
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
Parameters
• file – File or File like object
• content_type – str
• **kwargs –
Returns
Return type CreateFeedDocumentResponse
submit_feed(self, feed_type: str, file: File or File like, content_type='text/tsv', **kwargs) → [Create-
FeedDocumentResponse, CreateFeedResponse]
This method combines create_feed_document and create_feed.
It uploads the encrypted file and sends the feed to amazon
Usage Plan:
Parameters
• feed_type –
• file –
• content_type –
• **kwargs –
Returns
Return type [CreateFeedDocumentResponse, CreateFeedResponse]
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
Parameters
• feed_id – str
• **kwargs –
Returns
Return type GetFeedResponse
get_feed_result_document(**kwargs)
Returns the decrypted, unpacked FeedResponse
Usage Plan:
4.2. Feeds 11
PYTHON-AMAZON-SP-API
Parameters
• feed_id – str
• **kwargs –
Returns The feed results’ contents
Return type str
4.3 Finances
4.4 Notifications
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
Parameters
• notification_type – NotificationType or str
• destination_id – str
• **kwargs –
Returns
Return type CreateSubscriptionResponse
get_subscription(self, notification_type: NotificationType or str, **kwargs) → GetSubscription-
Response
Returns information about subscriptions of the specified notification type. You can use this API to get
subscription information when you do not have a subscription identifier.
12 Chapter 4. Endpoints
PYTHON-AMAZON-SP-API
Usage Plan:
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
Parameters
• notification_type – NotificationType or str
• **kwargs –
Returns
Return type GetSubscriptionResponse
delete_notification_subscription(self, notification_type: NotificationType or str, sub-
scription_id: str, **kwargs) → DeleteSubscription-
ByIdResponse
Deletes the subscription indicated by the subscription identifier and notification type that you specify. The
subscription identifier can be for any subscription associated with your application. After you successfully
call this operation, notifications will stop being sent for the associated subscription. The deleteSubscrip-
tionById API is grantless. For more information, see “Grantless operations” in the Selling Partner API
Developer Guide.
Usage Plan:
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
Parameters
• notification_type – NotificationType or str
• subscription_id – str
• **kwargs –
Returns
Return type DeleteSubscriptionByIdResponse
create_destination(self, name: str, arn: str, **kwargs) → CreateDestinationResponse
Creates a destination resource to receive notifications. The createDestination API is grantless. For more
information, see “Grantless operations” in the Selling Partner API Developer Guide.
Usage Plan:
Parameters
• name – str
• arn – str
• **kwargs –
4.4. Notifications 13
PYTHON-AMAZON-SP-API
Returns
Return type CreateDestinationResponse
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
Parameters **kwargs –
Returns
Return type GetDestinationsResponse
get_destination(self, destination_id: str, **kwargs) → GetDestinationResponse
Returns information about all destinations. The getDestinations API is grantless. For more information,
see “Grantless operations” in the Selling Partner API Developer Guide.
Usage Plan:
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
Parameters
• destination_id – str
• **kwargs –
Returns
Return type GetDestinationResponse
delete_destination(self, destination_id: str, **kwargs) → DeleteDestinationResponse
Deletes the destination that you specify. The deleteDestination API is grantless. For more information, see
“Grantless operations” in the Selling Partner API Developer Guide.
Usage Plan:
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
Parameters
• destination_id – str
• **kwargs –
Returns
Return type DeleteDestinationResponse
14 Chapter 4. Endpoints
PYTHON-AMAZON-SP-API
4.5 Orders
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
Parameters
• CreatedAfter (key) – date
• CreatedBefore (key) – date
• LastUpdatedAfter (key) – date
• LastUpdatedBefore (key) – date
• OrderStatuses (key) – [str]
• MarketplaceIds (key) – [str]
• FulfillmentChannels (key) – [str]
• PaymentMethods (key) – [str]
• BuyerEmail (key) – str
• SellerOrderId (key) – str
• MaxResultsPerPage (key) – int
• EasyShipShipmentStatuses (key) – [str]
• NextToken (key) – str
• AmazonOrderIds (key) – [str]
Returns
Return type GetOrdersResponse
get_order(self, order_id: str, **kwargs) → GetOrderResponse
Returns the order indicated by the specified order ID.
Usage Plan:
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
4.5. Orders 15
PYTHON-AMAZON-SP-API
Parameters
• order_id – str
• **kwargs –
Returns
Return type GetOrderResponse
get_order_items(self, order_id: str, **kwargs) → GetOrderItemsResponse
Returns detailed order item information for the order indicated by the specified order ID. If NextToken is
provided, it’s used to retrieve the next page of order items.
Note: When an order is in the Pending state (the order has been placed but payment has not been au-
thorized), the getOrderItems operation does not return information about pricing, taxes, shipping charges,
gift status or promotions for the order items in the order. After an order leaves the Pending state (this
occurs when payment has been authorized) and enters the Unshipped, Partially Shipped, or Shipped state,
the getOrderItems operation returns information about pricing, taxes, shipping charges, gift status and
promotions for the order items in the order.
Usage Plan:
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
Parameters
• order_id – str
• **kwargs –
Returns
Return type GetOrderItemsResponse
get_order_address(**kwargs)
Returns the shipping address for the order indicated by the specified order ID.
Note To get useful information from this method, you need to have access to PII.
Usage Plan:
Parameters
• order_id – str
• **kwargs –
Returns:
get_order_buyer_info(self, order_id: str, **kwargs) → GetOrderBuyerInfoResponse
Returns buyer information for the order indicated by the specified order ID.
Note To get useful information from this method, you need to have access to PII.
16 Chapter 4. Endpoints
PYTHON-AMAZON-SP-API
Usage Plan:
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
Parameters
• order_id – str
• **kwargs –
Returns
Return type GetOrderBuyerInfoResponse
4.7 Products
Parameters
• seller_sku_list – [str]
• item_condition – str (“New”, “Used”, “Collectible”, “Refurbished”, “Club”)
• **kwargs –
Returns
Return type GetPricingResponse
Parameters
• asin_list – [str]
• item_condition – str (“New”, “Used”, “Collectible”, “Refurbished”, “Club”) Filters
the offer listings based on item condition. Possible values: New, Used, Collectible, Refur-
bished, Club. Available values : New, Used, Collectible, Refurbished, Club
• kwargs –
Returns
Parameters
• seller_sku_list – [str]
• kwargs –
Returns
Parameters
• asin_list – [str]
• kwargs –
Returns
4.8 Reports
18 Chapter 4. Endpoints
PYTHON-AMAZON-SP-API
4.9 Sales
4.10 Sellers
4.11 Inventories
For more information, see “Usage Plans and Rate Limits” in the Selling Partner API documentation.
All inventory summaries with available details are returned when the startDateTime and sellerSkus param-
eters are omitted. When startDateTime is provided, the operation returns inventory summaries that have
had changes after the date and time specified. The sellerSkus parameter is ignored. When the sellerSkus
parameter is provided, the operation returns inventory summaries for only the specified sellerSkus. Usage
Plan:
Parameters
• details (key) – bool | true to return inventory summaries with additional summarized
inventory details and quantities. Otherwise, returns inventory summaries only (default
value). boolean “false”
• granularityType (key) – Granularity Type | The granularity type for the inventory
aggregation level. enum (GranularityType) -
• granularityId (key) – str The granularity ID for the inventory aggregation level.
string -
4.9. Sales 19
PYTHON-AMAZON-SP-API
• startDateTime (key) – datetime | A start date and time in ISO8601 format. If speci-
fied, all inventory summaries that have changed since then are returned. You must specify
a date and time that is no earlier than 18 months prior to the date and time when you
call the API. Note: Changes in inboundWorkingQuantity, inboundShippedQuantity and
inboundReceivingQuantity are not detected. string (date-time) -
• sellerSkus (key) – [str] | A list of seller SKUs for which to return inventory sum-
maries. You may specify up to 50 SKUs.
• nextToken (key) – str | String token returned in the response of your previous request.
string -
• marketplaceIds (key) – str | The marketplace ID for the marketplace for which to
return inventory summaries.
Returns
Return type GetInventorySummariesResponse
20 Chapter 4. Endpoints
CHAPTER
FIVE
• genindex
• modindex
• search
21
PYTHON-AMAZON-SP-API
A get_order_buyer_info() (sp_api.api.Orders
add_subscription() (sp_api.api.Notifications method), 16
method), 12 get_order_items() (sp_api.api.Orders method), 16
get_orders() (sp_api.api.Orders method), 15
C get_product_pricing_for_asins()
(sp_api.api.Products method), 17
Catalog (class in sp_api.api), 9
get_product_pricing_for_skus()
create_destination() (sp_api.api.Notifications
(sp_api.api.Products method), 17
method), 13
get_subscription() (sp_api.api.Notifications
create_feed() (sp_api.api.Feeds method), 10
method), 12
create_feed_document() (sp_api.api.Feeds
method), 10
create_subscription() (sp_api.api.Notifications
I
method), 12 Inventories (class in sp_api.api), 19
D L
delete_destination() (sp_api.api.Notifications list_items() (sp_api.api.Catalog method), 9
method), 14
delete_notification_subscription() N
(sp_api.api.Notifications method), 13 Notifications (class in sp_api.api), 12
F O
Feeds (class in sp_api.api), 10 Orders (class in sp_api.api), 15
G P
get_competitive_pricing_for_asins() Products (class in sp_api.api), 17
(sp_api.api.Products method), 18
get_competitive_pricing_for_skus() S
(sp_api.api.Products method), 18 submit_feed() (sp_api.api.Feeds method), 11
get_destination() (sp_api.api.Notifications
method), 14
get_destinations() (sp_api.api.Notifications
method), 14
get_feed() (sp_api.api.Feeds method), 11
get_feed_result_document() (sp_api.api.Feeds
method), 11
get_inventory_summary_marketplace()
(sp_api.api.Inventories method), 19
get_item() (sp_api.api.Catalog method), 9
get_order() (sp_api.api.Orders method), 15
get_order_address() (sp_api.api.Orders method),
16
23