python wrapper for amazon selling partner api
Project description
PYTHON-AMAZON-SP-API
Amazon Selling-Partner API
Contributions very welcome!
Installation
pip install python-amazon-sp-api
Usage
# orders API
try:
res = Orders().get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())
print(res.payload) # json data
except SellingApiException as ex:
print(ex)
# report request
createReportResponse = Reports().create_report(reportType='GET_FLAT_FILE_OPEN_LISTINGS_DATA')
# submit feed
# feeds can be submitted like explained in Amazon's docs, or simply by calling submit_feed
Feeds().submit_feed(self, <feed_type>, <file_or_bytes_io>, content_type='text/tsv', **kwargs)
Credential configuration
You can set the required credentials via a config file, or with environment variables. An example config file is provided in this repository, it supports multiple accounts. The programm looks for a file called credentials.yml
The config is parsed by confused, see their docs for more in depth information. Search paths are:
- macOS: ~/.config/python-sp-api
- Other Unix: ~/.config/python-sp-api
- Windows: %APPDATA%\python-sp-api where the APPDATA environment variable falls back to %HOME%\AppData\Roaming if undefined
version: '1.0'
default:
refresh_token: ''
lwa_app_id: ''
lwa_client_secret: ''
aws_secret_key: ''
aws_access_key: ''
role_arn: ''
another_account:
refresh_token: ''
lwa_app_id: ''
lwa_client_secret: ''
aws_secret_key: ''
aws_access_key: ''
role_arn: ''
If no account is passed to the client, default will be used.
# use default
Orders().get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())
# use 'another_account'
Orders(account='another_account').get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())
If you prefer to set environment variables, the following have to be set:
ENVIRONMENT VARIABLE | DESCRIPTION |
---|---|
SP_API_REFRESH_TOKEN | The refresh token used obtained via authorization (can be passed to the client instead) |
LWA_APP_ID | Your login with amazon app id |
LWA_CLIENT_SECRET | Your login with amazon client secret |
SP_API_SECRET_KEY | AWS USER SECRET KEY |
SP_API_ACCESS_KEY | AWS USER ACCESS KEY |
SP_API_ROLE_ARN | The role's arn (needs permission to "Assume Role" STS) |
You can (but don't have to) suffix each of these variables with _<account>
if you want to set multiple accounts via env variables.
# use default, with or without suffix
Orders().get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())
# use 'ANOTHER_ACCOUNT', e.g. SP_API_REFRESH_TOKEN_ANOTHER_ACCOUNT
Orders(account='ANOTHER_ACCOUNT').get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())
DISCLAIMER
We are not affiliated with Amazon
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python-amazon-sp-api-0.1.1.tar.gz
(135.1 kB
view hashes)
Built Distribution
Close
Hashes for python-amazon-sp-api-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3c6706f56b61aad55363dbe33aa027dbb0c8eacdd026fb7c1108b4e642305b1 |
|
MD5 | 4720caa034e985a40a1f867c3e4cf0f5 |
|
BLAKE2b-256 | 1cf1f89e98668feb03abb8fc9ef3131d97ef7148d4275ead32f1ebd6e82cfbfe |
Close
Hashes for python_amazon_sp_api-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1399d965e567bb437e4cceaa28df5e958d03147e1dec861f61eeecc99bc31394 |
|
MD5 | a972ad452f4154a24a163c4613ad425a |
|
BLAKE2b-256 | 26133fa7dc9b7ee462cf3f6d5dc6709dbd9e5d580d2ecb4344c988a4c0188720 |