This is a car insurance simulator developed with FastAPI. It calculates insurance quotes based on provided input data.
- Python 3.12
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/gnutzmann/car_insurance_simulator.git cd car_insurance_simulator -
Create and activate a virtual environment:
python3 -m venv .venv source .venv/bin/activate -
Install the dependencies:
pip install -r requirements.txt
-
Create a .env file with the necessary environment variables:
AGE_RATE_INCREMENT = 0.005 BROKER_FEE = 50.0 DEDUCTIBLE_PERCENTAGE = 0.1 VALUE_RATE_INCREMENT = 0.005 COVERAGE_PERCENTAGE = 1.0
-
Run the application:
python3 app/main.py
-
Access the application at http://localhost:5000.
-
Build and start the containers:
docker-compose up --build
-
Access the application at http://localhost:5000.
-
URL:
/insurance/quote -
Method:
POST -
Request Body:
{ "car": { "make": "Toyota", "model": "Corolla", "year": 2015, "value": 100000 }, "deductible_percentage": 0.1, "broker_fee": 50.0 } -
Response Body:
{ "car": { "make": "Toyota", "model": "Corolla", "value": 100000.0, "year": 2015 }, "applied_rate": 0.1, "policy_limit": 90000.0, "calculated_premium": 9050.0, "deductible_value": 10000.0 }
A Postman collection for testing the API is available in the docs folder.
app/main.py: Application entry point.app/services/insurance_calculation_service.py: Premium calculation service.app/models/insurance_quote_input.py: Input model for insurance quote.app/models/insurance_quote_output.py: Output model for insurance quote.app/base/config.py: Application settings.