Amazon Selling-Partner API
A wrapper to access Amazon's Selling Partner API with an easy-to-use interface.
New Features
Async support!
- httpx-based transport for sync clients, enabling connection pooling and consistent streaming behavior.
- Async client package under
sp_api.asynciofor non-blocking calls across services.
🌟 Thank you for using python-amazon-sp-api! 🌟
This tool helps developers and businesses connect seamlessly with Amazon's vast marketplace, enabling powerful automations and data management.
If you appreciate this project and find it useful, please consider supporting its continued development:
- 🙌 GitHub Sponsors
Your support helps keep the project alive and evolving, and is greatly appreciated!
Documentation
Documentation is available here
Q & A
If you have questions, please ask them in GitHub discussions
or
Installation
pip install python-amazon-sp-api
pip install "python-amazon-sp-api[aws]" # if you want to use AWS Secret Manager Authentication.
pip install "python-amazon-sp-api[aws-caching]" # if you want to use the Cached Secrets from AWS
Usage
from sp_api.api import Orders from sp_api.api import Reports from sp_api.api import DataKiosk from sp_api.api import Feeds from sp_api.base import SellingApiException from sp_api.base.reportTypes import ReportType from datetime import datetime, timedelta, timezone # DATA KIOSK API client = DataKiosk() res = client.create_query(query="{analytics_salesAndTraffic_2023_11_15{salesAndTrafficByAsin(startDate:\"2022-09-01\" endDate:\"2022-09-30\" aggregateBy:SKU marketplaceIds:[\"ATVPDKIKX0DER\"]){childAsin endDate marketplaceId parentAsin sales{orderedProductSales{amount currencyCode}totalOrderItems totalOrderItemsB2B}sku startDate traffic{browserPageViews browserPageViewsB2B browserPageViewsPercentage browserPageViewsPercentageB2B browserSessionPercentage unitSessionPercentageB2B unitSessionPercentage}}}}") print(res) # orders API try: res = Orders().get_orders(CreatedAfter=(datetime.now(timezone.utc) - timedelta(days=7)).isoformat()) print(res.payload) # json data except SellingApiException as ex: print(ex) # report request create_report_response = Reports().create_report(reportType=ReportType.GET_MERCHANT_LISTINGS_ALL_DATA) # submit feed # feeds can be submitted like explained in Amazon's docs, or simply by calling submit_feed Feeds().submit_feed(<feed_type>, <file_or_bytes_io>, content_type='text/tsv', **kwargs) # PII Data Orders(restricted_data_token='<token>').get_orders(CreatedAfter=(datetime.now(timezone.utc) - timedelta(days=7)).isoformat()) # or use the shortcut orders = Orders().get_orders( LastUpdatedAfter=(datetime.now(timezone.utc) - timedelta(days=1)).isoformat() )
Async Usage
import asyncio from datetime import datetime, timedelta, timezone from sp_api.asyncio.api import Orders, Reports from sp_api.base.reportTypes import ReportType async def main(): async with Orders() as orders_client: res = await orders_client.get_orders( LastUpdatedAfter=(datetime.now(timezone.utc) - timedelta(days=1)).isoformat() ) print(res.payload) async with Reports() as reports_client: report = await reports_client.create_report( reportType=ReportType.GET_MERCHANT_LISTINGS_ALL_DATA ) print(report.payload) # OR await Reports().create_report( reportType=ReportType.GET_MERCHANT_LISTINGS_ALL_DATA ) if __name__ == "__main__": asyncio.run(main())
New endpoints
You can create a new endpoint file by running make_endpoint <model_json_url>
make_endpoint https://raw.githubusercontent.com/amzn/selling-partner-api-models/main/models/listings-restrictions-api-model/listingsRestrictions_2021-08-01.json
This creates a ready to use client. Please consider creating a pull request with the new code.
ADVERTISING API
You can use nearly the same client for the Amazon Advertising API. @denisneuf has built Python-Amazon-Advertising-API on top of this client. Check it out here
DISCLAIMER
We are not affiliated with Amazon
LICENSE
Base Client
The client is pretty extensible and can be used for any other API. Check it out here: