sp-api-clients
This is a package generated from amazon selling partner open api models.
This package is for my personal usage, and may not be a good package, but enough for myself.
Features
- ready to use;
- provide code to generate clients, in case that amazon update models;
- type hint.
Usage
For saving time, just paste my test code here.
For better understanding, all the fields are the same length of actual fields, and some readable information are kept.
def test_api():
from datetime import datetime
import sp_api_clients
endpoint = "https://sellingpartnerapi-eu.amazon.com"
marketplace_id = "XXXXXXXXXXXXXX"
refresh_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
order_pk = '123-1234567-1234567'
role_arn = "arn:aws:iam::123456789012:role/xxxxxx"
aws_access_key = 'XXXXXXXXXXXXXXXXXXXX'
aws_secret_key = "XXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
client_id = 'amzn1.application-oa2-client.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
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,
)
order_client = sp_api_clients.orders.OrdersClient(**client_config, use_cache=True)
orders = order_client.getOrders(
MarketplaceIds=[marketplace_id],
CreatedAfter=datetime(2000, 1, 1).isoformat()).payload.Orders
assert len(orders) > 0
assert orders[0].AmazonOrderId == order_pk
Configuration
The client configuration can be set both at the initiation and as environment variables.
- SP_API_ROLE_ARN
- SP_API_ENDPOINT
- SP_API_REGION
- SP_API_MARKETPLACE_ID
- SP_API_REFRESH_TOKEN
- SP_API_AWS_ACCESS_KEY
- SP_API_AWS_SECRET_KEY
- SP_API_LWA_CLIENT_KEY
- SP_API_LWA_CLIENT_SECRET
Build
The client is generated in the following steps:
- download amazon open api 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 script of generation is the test_main python file.
When convert open api to py clients,
I separated the process into 6 steps,
which are defined in the swager_client_generator.stages module.
If my build is not suitable for your demand,
or amazon api model updates but my build do not follow,
you can clone this repo, modify the api.pyt template and build it by yourself,
and please push a PR, thanks!
Acknowledgement
The auth method is partially from python-amazon-sp-api.
Note
If this library helps you, please give me a star, thanks!
如果这个库对您有用,请为我点亮Star,谢谢!
商业合作请联系 panhaoyu.china@outlook.com。
Metadata
Release files for sp-api-clients 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sp-api-clients-0.2.5.tar.gz | 54.3 kB | Without provenance | Details for sp-api-clients-0.2.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sp_api_clients-0.2.5-py3-none-any.whl | Python 3 | none | any | Details for sp_api_clients-0.2.5-py3-none-any.whl |
Total release size: 117.6 kB
Release files / sp-api-clients-0.2.5.tar.gz
| Download URL | sp-api-clients-0.2.5.tar.gz |
|---|---|
| Size | 54.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a814b75e59ed999ac44f1347f8731e5c481c51562aa0bf53c4ce2ec5e639998c
|
|
BLAKE2b-256 checksum How to use checksums |
614f89cfe13b01391f21d712e435873cee6dde383ed5b5effef39ff6bd238d00
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.1
|
Release files / sp_api_clients-0.2.5-py3-none-any.whl
| Download URL | sp_api_clients-0.2.5-py3-none-any.whl |
|---|---|
| Size | 63.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5d332ec9c9ab4c3f98b87d3a7232d5d85dd7124ccdd21b2d108b9e40d0906054
|
|
BLAKE2b-256 checksum How to use checksums |
0a77ab39f940d85f34f2bc2f277d831bcedc47d2d04ee82c490097f9d5e908a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.1
|
Security for sp-api-clients 0.2.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.