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())
Credentials by params:
Pass a dict like below to the client:
credentials=dict(
refresh_token='<refresh_token>',
lwa_app_id='<lwa_app_id>',
lwa_client_secret='<lwa_client_secret>',
aws_secret_key='<aws_secret_access_key>',
aws_access_key='<aws_access_key_id>',
role_arn='<role_arn>',
)
Orders(credentials=credentials).get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())
The refresh token can be passed directly to the client, too. You don't need to pass the whole credentials if all that changes is the refresh token.
Credentials are looked up in the following order:
- Credential dict
- Env variables
- Config File
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
Built Distribution
Hashes for python-amazon-sp-api-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2adb156024c3193b0b0a7d54b4f3016d562f836578a72a7303fb4e9b17f39cc5 |
|
MD5 | 5e0b01bff17eb00cfa17e2ab87c2d711 |
|
BLAKE2b-256 | 7669484dde898542cde172a01de3f8050596ddb598df4a1af409ab885e5c4e60 |
Hashes for python_amazon_sp_api-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea905dee206035e8660d9188cbfdfa9ceac34f99c4a7f035e870d2ab74ae7807 |
|
MD5 | 6eee42404c1d1a224621aabd9c81cfc6 |
|
BLAKE2b-256 | 9a38e1026afc8f71c9a7e8f5679403a55864cec13ede47aff15815ac386771c8 |