Skip to main content

A Python library (and CLI) for Amazon order history

Project description

amazon-orders - A Python library (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, line items, and transactions.

Only the English, .com version of Amazon is officially supported. Other Amazon domains can be targeted by passing domain to AmazonSession (or --domain on the CLI), and other English-based sites may work by chance — see Known Limitations for details.

Note: 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, older versions of this package may break at any time, so it's recommended that you use the latest version.

Installation

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

pip install amazon-orders --upgrade

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

If pinning, be sure to use a wildcard for the minor version (ex. ==4.3.*, not ==4.2.1) to ensure you always get the latest stable release.

Basic Usage

You'll use AmazonSession to authenticate your Amazon account, then AmazonOrders and AmazonTransactions to interact with account data. 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)

# Get orders from a specific year
orders = amazon_orders.get_order_history(year=2023)

# Or use time filters for recent orders
orders = amazon_orders.get_order_history(time_filter="last30")  # Last 30 days
orders = amazon_orders.get_order_history(time_filter="months-3")  # Past 3 months

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

If the fields you're looking for aren't populated with the above, set full_details=True (or pass --full-details to the history CLI command), since by default it is False (enabling it slows down querying, since an additional request for each order is necessary). Have a look at the Order entity's docs to see what fields are only populated with full details.

Command Line Usage

You can also run any command available to the main Python interface from the command line:

amazon-orders login
amazon-orders history --year 2023
amazon-orders history --last-30-days
amazon-orders history --last-3-months

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)

To enable WAF auto-solve via a third-party integration, install with the relevant extra:

pip install amazon-orders[capsolver]
pip install amazon-orders[anticaptcha]
pip install amazon-orders[2captcha]

See Solving WAF Challenges for details.

To enable browser-based challenge handling (ACIC and JavaScript bot-detection pages) via a headless browser, install with the browser extra:

pip install amazon-orders[browser]
playwright install chromium

See Browser Automation for details.

For legacy Captcha auto-solve on Python <=3.12, install with captcha extra:

pip install amazon-orders[captcha]

See Login Challenges for details.

Documentation

For more advanced usage, amazon-orders's official documentation is available at Read the Docs.

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!

Project details


Release history Release notifications | RSS feed

This version

4.3.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

amazon_orders-4.3.1.tar.gz (56.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

amazon_orders-4.3.1-py3-none-any.whl (58.8 kB view details)

Uploaded Python 3

File details

Details for the file amazon_orders-4.3.1.tar.gz.

File metadata

  • Download URL: amazon_orders-4.3.1.tar.gz
  • Upload date:
  • Size: 56.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for amazon_orders-4.3.1.tar.gz
Algorithm Hash digest
SHA256 49c6652f6a66278357519e446ecdca6876d30b78c6580d3737edbbee70830abd
MD5 ac2eae2a9730da68b497964927dc607d
BLAKE2b-256 0e018f44fd556296e70dc06a7e14c7407b8a34ab4afcca77aa3b3cbf5715fa2c

See more details on using hashes here.

File details

Details for the file amazon_orders-4.3.1-py3-none-any.whl.

File metadata

  • Download URL: amazon_orders-4.3.1-py3-none-any.whl
  • Upload date:
  • Size: 58.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for amazon_orders-4.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 47a9098dabb2975e76f48cfa37d39b8fea34ad5ce0e04354bfbd56141c86a405
MD5 f4261065e14eac7058e880a642e3d35f
BLAKE2b-256 09691f8de8136ff5c1c74ab0ad53120254eee92c1b30e6821c6677639690e92b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page