{"id":15288717,"url":"https://github.com/autotraderuk/fastapi-mlflow","last_synced_at":"2025-04-13T06:32:08.705Z","repository":{"id":57428499,"uuid":"453056787","full_name":"autotraderuk/fastapi-mlflow","owner":"autotraderuk","description":"Deploy mlflow models as JSON APIs with minimal new code","archived":false,"fork":false,"pushed_at":"2025-01-08T12:29:19.000Z","size":474,"stargazers_count":20,"open_issues_count":2,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-11T15:41:25.510Z","etag":null,"topics":["api","fastapi","mlflow","mlops","python","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/autotraderuk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-01-28T12:19:48.000Z","updated_at":"2025-01-08T12:29:24.000Z","dependencies_parsed_at":"2023-02-16T19:31:27.351Z","dependency_job_id":null,"html_url":"https://github.com/autotraderuk/fastapi-mlflow","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autotraderuk%2Ffastapi-mlflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autotraderuk%2Ffastapi-mlflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autotraderuk%2Ffastapi-mlflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autotraderuk%2Ffastapi-mlflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/autotraderuk","download_url":"https://codeload.github.com/autotraderuk/fastapi-mlflow/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248674659,"owners_count":21143760,"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":["api","fastapi","mlflow","mlops","python","python3"],"created_at":"2024-09-30T15:52:27.271Z","updated_at":"2025-04-13T06:32:08.326Z","avatar_url":"https://github.com/autotraderuk.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastapi mlflow\n\nDeploy [mlflow](https://www.mlflow.org/) models as JSON APIs using [FastAPI](https://fastapi.tiangolo.com) with minimal new code.\n\n## Installation\n\n```shell\npip install fastapi-mlflow\n```\n\nFor running the app in production, you will also need an ASGI server, such as [Uvicorn](https://www.uvicorn.org) or [Hypercorn](https://gitlab.com/pgjones/hypercorn).\n\n## Install on Apple Silicon (ARM / M1)\n\nIf you experience problems installing on a newer generation Apple silicon based device, [this solution from StackOverflow](https://stackoverflow.com/a/67586301) before retrying install has been found to help.\n\n```shell\nbrew install openblas gfortran\nexport OPENBLAS=\"$(brew --prefix openblas)\"\n```\n\n## License\n\nCopyright © 2022-23 Auto Trader Group plc.\n\n[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)\n\n## Examples\n\n### Simple\n\n#### Create\n\nCreate a file `main.py` containing:\n\n```python\nfrom fastapi_mlflow.applications import build_app\nfrom mlflow.pyfunc import load_model\n\nmodel = load_model(\"/Users/me/path/to/local/model\")\napp = build_app(model)\n```\n\n#### Run\n\nRun the server with:\n\n```shell\nuvicorn main:app\n```\n\n#### Check\n\nOpen your browser at \u003chttp://127.0.0.1:8000/docs\u003e\n\nYou should see the automatically generated docs for your model, and be able to test it out using the `Try it out` button in the UI.\n\n### Serve multiple models\n\nIt should be possible to host multiple models (assuming that they have compatible dependencies...) by leveraging [FastAPIs Sub Applications](https://fastapi.tiangolo.com/advanced/sub-applications/#sub-applications-mounts):\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_mlflow.applications import build_app\nfrom mlflow.pyfunc import load_model\n\napp = FastAPI()\n\nmodel1 = load_model(\"/Users/me/path/to/local/model1\")\nmodel1_app = build_app(model1)\napp.mount(\"/model1\", model1_app)\n\nmodel2 = load_model(\"/Users/me/path/to/local/model2\")\nmodel2_app = build_app(model2)\napp.mount(\"/model2\", model2_app)\n```\n\n[Run](#run) and [Check](#check) as above.\n\n### Custom routing\n\nIf you want more control over where and how the prediction end-point is mounted in your API, you can build the predictor function directly and use it as you need:\n\n```python\nfrom inspect import signature\n\nfrom fastapi import FastAPI\nfrom fastapi_mlflow.predictors import build_predictor\nfrom mlflow.pyfunc import load_model\n\nmodel = load_model(\"/Users/me/path/to/local/model\")\npredictor = build_predictor(model)\napp = FastAPI()\napp.add_api_route(\n    \"/classify\",\n    predictor,\n    response_model=signature(predictor).return_annotation,\n    methods=[\"POST\"],\n)\n```\n\n[Run](#run) and [Check](#check) as above.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautotraderuk%2Ffastapi-mlflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fautotraderuk%2Ffastapi-mlflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautotraderuk%2Ffastapi-mlflow/lists"}