amazon-sp-api-python
This is a python version of the Amazon Seller API https://developer-docs.amazon.com/sp-api/docs/
We use the openapi generator https://openapi-generator.tech/ to convert the amazon sp-api swagger api models https://github.com/amzn/selling-partner-api-models.git into a python package.
This creates a requests based API with pydantic types. Awesome!
This project consists of tweaks I had to make to aws auth schemes to get things working with the openapi generator client, the generator script that creates the models and a little bit of documentation. Nothing fancy.
Prerequisites
- python 3.9+
- amazon seller api credentials. See the docs https://developer-docs.amazon.com/sp-api/docs/
Installation
pip install amazon-sp-api-python
Usage
import os
import dotenv
dotenv.load_dotenv()
from py_sp_api.generated.productPricingV0 import ProductPricingApi, SPAPIClient as PricingClient
from py_sp_api.generated.notifications import NotificationsApi, SPAPIClient as NotificationsClient
from py_sp_api import SPAPIConfig
def test_get_pricing(asin: str, marketplace_id="ATVPDKIKX0DER"):
# demonstrates a grantful "refresh_token" request (the default)
spapi_config = SPAPIConfig(
client_id=os.getenv("SPAPI_CLIENT_ID"),
client_secret=os.getenv("SPAPI_CLIENT_SECRET"),
refresh_token=os.getenv("SPAPI_TOKEN"),
region="NA",
)
product_pricing = ProductPricingApi(PricingClient(spapi_config))
response = product_pricing.get_pricing(marketplace_id=marketplace_id, item_type="Asin", asins=[asin])
print("pricing", response)
def test_notifications():
# demomonstrates a grantless request (required for some operations like creating a notification destination)
grantless_config = SPAPIConfig(
client_id=os.getenv("SPAPI_CLIENT_ID"),
client_secret=os.getenv("SPAPI_CLIENT_SECRET"),
refresh_token=os.getenv("SPAPI_TOKEN"),
region="NA",
grant_type="client_credentials",
scope="sellingpartnerapi::notifications",
)
notifications = NotificationsApi(NotificationsClient(grantless_config))
response = notifications.get_destinations()
print("destinations", response)
test_notifications()
test_get_pricing(asin="B0DP7GSWC8")
Development
This is a poetry project so do the normal poetry install type things to set up your environment.
We use a Makefile for build automation.
make cleanremoves the generated codemake generategenerates the schemasmake testruns unit testsmake lint-fixfixes linting issues and checks compliance with linting standards
Project Structure
.
├── Makefile - make scripts
├── README.md - this file
├── notebooks
│ └── api_test.ipynb - example usage
├── poetry.lock
├── pyproject.toml
├── selling-partner-api-models - git submodule from <https://github.com/amzn/selling-partner-api-models.git>
├── scripts
│ └── generate_schemas.py - script to generate api
├── tests - unit tests. (just enough to make sure things generated without error)
└── src
└── py_sp_api
├── auth - copied from selling-partner-api-models/clients/sellingpartner-api-aa-python/auth
│ ├── LwaException.py - unchanged
│ ├── LwaExceptionErrorCode.py - unchanged
│ ├── LwaRequest.py - import paths modified
│ └── credentials.py - tweaked to allow grantless operations
|── base_client.py - client that gets copied into each package in generated/
└── generated - the generated api files created when generate_schemas.py is run
Metadata
Release files for amazon-sp-api-python 0.1.1
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 |
|---|---|---|---|---|
| amazon_sp_api_python-0.1.1.tar.gz | 2.2 MB | Without provenance | Details for amazon_sp_api_python-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| amazon_sp_api_python-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for amazon_sp_api_python-0.1.1-py3-none-any.whl |
Total release size: 7.8 MB
Release files / amazon_sp_api_python-0.1.1.tar.gz
| Download URL | amazon_sp_api_python-0.1.1.tar.gz |
|---|---|
| Size | 2.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
093f3e228ff86cc2cc50f27c534152a842b0d9535c5a2e306344f4c4d1af8c2d
|
|
BLAKE2b-256 checksum How to use checksums |
395b9e81a9984ddc92bb416b604696e5f4a43acc497f8b515b7c20385e28d776
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.11.11 Linux/6.8.0-1017-azure
|
Release files / amazon_sp_api_python-0.1.1-py3-none-any.whl
| Download URL | amazon_sp_api_python-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.6 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e604659f8a4355e531799fc827e71a9c1bd9f2deace6227858e817cedb36cd7d
|
|
BLAKE2b-256 checksum How to use checksums |
0e5f6a3dcdb0739f84dadfad1a664cc97ad928b95117ba0c1a7303f7c93b6679
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.11.11 Linux/6.8.0-1017-azure
|
Security for amazon-sp-api-python 0.1.1
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.