Convert Amazon order history to credit card-like transactions
Project description
Convert exported Amazon order and return history into something close to credit card transactions.
Why
To better track my finances, I wanted to identify which Amazon orders / products each of my credit card transactions corresponded to so I could categorize the transactions and figure out where my spending is going.
Amazon has a transactions page, but it does not allow navigating directly to specific time periods, instead requiring you to hit the 'Next' page button as many times as needed to go back in time. Worse, you cannot link to transactions pages as they do not modify the URL, so if you lose your place (or Amazon gives the dreaded "you have no transactions" error) and you have to start all over again.
There are other tools like the Chrome extension Amazon Order History Reporter (Azad) which can export your order history by scraping Amazon pages, but I found them all to output lots of missing data to the point of being nearly unusable. To be fair, Amazon order history and transacions pages are an ever moving target.
Working directly with official Amazon exported data like this script does is much easier and in principle fully complete. Plus it comes in a convenient CSV format that you may find useful for your own quick lookups and analysis.
I personally use this tool to track my spending with Lunch Money, categorizing Amazon transactions based on what I bought. In the near future I plan to create a tool that makes use of the exported data from this tool to directly update corresponding transactions in Lunch Money since it has an open API.
Quick Start
- Export your Amazon order history (may take an hour or longer): https://www.amazon.com/hz/privacy-central/data-requests/preview.html
- While you wait, install this script using
pipx install .,uv tool install ., or a similar Python app manager. - Once export is complete, download the resulting ZIP file and extract the
Retail.OrderHistory.1.csvandRetail.OrdersReturned.Payments.1.csvfiles, ideally to the same location as the script to avoid specifiying paths. - Run the script, pointing it to your files and desired output filename.
- Done! The output transactions CSV file will not perfectly match you credit card transactions since Amazon sometimes charges one transaction per shipment and other times charges the whole order as one transaction. Hence the reason both transaction amounts (cost of a shipment or refund) and overall order totals are given.
Usage
Order transactions only:
amazon-orders-to-transactions Retail.OrderHistory.1.csv transactions.csv
Orders + returns combined:
amazon-orders-to-transactions Retail.OrderHistory.1.csv transactions.csv --returns Retail.OrdersReturned.Payments.1.csv
Output
The script produces a CSV file with the following columns:
| Column | Description |
|---|---|
| Ship Date | Date when the order shipped (YYYY-MM-DD format). For returns, this is the refund completion date. |
| Order ID | Amazon order identifier that links to the original order |
| Transaction Amount | Total amount charged/refunded for a single shipment/return. Positive values are charges, negative values are refunds. |
| Order Total | Total cost of the entire order (sum of all items for that Order ID). Useful when the whole order was charged to your card as one transaction, rather than one transaction per shipment. |
| Product Names | Semicolon-separated list of product names. Each product name is truncated to 60 characters max for readability. |
| Order URL | Direct link to Amazon order details page |
Transaction Grouping
The script groups individual order items into transactions based on:
- Order ID + Shipment Item Subtotal (to handle partial charges/refunds)
- Items with the same Order ID and subtotal amount are combined into a single transaction row
- Product names from grouped items are concatenated with semicolons
Example Output
Ship Date,Order ID,Transaction Amount,Order Total,Product Names,Order URL
2025-08-10,111-1111111-1111111,-13.99,61.58,Watermelon,https://amazon.com/gp/your-account/order-details?orderID=111-1111111-1111111
2025-08-05,111-1111111-1111111,61.58,61.58,Watermelon; Organic Red Onion,https://amazon.com/gp/your-account/order-details?orderID=111-1111111-1111111
2025-08-04,222-2222222-2222222,25.99,25.99,Wireless Headphones,https://amazon.com/gp/your-account/order-details?orderID=222-2222222-2222222
Note: Returns appear as separate rows with negative Transaction Amount values, but maintain the same Order Total as the original order for context.
Develop
To make development easier, I prefer to install via pipx with the --editable
flag so that all updates to the code automatically reflect in the installed
tool:
pipx install --editable .
To run tests:
uv run -m pytest
Publishing to PyPI
The package is configured for PyPI publication. To publish a new version:
- Update version in
pyproject.toml - Build the package:
uv run python -m build
- Validate the build:
uv run python -m twine check dist/*
- Upload to PyPI:
# Test upload (recommended first) uv run python -m twine upload --repository testpypi dist/* # Production upload uv run python -m twine upload dist/*
Prerequisites:
- PyPI account with API token configured
- Install dev dependencies:
uv sync --group dev
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file amazon_orders_to_transactions-0.2.0.tar.gz.
File metadata
- Download URL: amazon_orders_to_transactions-0.2.0.tar.gz
- Upload date:
- Size: 89.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f4ce5d572152b26a5bbb4d90dd9a76238e214378341eb5797ad250e10322d48
|
|
| MD5 |
7872ce10fdbe1527b954d286611fa78e
|
|
| BLAKE2b-256 |
9e529fe14a4307e6e23787cb2acbe69134c5f021d3af8eaeef380e94d910eb35
|
File details
Details for the file amazon_orders_to_transactions-0.2.0-py3-none-any.whl.
File metadata
- Download URL: amazon_orders_to_transactions-0.2.0-py3-none-any.whl
- Upload date:
- Size: 35.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9cf98fc7c74a77d47e396542828815c05734f3a1e83829e26702a5810dbbda5
|
|
| MD5 |
9587afff23660ce313261a969eff47e4
|
|
| BLAKE2b-256 |
a1ebdb025f13c5cfeb83c7fd03fe441ae45823d3ee26bab3d1861614133e2653
|