amazon-sp-api-clients
Python clients for the Amazon Selling Partner API, generated from the official open api models. Fully type hinted and battle-tested. Enjoy it!
Attention
V1.0.0 changes many apis, compared with v0.x.x!
注意!V1.0.0 相较于 v0.x.x 更改了大量的 API!
Features
- Ready to use
- Fully type hinted
- Orders, feeds, reports and all other Selling Partner APIs
- Automatically manage LWA access tokens and STS role assumption
- Ships with a code generator, in case Amazon updates the models
- 700+ mocked tests, runnable without any credentials
Installation
pip install amazon-sp-api-clients
Quick Start
All credential fields below follow the real layout of actual credentials, with the sensitive parts replaced by ....
from datetime import datetime
import amazon_sp_api_clients
endpoint = "https://sellingpartnerapi-eu.amazon.com"
marketplace_id = "A1F83G8C2ARO7P"
refresh_token = "Atzr|...xxxx"
role_arn = "arn:aws:iam::123456789012:role/xxxxxx"
aws_access_key = "...xxxx"
aws_secret_key = "...xxxx"
client_id = "amzn1.application-oa2-client....xxxx"
client_secret = "...xxxx"
client_config = dict(
role_arn=role_arn,
endpoint=endpoint,
marketplace_id=marketplace_id,
refresh_token=refresh_token,
aws_access_key=aws_access_key,
aws_secret_key=aws_secret_key,
lwa_client_key=client_id,
lwa_client_secret=client_secret,
)
clients = amazon_sp_api_clients.AmazonSpApiClients(**client_config)
orders = clients.orders_v0.getOrders(
MarketplaceIds=[marketplace_id],
CreatedAfter=datetime(2000, 1, 1).isoformat(),
).payload.Orders
for order in orders:
print(order.AmazonOrderId, order.LastUpdateDate)
Configuration
Configuration can be passed to the constructor, or read from environment variables.
Constructor parameters
role_arn— IAM role to assume, e.g.arn:aws:iam::xxxxxxxxxxxx:role/sp_api_roleendpoint— Selling Partner API endpoint, e.g.https://sellingpartnerapi-eu.amazon.comregion— AWS region for the STS role, defaultus-east-1marketplace_id— e.g.A1F83G8C2ARO7P(EU marketplace)refresh_token— LWA refresh tokenaws_access_key— IAM user access keyaws_secret_key— IAM user secret keylwa_client_key— LWA application client idlwa_client_secret— LWA application client secretraise_exceptions— ifTrueraiseSellingApiExceptionon error, ifFalsereturn the response json as-is (defaultTrue)
Environment variables
SP_API_ROLE_ARNSP_API_ENDPOINTSP_API_REGIONSP_API_MARKETPLACE_IDSP_API_REFRESH_TOKENSP_API_AWS_ACCESS_KEYSP_API_AWS_SECRET_KEYSP_API_LWA_CLIENT_KEYSP_API_LWA_CLIENT_SECRET
Documentation
Detailed Chinese documentation lives under docs/, with docs/README.md as the index.
中文详细文档见 docs/ 目录,docs/README.md 为索引。
- docs/README.md — 文档索引
- 01_项目概览
- 02_快速开始
- 03_核心机制
- 04_API客户端参考
- 05_市场与端点
- 06_报表与Feed类型
- 07_代码生成器
- 08_测试指南
- 09_常见问题与调试
- 10_版本历史与兼容性
Tests
700+ mocked tests runnable without any credentials. 无需任何凭证即可运行全部测试:
py -m pytest tests -q
Build
Clients are generated from the Amazon open api models:
- download the amazon selling-partner-api-models repository
- copy open api 2 json files from the amazon repository to a single directory
- convert open api 2 json files to open api 3 json files
- convert open api 3 json files to py clients
The main generation script is test_main, and the conversion is split into 6 steps defined in the swager_client_generator.stages module.
If the build does not fit your demand, or Amazon updates the models but this repo has not followed yet, clone the repo, modify the api.pyt template and build it by yourself — and please push a PR, thanks!
See docs/07_代码生成器.md for details.
Acknowledgement
The auth method is partially from python-amazon-sp-api.
Note
For technical support, please contact panhaoyu.china@outlook.com.
Previously this lib was only open access but not open source, and now it's time to make it public to serve more developers.
If there's any bug, please feel free to open an issue or send a PR.
If this library helps you, please give me a star, thanks!
如果这个库对您有用,请为我点亮 Star,谢谢!
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file amazon_sp_api_clients-2.0.1.tar.gz.
File metadata
- Download URL: amazon_sp_api_clients-2.0.1.tar.gz
- Upload date:
- Size: 154.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.4.1 CPython/3.14.6 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99cf47f91f36e57d8f0ec178deaa72d2ed3b098758d3a9c6feeec9f3c9793241
|
|
| MD5 |
bf87f34865074de754ed2c876bef38ae
|
|
| BLAKE2b-256 |
3d51914fac82c00ae8d93207ca201259c5c240ab0b3c65a6a95bc3a4851ac55c
|
File details
Details for the file amazon_sp_api_clients-2.0.1-py3-none-any.whl.
File metadata
- Download URL: amazon_sp_api_clients-2.0.1-py3-none-any.whl
- Upload date:
- Size: 204.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.4.1 CPython/3.14.6 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8329625f85de6f20076718b215db6802a20fe2a87f32ecdcf5c79ab968700bd8
|
|
| MD5 |
17309d080c4aa38e6300bb27220c6cf3
|
|
| BLAKE2b-256 |
2692e8e6e29f3a66ce28f4fa20a8d112c74fd8561515eea701976ac76d81a50a
|