This project is a Flask-based REST API for managing inventory in a retail system. It allows users to perform full CRUD operations on products and integrates with the OpenFoodFacts API to fetch real-world product data using barcodes.
The system also includes a CLI (Command Line Interface) for user interaction and a testing suite to validate functionality.
- Add new items
- View all inventory items
- View a single item by ID
- Update item price and stock
- Delete items
-
Fetch product details using barcode
-
Retrieve:
- Product name
- Brand
- Ingredients
- User-friendly terminal menu
- Perform all operations without a browser
-
Unit tests using
pytest -
Covers:
- API endpoints
- CRUD operations
- External API route
- Python 3
- Flask
- Requests
- Pytest
inventory-api/
│
├── app.py # Main Flask API
├── inventory.py # In-memory database (list)
├── cli.py # Command-line interface
├── test_app.py # Unit tests
├── requirements.txt # Dependencies
└── README.md # Documentation
git clone https://github.com/YOUR_USERNAME/inventory-api.git
cd inventory-apipython3 -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windowspip install -r requirements.txtpython app.pyServer runs at:
http://127.0.0.1:5000/
| Method | Endpoint | Description |
|---|---|---|
| GET | /inventory | Get all items |
| GET | /inventory/ | Get one item |
| POST | /inventory | Add item |
| PATCH | /inventory/ | Update item |
| DELETE | /inventory/ | Delete item |
| GET | /fetch/ | Fetch product from API |
Open:
http://127.0.0.1:5000/inventory
http://127.0.0.1:5000/fetch/737628064502
Run:
python cli.pyYou can:
- Add items
- View inventory
- Update items
- Delete items
- Fetch product data
Run:
pytestExpected output:
6 passed
- The inventory is stored in memory (resets when server restarts)
- External API may fail depending on network environment
- Error handling is implemented for API failures
- Persistent database (SQLite/PostgreSQL)
- Web frontend (React)
- Authentication system
- Auto-save fetched products into inventory
Samantha Bora