A small command-line Python application that processes a folder of receipt images and uses the OpenAI API to extract structured information such as date, total amount, vendor, and category.
The program outputs a single JSON dictionary mapping each receipt filename to its extracted fields.
lab_1_repo/
├── src/
│ └── receipt_app/
│ ├── __init__.py
│ ├── main.py
│ ├── gpt.py
│ └── file_io.py
├── receipts/
│ └── sample receipt images
├── pyproject.toml
├── Makefile
└── README.md
- Python 3.10+
- An OpenAI API key
- Conda or virtualenv recommended
-
Create and activate your environment (conda or venv).
-
Install the project and dependencies:
pip install -e .- Set your OpenAI API key:
set OPENAI_API_KEY=YOUR_API_KEY_HEREexport OPENAI_API_KEY=YOUR_API_KEY_HERERun the application on a folder of receipt images:
python -m receipt_app.main receipts --printIf you added the console script entry point:
receipt-app receiptsThe program prints JSON output to stdout.
Example:
{
"receipt_1.jpg": {
"date": "2024-01-12",
"vendor": "Walmart",
"amount": 23.45,
"category": "groceries"
}
}If a field cannot be determined, the value will be null.
The --plot option generates a pie chart saved to expenses_by_category.png.
Readability choices:
- Start angle set to 90° so slices begin at the top.
- Categories sorted by total spent (largest first).
- The largest slice is slightly separated (“explode”) to draw attention.
- A legend is placed outside the pie to avoid cluttering labels on the chart.
- Receipt images are not included in version control.
- This project uses the OpenAI API and requires internet access.
- The codebase follows a standard
src/Python package layout.
MIT License