Skip to main content

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!

typehint 1

typehint 2

typehint 3

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_role
  • endpoint — Selling Partner API endpoint, e.g. https://sellingpartnerapi-eu.amazon.com
  • region — AWS region for the STS role, default us-east-1
  • marketplace_id — e.g. A1F83G8C2ARO7P (EU marketplace)
  • refresh_token — LWA refresh token
  • aws_access_key — IAM user access key
  • aws_secret_key — IAM user secret key
  • lwa_client_key — LWA application client id
  • lwa_client_secret — LWA application client secret
  • raise_exceptions — if True raise SellingApiException on error, if False return the response json as-is (default True)

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

Documentation

Detailed Chinese documentation lives under docs/, with docs/README.md as the index.

中文详细文档见 docs/ 目录,docs/README.md 为索引。

Tests

700+ mocked tests runnable without any credentials. 无需任何凭证即可运行全部测试:

py -m pytest tests -q

Build

Clients are generated from the Amazon open api models:

  1. download the amazon selling-partner-api-models 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 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

amazon_sp_api_clients-2.0.1.tar.gz (154.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

amazon_sp_api_clients-2.0.1-py3-none-any.whl (204.3 kB view details)

Uploaded Python 3

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

Hashes for amazon_sp_api_clients-2.0.1.tar.gz
Algorithm Hash digest
SHA256 99cf47f91f36e57d8f0ec178deaa72d2ed3b098758d3a9c6feeec9f3c9793241
MD5 bf87f34865074de754ed2c876bef38ae
BLAKE2b-256 3d51914fac82c00ae8d93207ca201259c5c240ab0b3c65a6a95bc3a4851ac55c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for amazon_sp_api_clients-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8329625f85de6f20076718b215db6802a20fe2a87f32ecdcf5c79ab968700bd8
MD5 17309d080c4aa38e6300bb27220c6cf3
BLAKE2b-256 2692e8e6e29f3a66ce28f4fa20a8d112c74fd8561515eea701976ac76d81a50a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 files

1.9.2

2 files

1.9.1

2 files

1.9.0

2 files

1.8.12

2 files

1.8.11

2 files

1.8.9

2 files

1.8.8

2 files

1.8.7

2 files

1.8.6

2 files

1.8.5

2 files

1.8.4

2 files

1.8.3

2 files

1.8.2

2 files

1.8.1

2 files

1.8.0

2 files

1.7.10

2 files

1.7.9

2 files

1.7.8

2 files

1.7.7

2 files

1.7.6

2 files

1.7.5

2 files

1.7.4

2 files

1.7.3

2 files

1.7.2

2 files

1.7.1

2 files

1.7.0

2 files

1.6.3

2 files

1.6.2

2 files

1.6.0

2 files

1.5.0

2 files

1.4.1

2 files

1.4.0

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page