FitMart Product API & Inventory Report Generator This project provides two key functionalities:
A FastAPI-based REST API to serve product data from an Excel sheet.
A Django-integrated inventory report generator that exports styled Excel reports from a PostgreSQL database.
π§ Tech Stack Python 3.x FastAPI Pandas OpenPyXL Pillow PostgreSQL Django (for database access) Uvicorn (for running FastAPI server)
π File Structure bash Copy Edit βββ sample.py # FastAPI backend to serve Excel product data βββ report2.py # Generates formatted inventory Excel reports βββ Product data.xlsx # Sample product data file (used by sample.py) βββ logo.png # Logo used in the Excel report βββ report.xlsx # Auto-generated styled inventory report π 1. FastAPI Product API (sample.py) π Description Serves product data from an Excel file (Product data.xlsx) through a REST API at /products/.
π¦ How to Run pip install fastapi uvicorn pandas openpyxl pillow uvicorn sample:app --reload
π API Endpoint GET /products/: Returns a JSON array of product objects with:
Name Brand Category Price Discount Stock Quantity Size
π 2. Inventory Report Generator (report2.py) π Description Fetches product data from a PostgreSQL database via Django ORM and exports a fully formatted Excel report (report.xlsx) with a logo, summary stats, and product listings.
βοΈ Prerequisites Django project set up with a products app and Product model. PostgreSQL database with valid credentials.
π¦ How to Run
pip install openpyxl pillow pandas psycopg2 django
python report2.py
β Output report.xlsx β Includes:
Logo Title and date Total number of products and categories Product table with ID, Name, Quantity, and Price Styled headers, borders, and column widths
π Configuration Notes Update the PostgreSQL connection credentials in report2.py:
conn_params = { 'host': 'localhost', 'database': 'fitmart_db', 'user': 'postgres', 'password': 'your_password', } Ensure your Django settings and model paths are correctly defined for importing.
πΈ Sample Preview A screenshot or sample of report.xlsx would go here.
β¨ Future Improvements Add authentication to the API
Upload new products via API
Automate daily report generation with cron or Django management command
Deploy the FastAPI service
π License This project uses open-source components and is licensed under the MIT License.