This project contains scripts to fetch and analyze Costco receipt data using the Costco API. Note that you need to log in to costco.com manually and look at the network requests to get the bearer token, the client ID, and the client identifier.
-
Install dependencies:
uv sync
-
Set up environment variables:
cp .env.example .env
Then edit
.envand add your actual Costco API credentials. You can get these by looking at the network requests in your browser when you're logged in to costco.com and looking at the headers in the graphql requests.COSTCO_BEARER_TOKEN- Your bearer tokenCOSTCO_CLIENT_ID- Your client IDCOSTCO_CLIENT_IDENTIFIER- Your client identifier
fetch_receipts.py- Fetches receipt lists for date rangesfetch_receipt_details.py- Fetches detailed receipt information by barcodefetch_all_receipt_details.py- Batch fetches detailed receipts for all barcodes found in data files
COSTCO_BEARER_TOKEN- Your Costco API bearer tokenCOSTCO_CLIENT_ID- Your Costco API client IDCOSTCO_CLIENT_IDENTIFIER- Your Costco API client identifier
All scripts will automatically load the required credentials from your .env file. Make sure to set up all the environment variables before running any scripts.
python fetch_receipts.py
python fetch_all_receipt_details.pyUse the generate_csv_file.py script to flatten all downloaded receipt JSON into two CSVs at the repo root:
python generate_csv_file.pycostco-items.csv— one row per line item withtransaction_date,transaction_barcode,warehouse_name,transaction_type,item_number,description,description2,combined_description,item_department_number,item_unit_price,item_amount,item_quantity.costco-receipts.csv— one row per receipt withtransaction_date,transaction_barcode,warehouse_name,transaction_type,subtotal,taxes,total,instant_savings,total_item_count.
The queries used by the script live in generate_csv_file.py (ITEMS_QUERY and RECEIPTS_QUERY). They read directly from data/receipts/*.json via DuckDB's read_json_auto.
index.html is a self-contained ECharts dashboard that consumes both CSVs. Serve the directory locally and open it:
python -m http.server 8000
# then open http://localhost:8000/index.htmlThree tabs:
- Item Trends — original price-over-time chart and data table, grouped by
item_number(descriptions are shown as the latest seen for each item). - Price Index — personal Costco price index. Items bought 4+ times are normalized to 100 at their baseline (avg of first 2 purchases); the chart plots the monthly mean across qualified items. Includes a "biggest movers" table.
- Departments — monthly stacked spend chart for the top 10 departments, plus a lifetime spend table showing the top items in each department.