Skip to content

alexdlaird/amazon-orders

Repository files navigation

amazon-orders - A Python libray (and CLI) for Amazon order history

Version Python Versions Coverage Build Docs GitHub License

amazon-orders is an unofficial library that provides a Python API (and CLI) for Amazon order history.

This package works by parsing data from Amazon's consumer-facing website. A periodic build validates functionality to ensure its stability, but as Amazon provides no official API to use, this package may break at any time. Pin the minor version with a wildcard (ex. ==4.0.*, not ==4.0.5)—or reinstall with the --upgrade (as shown below) often—to ensure you always get the latest stable release.

This package only officially supports the English, .com version of Amazon.

Installation

amazon-orders is available on PyPI and can be installed using pip:

pip install amazon-orders --upgrade

That's it! amazon-orders is now available as a Python package is available from the command line.

Basic Usage

Execute amazon-orders from the command line with:

amazon-orders --username <AMAZON_EMAIL> --password <AMAZON_PASSWORD> history

Or to use amazon-orders programmatically, get_order_history and get_order are good places to start:

from amazonorders.session import AmazonSession
from amazonorders.orders import AmazonOrders

amazon_session = AmazonSession("<AMAZON_EMAIL>",
                               "<AMAZON_PASSWORD>")
amazon_session.login()

amazon_orders = AmazonOrders(amazon_session)
orders = amazon_orders.get_order_history(year=2023)

for order in orders:
    print(f"{order.order_number} - {order.grand_total}")

If desired fields are populated as None, set full_details=True (or pass --full-details to the history command), since by default it is False (it will slow down querying). Have a look at the Order entity's docs to see what fields are only populated with full details.

Automating Authentication

Authentication can be automated by (in order of precedence) storing credentials in environment variables, passing them to AmazonSession, or storing them in AmazonOrdersConfig. The environment variables amazon-orders looks for are:

  • AMAZON_USERNAME
  • AMAZON_PASSWORD
  • AMAZON_OTP_SECRET_KEY (see docs for usage)

Documentation

For more advanced usage, amazon-orders's official documentation is available at http://amazon-orders.readthedocs.io.

Contributing

If you would like to get involved, be sure to review the Contribution Guide.

Want to contribute financially? If you've found amazon-orders useful, sponsorship would also be greatly appreciated!