{"id":30186987,"url":"https://github.com/codeofrahul/insurance-premium-prediction-fastapi","last_synced_at":"2025-08-12T15:24:13.207Z","repository":{"id":297801601,"uuid":"997932853","full_name":"CodeofRahul/Insurance-premium-prediction-fastapi","owner":"CodeofRahul","description":"A FastAPI based API for the insurance premium prediction ML project","archived":false,"fork":false,"pushed_at":"2025-06-07T14:43:14.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-07T15:31:47.318Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodeofRahul.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-07T14:06:02.000Z","updated_at":"2025-06-07T14:43:18.000Z","dependencies_parsed_at":"2025-06-07T15:42:09.539Z","dependency_job_id":null,"html_url":"https://github.com/CodeofRahul/Insurance-premium-prediction-fastapi","commit_stats":null,"previous_names":["codeofrahul/insurance-premium-prediction-fastapi"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CodeofRahul/Insurance-premium-prediction-fastapi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeofRahul%2FInsurance-premium-prediction-fastapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeofRahul%2FInsurance-premium-prediction-fastapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeofRahul%2FInsurance-premium-prediction-fastapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeofRahul%2FInsurance-premium-prediction-fastapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeofRahul","download_url":"https://codeload.github.com/CodeofRahul/Insurance-premium-prediction-fastapi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeofRahul%2FInsurance-premium-prediction-fastapi/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270084462,"owners_count":24524187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-12T15:24:10.160Z","updated_at":"2025-08-12T15:24:13.196Z","avatar_url":"https://github.com/CodeofRahul.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Insurance Premium Prediction API 🚀\n\nA FastAPI-based machine learning API that predicts insurance premium categories based on user input such as age, BMI, city tier, and occupation.\n\n## Features\n\n- FastAPI backend\n- Pydantic input validation with computed fields\n- Pickle-based model prediction\n- JSON API response\n\n\nA FastAPI lab for prototyping ideas, testing features, and deepening API knowledge.\n\n![Fastapi 8](https://github.com/user-attachments/assets/cf28c33f-eba2-4562-a1f8-ce02e09c1afa)\n\n![Fastapi 7](https://github.com/user-attachments/assets/de5730b6-9fbe-4f2d-a061-c5eba6731f1d)\n\n![Fastapi 6](https://github.com/user-attachments/assets/574a192d-2d68-4a30-af85-d6817e5bdf43)\n\n![Fastapi 5](https://github.com/user-attachments/assets/08d4b9ec-d6ff-43ea-86cb-dd7061c71e3e)\n\n![Fastapi 4](https://github.com/user-attachments/assets/380c1b44-e4ca-4c5e-af6d-47009bbad433)\n\n![Fastapi 3](https://github.com/user-attachments/assets/21a25096-17e5-4288-b238-8dfe5c542ca2)\n\n![Fastapi 2](https://github.com/user-attachments/assets/65a5d86e-b424-4d42-a9c8-154176f7fab9)\n\n![Fastapi 1](https://github.com/user-attachments/assets/5bf32338-a69c-48b3-b597-fd32351ead8e)\n\n## Why FastAPI is fast to code?\n\n1. Automatic input Validation \u003cbr\u003e\n2. Auto-Generated interactive Documentation \u003cbr\u003e\n3. Seamless Integration with Modern Ecosystem (ML/DL libraries, OAuth, JWT, SQL Alchemy, Docker, Kubernetes etc) \n\n#### Run the Server:\n\n```bash\nuvicorn main:app --reload\nfastapi dev app.py\n```\n\n## Request body:\n\nA **request body** is the portion of an HTTP request that contains data sent by the client to the server. It is typically used to HTTP methods POST or PUT to transmit structured data (e.g. JSON, XML, form-data) for the purpose of creating or updating resources on the server. The server parses the request body to extract the necessary information and perform the intended operation.\n\n\n\n## **HTTP Requests:**\n\n## Real-world analogy:\n\nGET is like reading a book in a library.\nPost is like writing a note and handing it to the librarian.\n\n-\tWhen you GET, you’re just requesting to see something\n-\tWhen you POST, you’re sending data to be processed or saved.\n\n### Technical Difference\n\n| Feature | GET | POST |\n| -------- | ------- | ------- |\n| Purpose | Retrieve data | Submit data |\n| Data location | In URL (query string) | In the request body |\n| Visibility | Data is visible in URL | Data is hidden from URL |\n| Use for | Reading/fetching resources | Creating/updating resources |\n| Bookmarkable | Yes | No |\n| Idempotent | Yes (repeating gives same result) | Not necessarily (can cause changes |\n\n### Get request:\n\n```http\nGET /search?query=shoes HTTP/1.1\n```\n\n-\tYou’re asking: “Hey server, show me all the shoes.”\n\n### POST request:\n\n```http\nPOST /add-to-cart HTTP/1.1\nBody: { “item_id”: 123, “quantity”: 2}\n```\n\n-\tYou’re saying: “Hey server, please add this item to my cart.”\n\n## Think of it like a conversation with a website:\n\n### 1. GET = “Just give me info”\n\n-\tYou’re asking the server for something.\n-\tExample: “Show me all blog posts tagged with ‘travel’.”\n-\tYou don’t change anything on the server.\n-\tThe server responds with that info.\n\n**In the browser: **\n\n-\tYou type in a URL or click a link – that’s a GET request.\n-\tExample: `https://example.com/posts?tag=travel`\n\n### 2. POST = “I’m giving you something to do”\n\n-\tYou’re sending data to the server to do something with it.\n-\tExample: “Here is my comment on this blog post.”\n-\tThe server might save that comment to a database.\n\n**In the browser: **\n\n-\tYou fill out a form and click “Submit” – that’s a POST request.\n-\tExample: You post a review, submit login info, or upload a photo.\n\n## Why does it matter?\n\n-\tGET is for viewing. (safe, can be cached, can be bookmarked.)\n-\tPOST is for doing. (Sends new data, not cached, not bookmarkable.)\n\n## GET Scenarios (Read-only actions)\n\nThese are situations where the client just wants to retrieve data, without making any changes:\n\n### 1. Loading a web page\n\n-\tURL: `https://news.com/latest`\n-\tYou want to view the latest news.\n-\tNo data is sent except in the URL.\n\n### 2. Search queries\n\n-\tURL: `https://store.com/search?q=laptop`\n-\tYou are searching for laptop”.\n-\tThe search term is passed as a query string.\n\n### 3. Viewing a user profile\n\n-\tURL: `https://site.com/user/john`\n-\tJust displays John’s profile\n-\tDoesn’t change anything.\n\n### 4. Pagination\n\n-\tURL: `https://blog.com/posts?page=3`\n-\tYou’re just asking for page 3 of the blog.\n\n### 5. Filtering results\n\n-\tURL: `https://shop.com/products?category=shoes\u0026price=low`\n-\tYou’re applying filters to what you see.\n\n## POST Scenarios (Write/Submit actions)\n\nThese are situations where the client is sending data to the server to create, modify, or trigger actions.\n\n### 1. Submitting a login form\n\n-\tURL: `https://site.com/login`\n-\tSends your username and password.\n-\tServer checks and starts your session.\n\n### 2. Creating a new user/account\n\n-\tURL: `https://site.com/signup`\n-\tSends your name, email, password, etc.\n\n### 3. Submitting a contact form\n\n-\tSends message, name, email to the server to be saved or emailed.\n\n### 4. Uploading a file or image\n\n-\tSends the file data as part of the request body.\n\n### 5. Adding to a shopping cart\n\n-\tYou click “Add to Cart” – the item ID and quantity are sent to the server.\n\n### 6. Placing an order\n\n-\tURL: `https://shop.com/checkout`\n-\tSends the cart items, payment detail, shipping info.\n\n### 7. Posting a comment or message\n\n-\tSubmits text, maybe with a post ID or thread ID.\n\n\n## Summary Table:\n\n Scenario | Method |\n -------- | ------- | \n View a blog post | GET |\n Search for a products | GET |\n Login to a site | POST |\n Sign up for a new account | POST |\n Add an item to cart | POST |\n Submit a contact form | POST |\n View a list of product | GET |\n Filter products by price | GET |\n Post a review | GET |\n Get weather info by city | GET |\n Upload a profile picture | POST |\n View user profile | GET |\n\n## GET Request on Flipkart (Viewing or fetching data)\n\nThese happen when you’re just browsing or searching without changing anything on the server.\n\n### 1. Homepage Load\n\n-\tWhen you go to `https://www.flipkart.com`, your browser sends a GET request.\n-\tYou’re just asking to view the homepage.\n\n### 2. Searching for a product \n\n-\tYou type “mobile phone” in the search bar and hit Enter.\n-\tURL becomes: `https://www.flipkart.com/search?q=mobile+phones`\n-\tThat’s a GET request with the query `q=mobile+phones`\n-\tYou are just requesting info.\n\n### 3. Filtering products\n\n-\tApply a filter like “Price: Low to High” or select a brand.\n-\tURL updates to something like: `https://www.flipkart.com/search?q=mobile+phones\u0026sort=price_asc\u0026brand=Samsung`\n-\tStill a GET request – just showing filtered results.\n\n### 4. Viewing a product\n\n-\tClick on a phone to see its details.\n-\tURL: `https://www.flipkart.com/Samsung-galaxy/product-id`\n-\tAgain, it’s just fetching info – so it’s a GET.\n\n## POST Requests on Flipkart (Sending data or changing state)\n\nThese happen when you interact in a way that changes something – like logging in, adding to cart, or checking out.\n\n### 1. Logging in\n\n-\tYou enter your phone/email and password.\n-\tYour browser sends a POST request to `https://www.flipkart.com/api/login`\n-\tFlipkart checks your credentials and starts a session.\n\n### 2. Adding a product to cart\n\n-\tYou click “Add to Cart”.\n-\tA POST request is sent to something like: `https://www.flipkart.com/api/add-to-cart`\n-\tData sent: `{ product_id: 12345, quantity: 1 }`\n\n### 3. Placing an order\n\n-\tAfter selecting items, address, and payment, you click “Place Order”.\n-\tA POST request sends your order details to Flipkart’s servers to process.\n\n### 4. Submitting a review\n\n-\tYou rate a product and write a review.\n-\tFlipkart uses a POST request to store that review in their database.\n\n\n### Path Parameter\n\nThe Path() function in FastAPI is used to provide, validation rules, and documentation hints for path parameters in your API endpoints.\n\nTitle \u003cbr\u003e\nDescription \u003cbr\u003e\nge, gt, le, lt \u003cbr\u003e\nMin_length \u003cbr\u003e\nMax_length \u003cbr\u003e\nregex \u003cbr\u003e\n\n\n### HTTP status codes\n\n**HTTP status codes** are **3-digit number** returned by a web server (like FastAPI) to indicate the result of a client's request (like from a browser or API consumer).\n\nLINK\n\n\nThey help the **client (browser, fronted, mobile app, etc.) understand**:\n\n- whether the request was successful.\n- whether something went wrong.\n- and what kind of issue occurred (if any).\n\n|  |  |  |\n| -------- | ------- | ------- |\n| 2xx | ✅ Success | The request was successfully recieved and processed |\n| 3xx | 🔁 Redirection | Further action needs to be taken (e.g. redirect) |\n| 4xx | ⚠️ Client Error | Something is wrong with the request from the client |\n| 5xx | ❌ Server Error | Something went wrong on the server side |\n\n\n|  |  |  |\n| -------- | ------- | ------- |\n| 200 OK | Standard success | A `GET` or `POST` suceeded |\n| 201 Created | Resource created | After a `POST` that created something |\n| 204 No Content | Success, but no data returned | After a `DELETE` request |\n| 400 Bad Unauthorized | Malformed or invalid authentication | Missing field, wrong data type |\n| 401 Unauthorized | No/invallid authentication | Login required |\n| 403 Forbidden | Authenticated, but no permission | Logged in but not allowed |\n| 404 Not Found | Resource doesn't exist | Patient ID not DB |\n| 500 Internal Server Error | Generic failure | Something broken the server |\n| 502 Bad Gateway | Gateway (like Nginx) failed to reach backend |  |\n| 503 Service Unavailable | Server is down or overloaded |  |\n\n`HTTPException` is a Special built-in exception in FastAPI used to **return custom HTTP error responses** when something goes wrong your API.\n\nInstead of returning a normal JSON or crashing the Server, you can **gracefully raise an error** with:\n\n- a proper **HTTP** stats code (like 404, 400, 403, etc.)\n- a custom error message\n- (optional) extra header\n\n\n## Query Parameter\n\n**Query parameter** are optional key-value pairs appended to the end of a URL, used to **pass additional data** to the server in an HTTP request. They are typically employed for operations like filtering , sorting. \u003cbr\u003e\nsearching and pagination without altering the endpoint path itself.\n\n`/patients?city=Delhi\u0026sort_by=age`\n\n\n- The `?` marks the start of query parameters.\n- Each parameter is a key-value pair: `key=value`\n- Multiple parameters are separated by `\u0026`\n\nIn this case:\n\n- `city=Delhi` is query parameter for filtering\n- `sort_by=age` is a query parameter for sorting\n\n\n`Query()` is a utility function provided by **FastAPI** to declare, validate, and document **query parameters** in your API endpoints.\n\n\n## Pydantic\n\n**1. Define a Pydantic model** that represents the **ideal schema** of the data.\n\n- This includes the expected fields, their types, and any validation constraints (e.g. `gt=0` for positive number).\n\n**2. nstantiate the model with raw input data** (Usually a dictionary or JSON-like structure).\n\n- Pydantic will Automatically **validate** the data and **coerce** it into the correct Python type (if possible).\n- If the data doesn't meet the model's requirements, Pydantic raise a `validationError`.\n\n**3. Pass the validateed model object** to functions or use it throughout your codebase.\n\n- This ensures that every part of your program works with **clean, type-safe, and logically valid data**.\n\n\n\n### What is the difference between class and function in Python?\n\nIn Python, you use classes to describe objects. Think of a class as a tool you use to create your own data structures that contain information about something; you can then use functions (methods) to perform operations on the data you describe.\n\n\n\n\n## Bash Environment Commands\n\n- To Create a file\n\n```bash\n\ntouch \u003cfile_name\u003e\n# Example: touch Test_Excercise.py\n```\n\n- Run python (.py) file:\n\n```bash\npython file_name.py\n\n```\n\n- To Create a virtual environment\n\n```bash\n\npython -m venv \u003cenv_name\u003e\n# Example: python -m venv mlapi\n```\n\n- Activate the virtual environment\n\n```bash\n\nsource \u003cenv_name\u003e/bin/activate  # for macos\nsource \u003cenv_name\u003e/Scripts/activate  # for windows\n# Example for macos: source mlapi/bin/activate\n# Example for window bash: source mlapi/Scripts/activate\n```\n- Deactivate the virtual environment\n\n```bash\n\ndeactivate\n```\n\n- Delete the environment\n\n```bash\n\nrm -rf \u003cenv_name\u003e\n# Example: rm -rf mlapi\n```\n\n- Useful Bash Tips for Environment Management\n\nList Python virtual environments if stored in a folder (e.g., `~/venvs`)\n\n```bash\n\nls ~/venvs\n```\n\nFind all virtual environments on your system (search for `activate` scripts)\n\n```bash\n\nfind ~ -type f -name \"activate\"\n```\n\nQuick script to list venv env names inside `~/venvs`\n\n```bash\n\nfor dir in ~/venvs/*; do\n  if [ -f \"$dir/bin/activate\" ]; then\n    echo \"$(basename \"$dir\")\"\n  fi\ndone\n```\n\n## Pip Commands\n\n- To install requirements.txt = `pip install -r requirements.txt`\n- To check install packages = `pip list`\n- To check detailed about package = `pip show package_name`\n- To install package = `pip install package_name`\n- To uninstall package = `pip uninstall package_name`\n- To save all packages of env to a requirements.txt file = `pip freeze \u003e requirements.txt`\n\n## Git commands\n\n- To add all file = `git add .`\n- To add any particular file = `git add \u003cfile_name\u003e`\n- To commit = `git commit -m \"commit message\"`\n- To push the code = `git push origin main`\n\nDocs:\n\n- Documentation: https://fastapi.tiangolo.com\n- Source Code: https://github.com/fastapi/fastapi\n\n-  Swagger UI:\n\n```bash\nlocalhost:8000/docs\nhttp://127.0.0.1:8000/docs\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeofrahul%2Finsurance-premium-prediction-fastapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeofrahul%2Finsurance-premium-prediction-fastapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeofrahul%2Finsurance-premium-prediction-fastapi/lists"}