pymws package

pymws

class pymws.pymws.MWS(marketplace, merchant_id=None, access_key_id=None, secret_key=None, auth_token=None)[source]

Primary client class that acts as a gateway to all of the functionality offered by this package.

Example usage:

client = MWS(
    marketplace="US", merchant_id="1234",
    access_key_id="key", secret_key="secret",
    auth_token="token"
)
client.reports.get_reports_list()
Parameters:
  • marketplace – marketplace to connect to.
  • merchant_id – Amazon merchant it.
  • access_key_id – Access key of your app
  • secret_key – Secret key of your app
  • auth_token – Token obtained by the merchant after installing your app.
orders

Fetch the order API client Returns an instance of pymws.orders.Orders

products

Fetch the products API client. Returns an instance of pymws.products.Products

reports

Fetch the reports API client Returns an instance of pymws.reports.Reports

orders

class pymws.orders.Orders(client)[source]

Implements an order API client for Amazon MWS

response = client.orders.list_orders(CreatedAfter=start_date)
for order in response.Orders.getchildren():
    print(order.AmazonOrderId)

for other attributes of the order, refer to the Amazon MWS documentation.

To fetch the next page of orders:

response = client.orders.list_orders(CreatedAfter=start_date)
page2 = client.orders.list_orders_by_next_token(
    response.NextToken
)
get_order(AmazonOrderId)[source]

Returns orders based on the AmazonOrderId values that you specify.

Learn more

get_service_status()[source]

Returns the operational status of the Orders API section.

Learn more

list_order_items(AmazonOrderId)[source]

Returns order items based on the AmazonOrderId that you specify.

Learn more

list_order_items_by_next_token(NextToken)[source]

Returns the next page of order items using the NextToken parameter.

Learn more

list_orders(**kwargs)[source]

Returns orders created or updated during a time frame that you specify.

Learn more

list_orders_by_next_token(NextToken)[source]

Returns the next page of orders using the NextToken parameter.

Learn more

The NextToken argument is not very pythonic, but keeps the package user side code consistent with Amazon’s documentation and avoids a surprise for the user.

product

fulfillment

class pymws.fulfillment.outbound_shipment.OutboundShipment(client)[source]

Implements outbound shipment client for Amazon MWS

client.fulfillment_outbound_shipment.create_fulfillment_order(
    MarketplaceId='A2Q3Y263D00KWC',
    SellerFulfillmentOrderId='SO3421',
    FulfillmentAction='Ship',
    DisplayableOrderId='SO3421',
    DisplayableOrderDateTime=datetime.utcnow(),
    DisplayableOrderComment='Some comment',
    ShippingSpeedCategory='Standard',
    DestinationAddress={
        'Name': 'John Doe',
        'Line1': 'Random street',
        'StateOrProvinceCode': 'CA',
        'CountryCode': 'US',
    },
    Items=[{
        'SellerSKU': 'SKU-1',
        'SellerFulfillmentOrderItemId': 'SO3421-1',
        'Quantity': 1,
    }],
)

for other attributes refer to the Amazon MWS documentation.

create_fulfillment_order(**kwargs)[source]

Requests that Amazon ship items from the seller’s inventory in Amazon’s fulfillment network to a destination address.

Learn more

get_fulfillment_order(SellerFulfillmentOrderId)[source]

Returns a fulfillment order based on a specified SellerFulfillmentOrderId.

Learn more

reports

class pymws.reports.Reports(client)[source]

Implements a report client for Amazon MWS.

The report API works differently from other APIs and it is important to have a good understanding of how this API works from MWS reports overview

cancel_report_request(**kwargs)[source]

Cancels one or more report requests.

Learn more

get_report(ReportId)[source]

Returns the contents of a report and the Content-MD5 header for the returned report body.

Learn more

get_report_count(**kwargs)[source]

Returns a count of the reports, created in the previous 90 days, with a status of _DONE_ and that are available for download.

Learn more

get_report_list(**kwargs)[source]

Returns a list of reports that were created in the previous 90 days.

Learn more

get_report_list_by_next_token(NextToken)[source]

Returns a list of reports using the NextToken, which was supplied by a previous request to either GetReportListByNextToken or GetReportList, where the value of HasNext was true in the previous call.

Learn more

get_report_request_count(**kwargs)[source]

Returns a count of report requests that have been submitted to Amazon MWS for processing.

Learn more

get_report_request_list(**kwargs)[source]

Returns a list of report requests that you can use to get the ReportRequestId for a report.

Learn more

get_report_request_list_by_next_token(NextToken)[source]

Returns a list of report requests using the NextToken, which was supplied by a previous request to either GetReportRequestListByNextToken or GetReportRequestList, where the value of HasNext was true in that previous request.

Learn more

request_report(**kwargs)[source]

Creates a report request and submits the request to Amazon MWS.

Amazon MWS processes the report request and when the report is completed, sets the status of the report request to _DONE_. Reports are retained for 90 days.

Learn more

exceptions

All errors and exceptions

exception pymws.exceptions.AccessDenied[source]

Bases: pymws.exceptions.MWSError

Access was denied

exception pymws.exceptions.MWSError[source]

Bases: pymws.exceptions.MWSException

Parent class of all Amazon returned Errors.

exception pymws.exceptions.MWSException[source]

Bases: Exception

Parent class of all exceptions this package handles

exception pymws.exceptions.QuotaExceeded[source]

Bases: pymws.exceptions.MWSError

The total number of requests in an hour was exceeded.

exception pymws.exceptions.RequestThrottled[source]

Bases: pymws.exceptions.MWSError

The frequency of requests was greater than allowed..

exception pymws.exceptions.SignatureDoesNotMatch[source]

Bases: pymws.exceptions.MWSError

The signature used does not match the server’s calculated signature value.

utils

pymws.utils.MARKETPLACES = [Marketplace(code='BR', currency='BRL', id='A2Q3Y263D00KWC', endpoint='https://mws.amazonservices.com', name='Amazon.com.br'), Marketplace(code='CA', currency='CAD', id='A2EUQ1WTGCTBG2', endpoint='https://mws.amazonservices.ca', name='Amazon.ca'), Marketplace(code='MX', currency='MXN', id='A1AM78C64UM0Y8', endpoint='https://mws.amazonservices.com.mx', name='Amazon.com.mx'), Marketplace(code='US', currency='USD', id='ATVPDKIKX0DER', endpoint='https://mws.amazonservices.com', name='Amazon.com'), Marketplace(code='AE', currency='AED', id='A2VIGQ35RCS4UG', endpoint='https://mws.amazonservices.ae', name='United Arab Emirates (U.A.E.)'), Marketplace(code='DE', currency='EUR', id='A1PA6795UKMFR9', endpoint='https://mws-eu.amazonservices.com', name='Amazon.de'), Marketplace(code='EG', currency='EGP', id='ARBP9OOSHTCHU', endpoint='https://mws-eu.amazonservices.com', name='Egypt'), Marketplace(code='ES', currency='EUR', id='A1RKKUPIHCS9HS', endpoint='https://mws-eu.amazonservices.com', name='Amazon.es'), Marketplace(code='FR', currency='EUR', id='A13V1IB3VIYZZH', endpoint='https://mws-eu.amazonservices.com', name='Amazon.fr'), Marketplace(code='GB', currency='GBP', id='A1F83G8C2ARO7P', endpoint='https://mws-eu.amazonservices.com', name='Amazon.co.uk'), Marketplace(code='IN', currency='INR', id='A21TJRUUN4KGV', endpoint='https://mws.amazonservices.in', name='Amazon.in'), Marketplace(code='IT', currency='EUR', id='APJ6JRA9NG5V4', endpoint='https://mws-eu.amazonservices.com', name='Amazon.it'), Marketplace(code='NL', currency='EUR', id='A1805IZSGTT6HS', endpoint='https://mws-eu.amazonservices.com', name='Amazon.nl'), Marketplace(code='SA', currency='SAR', id='A17E79C6D8DWNP', endpoint='https://mws-eu.amazonservices.com', name='Saudi Arabia'), Marketplace(code='TR', currency='EUR', id='A33AVAJ2PDY3EV', endpoint='https://mws-eu.amazonservices.com', name='Turkey'), Marketplace(code='SG', currency='SGD', id='A19VAU5U5O7RUS', endpoint='https://mws-fe.amazonservices.com', name='Amazon.sg'), Marketplace(code='AU', currency='AUD', id='A39IBJ37TRP1C6', endpoint='https://mws.amazonservices.com.au', name='Amazon.com.au'), Marketplace(code='JP', currency='JPY', id='A1VC38T7YXB528', endpoint='https://mws.amazonservices.jp', name='Amazon.jp')]

A list of Marketplaces

class pymws.utils.Marketplace(code, currency, id, endpoint, name)
code

Alias for field number 0

currency

Alias for field number 1

endpoint

Alias for field number 3

id

Alias for field number 2

name

Alias for field number 4

pymws.utils.flatten_dict(kwargs, key)[source]

Convert a dict into URL parameters the way amazon like it.

Example:

flatten_dict(
    {'DestinationAddress': {'Name': 'John', 'Country': 'US'}},
    'DestinationAddress',
)

Becomes:

DestinationAddress.Name=John&DestinationAddress.Country=US
pymws.utils.flatten_list(kwargs, key, separator)[source]

Convert a list into URL parameters the way amazon like it.

Example:

flatten_list(
    {'ReportTypeList': ['_A_', '_B_']},
    'ReportTypeList',
    'Type'
)

Becomes:

ReportTypeList.Type.1=_A_&ReportTypeList.Type.2=_B_
pymws.utils.get_marketplace(id_or_code)[source]

Given a code, get the marketplace

pymws.utils.parse_xsv(text)[source]

Python 2 and 3 compatible (X)SV - CSV/TSV parser that returns a list of dictionary objects.