Skip to main content

Amazon Selling Partner Python Library

The Amazon Selling Partner Python library provides convenient access to the Amazon Selling Partner API from applications written in the Python language. It includes a pre-defined set of classes for API resources and it is compatible with the latest versions of the Amazon Selling Partner API.

Documentation

Installation

Create Virtual Environment

python3 -m pip install virtualenv

Enable Virtual Environment

For Linux and OS X

. ./venv/bin/activate

For Windows

. ./venv/Scripts/activate

Upgrade PIP

python -m pip install --upgrade pip

Install from a GitHub private repo

TOKEN="<token>" pip install git+https://dbritto-dev:$TOKEN@github.com/dbritto-dev/amzn-selling-partner-python.git

Install from source

pip install .

Requirements

  • Python 3.9 (PyPy supported)

Usage

This library needs to be configure with your account's secret keys: Selling Partner Keys and AWS Keys.

Set up the next environment variables. We can use dotenv to load them locally.

# Fetch "client id" and "client secret" from your application in Seller Central
# by clicking on "View" in front of your application ID.
SELLING_PARTNER_APP_CLIENT_ID=
SELLING_PARTNER_APP_CLIENT_SECRET=
# In order to call an API for a seller, you will need to paste the
# refresh_token for that particular seller below. You can get refresh token for
# a seller using OAuth flow. Otherwise, you can self-authorize your application
# by clicking on "Authorize" from the dropdown menu in front of your
# application ID in seller central. Once you click on "Generate Refresh Token",
# you would be able to receive a refresh token and paste it below.
SELLING_PARTNER_APP_REFRESH_TOKEN=
# Pull out "access key ID" and "secret access key" from IAM console by cliking on
# "Users" navigation menu option and opening "Security Credentials" tab.
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
# This role is necessary to create temporary credentials to the call Selling Partner API, to read
# more about which policies and resources are needed for this role, here's the link (click on ->
# `Select to expand the manual steps to create and configure IAM policies.` to read more about that)
# https://developer-docs.amazon.com/sp-api/docs/tutorial-create-a-private-selling-partner-api-application#step-3-create-and-configure-iam-resources
# The role session name is just the label that we set up for those temporary credentials
AWS_SELLING_PARTNER_ROLE=
AWS_SELLING_PARTNER_ROLE_SESSION_NAME=
import amzn_selling_partner.vendor as sp

sp_vendor_orders_client = sp.vendor.orders.Client()

purchase_orders = sp_vendor_orders_client.get_purchase_orders()
print(purchase_orders)

purchase_order = sp_vendor_orders_client.get_purchase_order("<purchase-order-number>")
print(purchase_order)

Handling exceptions

Unsuccessful requests raise exceptions. The errors should handled as Requests library exceptions. To read more about that: https://requests.readthedocs.io/en/latest/user/quickstart/#errors-and-exceptions

Per-client configuration

Configure individual clients with keyword arguments. For instance, you can make a request with a specific selling partner region or use sandbox.

import amzn_selling_partner.vendor as sp

na_sp_vendor_orders_client = sp.vendor.orders.Client(
    selling_partner_region=client.SellingPartnerRegion.NORTH_AMERICA
)

eu_sp_vendor_orders_client = sp.vendor.orders.Client(
    selling_partner_region=client.SellingPartnerRegion.EUROPE
)

fe_sp_vendor_orders_client = sp.vendor.orders.Client(
    selling_partner_region=client.SellingPartnerRegion.FAR_EAST
)

Enable Sandbox

import amzn_selling_partner.vendor as sp

sp_vendor_orders_client = sp.vendor.orders.Client(sandbox=True)

Note: some endpoints are not available on sandbox. To read more about that: https://developer-docs.amazon.com/sp-api/docs/the-selling-partner-api-sandbox

Development

Install from source

pip install .[dev]

Download files

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

Source Distribution

amzn_selling_partner-0.1.1.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

amzn_selling_partner-0.1.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file amzn_selling_partner-0.1.1.tar.gz.

File metadata

  • Download URL: amzn_selling_partner-0.1.1.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for amzn_selling_partner-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c5d563e116db88b344282ee113b92a79928f366c5e3c64c35a573b875455b152
MD5 d4387658787fc37580dbdadc2623559f
BLAKE2b-256 a9bb0e2bf7fc4e4a0c9131d104b5a4b0bcd46943366db00d0bb4f51fc28b6bef

See more details on using hashes here.

Provenance

The following attestation bundles were made for amzn_selling_partner-0.1.1.tar.gz:

Publisher: publish.yml on dbritto-dev/amzn-selling-partner-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file amzn_selling_partner-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for amzn_selling_partner-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 41eb9dfc5b65b9e556a51fce5e7b15802dc753ff42139555f0238e5b295275ca
MD5 14325301c908da7428ed6d42353476ea
BLAKE2b-256 10162da221622fd824de72d2c336cba8a5667928e656958f2ccbe73ed0af3ef1

See more details on using hashes here.

Provenance

The following attestation bundles were made for amzn_selling_partner-0.1.1-py3-none-any.whl:

Publisher: publish.yml on dbritto-dev/amzn-selling-partner-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

This release

0.1.1 This release

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