{"id":50928364,"url":"https://github.com/persteenolsen/fastapi-jwt-auth-ml-one","last_synced_at":"2026-06-17T01:31:10.623Z","repository":{"id":351347695,"uuid":"1210618266","full_name":"persteenolsen/fastapi-jwt-auth-ml-one","owner":"persteenolsen","description":"Python FastAPI with JWT Auth serving ML for House Price Prediction","archived":false,"fork":false,"pushed_at":"2026-04-14T16:30:46.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-14T17:27:06.036Z","etag":null,"topics":["fastapi","jwt","machine-learning","python"],"latest_commit_sha":null,"homepage":"https://fastapi-jwt-auth-ml-one.vercel.app/docs","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/persteenolsen.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-14T15:35:56.000Z","updated_at":"2026-04-14T16:58:26.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/persteenolsen/fastapi-jwt-auth-ml-one","commit_stats":null,"previous_names":["persteenolsen/fastapi-jwt-auth-ml-one"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/persteenolsen/fastapi-jwt-auth-ml-one","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-ml-one","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-ml-one/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-ml-one/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-ml-one/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/persteenolsen","download_url":"https://codeload.github.com/persteenolsen/fastapi-jwt-auth-ml-one/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-ml-one/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34430688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"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":["fastapi","jwt","machine-learning","python"],"created_at":"2026-06-17T01:31:10.056Z","updated_at":"2026-06-17T01:31:10.603Z","avatar_url":"https://github.com/persteenolsen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🏠 v1 - House Price Prediction API (FastAPI + JWT + ML)\n\nLast updated:\n\n- 19-04-2026\n\nA simple machine learning API built with FastAPI that predicts house prices based on house size and number of rooms.  \nThe API is secured using JWT authentication and serves a trained scikit-learn model.\n\n---\n\n## ✨ Features\n\n- JWT authentication (login + protected routes)\n- Machine Learning model (Linear Regression)\n- FastAPI REST API\n- Training pipeline using CSV dataset\n- Model saved with Joblib\n- Swagger UI (`/docs`) for testing\n\n---\n\n## 🧰 Tech Stack\n\n- FastAPI\n- Uvicorn\n- Scikit-learn\n- Pandas\n- NumPy\n- PyJWT\n- Joblib\n- Python-dotenv\n\n---\n\n## 📁 Project Structure\n\n- app.py → FastAPI application (API + JWT + ML)\n- train.py → Model training script\n- data.csv → Training dataset\n- model.pkl → Saved trained model\n- requirements.txt → Dependencies\n- .env → Environment variables\n\n---\n\n## ⚙️ Installation\n\n### 1. Clone repository\ngit clone \u003crepo-url\u003e\ncd project\n\n---\n\n### 2. Create virtual environment (optional)\npython -m venv venv\n\nActivate:\n- Windows:\n  venv\\Scripts\\activate\n\n- Mac/Linux:\n  source venv/bin/activate\n\n---\n\n### 3. Install dependencies\npip install -r requirements.txt\n\n---\n\n### 4. Create .env file\n\nSECRET_KEY=your_secret_key\nFAKE_USERNAME=admin\nFAKE_PASSWORD=1234\n\n---\n\n## 🧠 Train the Model\n\nRun:\n\npython train.py\n\nThis will:\n- Load data.csv\n- Train a Linear Regression model\n- Save model as model.pkl\n\n---\n\n## 🚀 Run the API\n\nStart server:\n\npython app.py\n\nOpen:\n\nhttp://localhost:8000\n\nhttp://localhost:8000/docs\n\n---\n\n## 🔐 Authentication Flow\n\n### Step 1: Login\n\nPOST /login\n\n{\n  \"username\": \"admin\",\n  \"password\": \"1234\"\n}\n\nResponse:\n\n{\n  \"token\": \"your_jwt_token\"\n}\n\n---\n\n### Step 2: Authorize in Swagger\n\nClick \"Authorize 🔒\" and enter:\n\nBearer \u003cyour_token\u003e\n\n---\n\n## 🏠 Prediction Endpoint\n\nPOST /predict (protected)\n\nRequest:\n\n{\n  \"size\": 90,\n  \"rooms\": 3\n}\n\nResponse:\n\n{\n  \"user\": \"admin\",\n  \"input\": {\n    \"size\": 90,\n    \"rooms\": 3\n  },\n  \"predicted_price\": 270000\n}\n\n---\n\n## 🧠 How it works\n\n- data.csv is used to train the model\n- Linear Regression learns relationship between:\n  - size\n  - rooms\n- Model is saved as model.pkl\n- FastAPI loads model at startup\n- JWT protects prediction endpoint\n\n---\n\n## 📈 What this project demonstrates\n\n- Learn FastAPI + ML integration\n- Build secure ML APIs\n- Portfolio project\n- Base for production ML services\n\n---\n\n## 🚀 Future Improvements\n\n- Use real datasets (Kaggle)\n- Add database (PostgreSQL)\n- Add user roles\n- Dockerize project\n- Deploy to other cloud than Vercel if wanted\n- Splitting the app.py into files and folders for better structure\n\n---\n\n## 👨‍💻 Author\n\nLearning project combining:\nFastAPI + JWT + Machine Learning\n\n---\n\n## 📜 License\n\nEducational use only ...\n\nHappy coding :-)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpersteenolsen%2Ffastapi-jwt-auth-ml-one","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpersteenolsen%2Ffastapi-jwt-auth-ml-one","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpersteenolsen%2Ffastapi-jwt-auth-ml-one/lists"}