Skip to main content

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.

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 (e.g. ==4.8.*, not ==4.8.0) to ensure you always get the latest stable release.

Basic Usage

You'll use AmazonSession to authenticate your Amazon account, then AmazonOrders, AmazonTransactions, and AmazonGiftCards 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

Output Formats

The history, order, transactions, order-transactions, and gift-card-activity commands accept --output, which renders Orders, Transactions, and Gift Card activity as text (the default), json, yaml, or csv. Progress messages are written to stderr, so redirecting stdout captures only the data.

amazon-orders history --year 2023 --output json > orders.json
amazon-orders history --last-30-days --output csv > orders.csv

To serialize from Python instead, every entity has to_dict(), which converts it and its nested entities to a dict of primitives.

import json

from amazonorders.orders import AmazonOrders

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

# [{"order_number": "112-9685975-5907428", "grand_total": 35.98, ...}]
print(json.dumps([order.to_dict() for order in orders], indent=2))

See OutputFormatter for each format's contract, and to override how entities are rendered.

Secure Sign-In

The most secure way to use amazon-orders is to sign in on Amazon's own page, in a browser window, so amazon-orders never needs to store your credentials:

amazon-orders login --browser

The session is persisted, so neither the CLI nor the Python API needs credentials:

from amazonorders.session import AmazonSession

amazon_session = AmazonSession()
amazon_session.login()

This requires a display and the browser extra (see Browser Automation to install it).

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 otp_secret_key)

Languages and Regions

amazon-orders core supports the English .com site.

  • Other English sites (e.g. amazon.ca, amazon.co.uk): set the domain config option.
  • Other languages: install a language package and set language_package. See Language Packages.

Documentation

For more advanced usage, amazon-orders's official documentation is available at Read the Docs, including handling login challenges (AWS WAF and JavaScript checks, with optional extras) and troubleshooting.

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!

Metadata

Release files for amazon-orders 4.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for amazon-orders 4.8.1
File Size Uploaded
amazon_orders-4.8.1.tar.gz 83.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for amazon-orders 4.8.1
File Interpreter ABI Platform
amazon_orders-4.8.1-py3-none-any.whl Python 3 none any Details

Total release size: 170.2 kB

Release files / amazon_orders-4.8.1.tar.gz

Download URL amazon_orders-4.8.1.tar.gz
Size 83.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3f320555338e84ad90eba59bd68e2e00b81213d09d6114d9148ffdd50966f860
BLAKE2b-256 checksum
How to use checksums
6dcad532d80c9285d2d37ead79d619612e8c3a36eb48292e582ea4704736995e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / amazon_orders-4.8.1-py3-none-any.whl

Download URL amazon_orders-4.8.1-py3-none-any.whl
Size 86.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83ab703a509f921af51da60eef6c26db3c2eef0961a6604e352931519756b674
BLAKE2b-256 checksum
How to use checksums
de32c54f2ec2143f370a617b21469abea91f7ecf8b1557e63a121a9e3ea46140
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release history Release notifications | RSS feed

4.9.2

2 release files

4.9.1

2 release files

4.9.0

2 release files

This release

4.8.1 This release

2 release files

4.8.0

2 release files

4.7.1

2 release files

4.7.0

2 release files

4.6.1

2 release files

4.6.0

2 release files

4.5.0

2 release files

4.4.7

2 release files

4.4.6

2 release files

4.4.5

2 release files

4.4.4

2 release files

4.4.3

2 release files

4.4.2

2 release files

4.4.1

2 release files

4.4.0

2 release files

4.3.1

2 release files

4.3.0

2 release files

4.2.2

2 release files

4.2.1

2 release files

4.2.0

2 release files

4.1.0

2 release files

4.0.19

2 release files

4.0.17

2 release files

4.0.14

2 release files

4.0.13

2 release files

4.0.12

2 release files

4.0.11

2 release files

4.0.10

2 release files

4.0.9

2 release files

4.0.8

2 release files

4.0.7

2 release files

4.0.6

2 release files

4.0.5

2 release files

4.0.4

2 release files

4.0.3

2 release files

4.0.2

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.2.19

2 release files

3.2.18

2 release files

3.2.17

2 release files

3.2.12

2 release files

3.2.11

2 release files

3.2.10

2 release files

3.2.9

2 release files

3.2.8

2 release files

3.2.7

2 release files

3.2.6

2 release files

3.2.5

2 release files

3.2.4

2 release files

3.2.3

2 release files

3.2.2

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.16

2 release files

1.0.14

2 release files

1.0.13

2 release files

1.0.12

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page