A comprehensive collection of FastAPI applications demonstrating modern web API development, including an e-commerce product management system and a machine learning-powered car price prediction API.
A full-featured e-commerce product management API with CRUD operations, advanced validation, and business logic.
Key Features:
- Complete product CRUD operations
- Advanced filtering, sorting, and pagination
- Pydantic-based data validation with business rules
- JSON file-based persistence
- Comprehensive error handling
- Automatic API documentation
Machine learning API for predicting used car prices using Random Forest regression, with both REST API and Streamlit web interface.
Key Features:
- ML model serving via REST API
- Streamlit web application for user interaction
- One-hot encoding for categorical features
- CORS-enabled for web integration
- Pre-trained model with Cardekho dataset
FastAPI project/
├── FastAPI/
│ └── fastapi-ecommerce/
│ ├── requirements.txt
│ └── app/
│ ├── main.py # Main FastAPI application
│ ├── schema/
│ │ └── product.py # Pydantic models
│ ├── service/
│ │ └── products.py # Business logic
│ └── data/
│ └── products.json # Sample product data
├── model/
│ └── car-price-api/
│ ├── main.py # FastAPI app
│ ├── schema.py # Pydantic models
│ ├── model.py # ML prediction logic
│ ├── streamlit_app.py # Web UI
│ ├── train.py # Model training
│ ├── requirements.txt
│ ├── random_forest_model.pkl # Trained model
│ ├── feature_columns.pkl # Feature metadata
│ └── cardekho_data (1).csv # Training data
└── README.md
- Python 3.8+
- pip package manager
cd FastAPI/fastapi-ecommerce
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install fastapi uvicorn pydantic python-dotenv
# Run the application
uvicorn app.main:app --reloadcd model/car-price-api
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run the API
uvicorn main:app --reload
# Run the Streamlit app (in another terminal)
streamlit run streamlit_app.pyGET /- API root with health checkGET /products- List products with filtering options- Query parameters:
name,sort_by_price,order,limit,offset
- Query parameters:
GET /products/{product_id}- Get specific productPOST /products- Create new productPUT /products/{product_id}- Update productDELETE /products/{product_id}- Delete product
Get all products:
curl http://localhost:8000/productsCreate a product:
curl -X POST "http://localhost:8000/products" \
-H "Content-Type: application/json" \
-d '{
"sku": "TEST-001-001",
"name": "Test Product",
"description": "A test product",
"category": "electronics",
"brand": "TestBrand",
"price": 100.0,
"stock": 10,
"is_active": true,
"rating": 4.5,
"image_urls": ["https://example.com/image.jpg"],
"dimensions_cm": {"length": 10, "width": 5, "height": 2},
"seller": {
"id": "123e4567-e89b-12d3-a456-426614174000",
"name": "Test Seller",
"email": "test@teststore.in",
"website": "https://teststore.in"
}
}'GET /- Health checkPOST /predict- Predict car price
curl -X POST "http://localhost:8000/predict" \
-H "Content-Type: application/json" \
-d '{
"Car_Name": "swift",
"Year": 2014,
"Present_Price": 5.59,
"Kms_Driven": 27000,
"Fuel_Type": "Petrol",
"Seller_Type": "Dealer",
"Transmission": "Manual",
"Owner": 0
}'- Data Validation: SKU format, email domains, business rules
- Business Logic: Stock management, discount validation
- Computed Fields: Final price calculation, volume computation
- Error Handling: Comprehensive HTTP exceptions
- Filtering: Name search, price sorting, pagination
- ML Model: Random Forest regression
- Preprocessing: Automatic one-hot encoding
- Feature Engineering: Categorical variable handling
- Web Interface: Streamlit-based user interface
# For ecommerce API
cd FastAPI/fastapi-ecommerce
python -m pytest
# For car price API
cd model/car-price-api
python -m pytest- Ecommerce API: http://localhost:8000/docs
- Car Price API: http://localhost:8000/docs
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is released for research and educational use.
Built with:
- FastAPI - Modern Python web framework
- Pydantic - Data validation
- scikit-learn - Machine learning
- Streamlit - Web app framework