{"id":26414095,"url":"https://github.com/sebiwtt/flaskriver","last_synced_at":"2025-07-05T09:34:04.432Z","repository":{"id":59251104,"uuid":"535991387","full_name":"sebiwtt/flaskriver","owner":"sebiwtt","description":"This is a repository for the open-source project flaskriver which will make it easier to combine the lightweight web-framework flask with the online-ML library river.","archived":false,"fork":false,"pushed_at":"2022-09-20T11:00:14.000Z","size":68,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-24T11:03:05.978Z","etag":null,"topics":["data-science","flask","machine-learning","online-learning","python","river","streaming"],"latest_commit_sha":null,"homepage":"https://flaskriver.ml","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/sebiwtt.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}},"created_at":"2022-09-13T06:36:35.000Z","updated_at":"2023-08-10T15:08:12.000Z","dependencies_parsed_at":"2023-01-18T16:02:50.204Z","dependency_job_id":null,"html_url":"https://github.com/sebiwtt/flaskriver","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sebiwtt/flaskriver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebiwtt%2Fflaskriver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebiwtt%2Fflaskriver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebiwtt%2Fflaskriver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebiwtt%2Fflaskriver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sebiwtt","download_url":"https://codeload.github.com/sebiwtt/flaskriver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebiwtt%2Fflaskriver/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263718840,"owners_count":23500939,"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":["data-science","flask","machine-learning","online-learning","python","river","streaming"],"created_at":"2025-03-17T23:57:45.952Z","updated_at":"2025-07-05T09:34:04.407Z","avatar_url":"https://github.com/sebiwtt.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"docs/img/text.png\" alt=\"logo\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    This is a repository for the open-source project Flaskriver. It combines the lightweight web-framework \u003ca href=\"https://flask.palletsprojects.com/en/2.2.x/\"\u003eFlask\u003c/a\u003e with the online-ML library \u003ca href=\"https://github.com/online-ml/river\"\u003eRiver\u003c/a\u003e. With this project, I want to make deploying online-ML models to the web easier and quicker.\n\u003c/p\u003e\n\n## Introduction\n### Installation\nFirst, you will have to install the package via pip:\n\n```sh\npip3 install flaskriver\n```\n\n### Hosting a model\nThe following code will spin up a development server which is providing a logistic regression model. You can reach its endpoints at:\n- http://localhost/predict:5000\n- http://localhost/train:5000\n- http://localhost/metric:5000\n\n```python\nfrom flaskriver import ClassificationInterface\nfrom flask import Flask\nfrom river import linear_model, metrics\n\nmodel = linear_model.LogisticRegression()\n\nmae = metrics.MAE()\naccuracy = metrics.Accuracy()\nmetrics = [mae, accuracy]\n\ninterface = ClassificationInterface(model, metrics)\n\napp = Flask(__name__)\ninterface.registerToApp(app)\n\nif __name__ == \"__main__\":\n    app.run(host=\"localhost\", debug=True)\n```\n\nAt these endpoints, the app will await the training data as the JSON payload of the request (since river models work with dictionaries). The payload for training the model could look something like this:\n\n```json\n{\n    \"features\":{\n        \"x1\":300,\n        \"x2\":210\n    },\n    \"target\":false\n}\n```\n\nThe most important thing about the payload for training is the keys \"features\" and \"target\". Without these, the model won't know what to learn. Training a model will not return anything but a 201 response (no payload).\n\nThe Payload for predicting a value would then look like this:\n\n```json\n{\n    \"x1\":100,\n    \"x2\":150\n}\n```\n\nA request to the prediction endpoint along with a payload like the one shown above would result in a response containing the predicted value under the key \"y_pred\".\n\n### Sending data to the model\nWith the following code, you can set up a small client which goes through an entire dataset (the \"Phishing\" dataset which comes with River) and incrementally trains the model. While training the model the specified metrics will be updated constantly. These metrics can be queried using the /metric endpoint. A request to this endpoint will result in a response containing all the metrics under an identically named key. So in this example, the response payload would contain the two keys \"MAE\" and \"Accuracy\" along with their values at this point in time.\n\n```python\nimport requests\nfrom river import datasets\n\ndataset = datasets.Phishing()\n\ntrain_url = f\"http://localhost:5000/train\"\nmetric_url = f\"http://localhost:5000/metric\"\n\nfor x, y in dataset:\n    payload = {\"features\": x, \"target\": y}\n    response = requests.post(train_url, json=payload)\n\n    response = requests.get(metric_url)\n    print(response.json())\n```\n\n## More information\n### Documentation\nYou can find more detailed documentation for Flaskriver at \u003ca href=\"https://flaskriver.ml\"\u003eflaskriver.ml\u003c/a\u003e\n\n### Package\nThe Package source and build is available on \u003ca href=\"https://pypi.org/project/flaskriver/\"\u003ePyPI\u003c/a\u003e so that it can be insalled via pip.\n\n### Repository\nIf you're wondering why there is a .gitlab-ci.yml file in the repository, don't worry. I did not mix up GitLab-CI and GitHub Actions ;) Since I am far more familiar with GitLab-CI I decided to create a repository there for running the automated CI-Pipeline. But with each push/merge to the main branch, all the code will be uploaded to this public GitHub repo as well. There is no extra code in the GitLab repository.\n\n## Contributing\nIf you would like to contribute something to the project feel free to share your ideas in form of an issue. You can also reach out to me directly via e-mail.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebiwtt%2Fflaskriver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsebiwtt%2Fflaskriver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebiwtt%2Fflaskriver/lists"}