Skip to main content

Amazon selling partner api clients.

Project description

amazon-sp-api-clients

This is a package generated from amazon selling partner open api models.

The package is tested in many situations, with fully type hint supported. Enjoy it!

typehint 1

typehint 2

typehint 3

Attention

V1.0.0 changes many api, compared with v0.x.x!

注意!V1.0.0相较于v0.x.x更改了大量的API!

Features

  • ready to use;
  • provide code to generate clients, in case that amazon update models;
  • type hint;
  • orders api, feed api, report api, and all other apis;
  • automatically manage tokens.

Installation

pip install amazon-sp-api-clients

Note

For technical support, please contact panhaoyu.china@outlook.com.

Previously this lib is 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 fell free to open an issue or send a pr.

Usage

For saving time, I just paste part of my test code here as a demo.

For better understanding, all the fields are the same length of actual fields, and some readable information are kept.

from datetime import datetime
import amazon_sp_api_clients
endpoint = "https://sellingpartnerapi-eu.amazon.com"
marketplace_id = "XXXXXXXXXXXXXX"
refresh_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
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,
)
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

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:

  1. download amazon open api repository;
  2. copy open api 2 json files from the amazon repository to a single directory;
  3. convert open api 2 json files to open api 3 json files;
  4. 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,谢谢!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

amazon-sp-api-clients-1.8.6.tar.gz (121.0 kB view details)

Uploaded Source

Built Distribution

amazon_sp_api_clients-1.8.6-py3-none-any.whl (163.3 kB view details)

Uploaded Python 3

File details

Details for the file amazon-sp-api-clients-1.8.6.tar.gz.

File metadata

  • Download URL: amazon-sp-api-clients-1.8.6.tar.gz
  • Upload date:
  • Size: 121.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.1 Windows/10

File hashes

Hashes for amazon-sp-api-clients-1.8.6.tar.gz
Algorithm Hash digest
SHA256 c163e6aac7a09ca22a1d9a281b23eca58a972a9e0bf3b6f8fc183aac2bcac8a1
MD5 46f0b2b0c53a2af139dd4fadc6a41404
BLAKE2b-256 55d02c3358f7e552c1794fa57fd21f8d8ad043ea26fb7bdf87b493aa6ef51f1a

See more details on using hashes here.

File details

Details for the file amazon_sp_api_clients-1.8.6-py3-none-any.whl.

File metadata

File hashes

Hashes for amazon_sp_api_clients-1.8.6-py3-none-any.whl
Algorithm Hash digest
SHA256 dc169635fc3c8cdaae2f555dd2aec9047aa064bb331fb749ddd93e63a28a7785
MD5 bb85d2477aa27802d9a171b90c2e1213
BLAKE2b-256 4344d8c8de56e12bd772ebbfcc7f1b1f78a1eb440658878ae237f53f13765c5f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page