This project is a FastAPI backend service that calculates insurance premiums based on user inputs. The API accepts various parameters related to the insured individual or object and returns a calculated insurance premium.
Clone the repository:
git clone https://github.com/UbeyOzcan/insurance-premium-api.git
cd insurance-premium-api
Create a virtual environment:
python3 -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
Install the dependencies:
pip install -r requirements.txt
navigate to app folder
cd app
Run the FastAPI server:
uvicorn api:app --host 127.0.0.1 --port 8080
The API will be available at http://127.0.0.1:8080
.
The API interactive documentation will be available at http://127.0.0.1:8080/docs
POST /calculate-premium
Calculates the insurance premium based on the provided input data.
Request Body:
{
"power": 20,
"VehAge": 10,
"DrivAge": 30,
"BonusMalus": 10,
"VehGas": "Regular",
"Area": "D"
}
Response:
{
"VehPower": [
20
],
"VehAge": [
10
],
"DrivAge": [
30
],
"BonusMalus": [
10
],
"VehGas": [
"Regular"
],
"Area": [
"D"
],
"Predicted Frequency": [
0.0269
],
"Predicted Severity": [
624.51
],
"Risk Premium": [
16.8
]
}
You can test the API using tools like Postman or Powershell - RestMethod.
Using Powershell - RestMethod:
$response = Invoke-RestMethod 'http://127.0.0.1:8080?power=20&VehAge=10&DrivAge=30&BonusMalus=10&VehGas=Regular&Area=D' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
insurance-premium-api/
│
├── app/
│ ├── __init__.py
│ ├── main.py # Main application file
│ ├── models.py # Data models for request and response
│ ├── routes.py # API route definitions
│ └── utils.py # Utility functions for premium calculation
│
├── tests/ # Unit and integration tests
│
├── requirements.txt # Python dependencies
└── README.md # Project documentation
Tests are located in the tests/
directory. You can run tests using pytest
:
pytest
Contributions are welcome! Please fork the repository and create a pull request with your changes.
git checkout -b feature/your-feature-name
).git commit -am 'Add some feature'
).git push origin feature/your-feature-name
).This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or feedback, feel free to reach out to the project maintainers.