{"id":16567893,"url":"https://github.com/drorata/pm_api","last_synced_at":"2025-09-07T21:45:44.590Z","repository":{"id":150667711,"uuid":"132578844","full_name":"drorata/pm_api","owner":"drorata","description":"Minimal example of a RESTful API for a prediction model","archived":false,"fork":false,"pushed_at":"2018-12-13T11:27:28.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-05T10:46:35.650Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drorata.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2018-05-08T08:31:42.000Z","updated_at":"2018-12-13T11:27:29.000Z","dependencies_parsed_at":"2023-04-29T10:31:16.462Z","dependency_job_id":null,"html_url":"https://github.com/drorata/pm_api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/drorata/pm_api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorata%2Fpm_api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorata%2Fpm_api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorata%2Fpm_api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorata%2Fpm_api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drorata","download_url":"https://codeload.github.com/drorata/pm_api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorata%2Fpm_api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260040414,"owners_count":22949818,"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","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":"2024-10-11T21:07:44.342Z","updated_at":"2025-06-15T19:39:45.585Z","avatar_url":"https://github.com/drorata.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Building a minimal Flask based prediction API\n\nSo, you finished training your model.\nCongratulations!\nNow, it is time to expose it to the world (or at least to your peers).\nA standard way would be to build a RESTful API; to that end [Flask](http://flask.pocoo.org/) is probably a natural choice.\nIn this repository, we:\n\n1. Fetch titanic survival data\n2. Train a model out of it\n3. Persist the model into a Python [pickle](https://docs.python.org/3/library/pickle.html)\n4. Build an app which accepts JSON and returns predictions\n\nIn reality, it is likely you will need to split this example into three components:\n1. *Model training* and persisting/pickling\n2. Trained model *storage* (e.g. on S3)\n3. *Prediction app* which will load the trained model and provide prediction based on requests\n\n# How to try out this?\n\n## Virtual environment\n\nFor your own safety, make sure you work with this example inside a virtual environment.\nSimple way to do so is `conda create -n try-out-prediction-app python=3.6` if you're using `conda`.\nIn the virtual environment, install the requirements: `pip install -r requirements.txt`\n\n## Prepare data and train model\n\nTo make life easy, simply run `make train`.\n\n## Run the app\n\n### Local and naive\n\nFirst, from the root of the project run `python src/app.py`.\nYou are expecting the following: `* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)`.\nIf you install `httpie`, you could now easily try out the app.\nIn another terminal, you can now ask the app for predictions on the test set: `http POST http://0.0.0.0:5000/predict \u003c data/test.json`.\nThat's it.\n\n### Using docker\n\nYou can also use the provided `Dockerfile`. First, build the image:\n\n```bash\ndocker build -t pm_api .\n```\n\nOnce built, you can start a container running the image.\nIt is important to forward the port `5000` from the container to the host; use the `-p` parameter to do so:\n\n```bash\ndocker run -p 5000:5000 pm_api\n```\n\nOnce, running, you can send requests using the same line as above (used for the local example).\n\n# Remarks\n\n- I used the skeleton provided by [Amir Ziai](https://medium.com/@amirziai/a-flask-api-for-serving-scikit-learn-models-c8bcdaa41daa)\n- To have a consistent way of training and predicting, I use the tools from [ds-pub-utils](https://github.com/drorata/ds-pub-utils).\n  This allows fitting the model on the training set (including with regards to the data preprocessing).\n- You can also play around with the `/sleep` endpoint and use `foo.json` and `foo2.json` to see how two requests are processed in parallel.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrorata%2Fpm_api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrorata%2Fpm_api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrorata%2Fpm_api/lists"}