Skip to main content

fastapi mlflow

Deploy mlflow models as JSON APIs using FastAPI with minimal new code.

Installation

pip install fastapi-mlflow

For running the app in production, you will also need an ASGI server, such as Uvicorn or Hypercorn.

Install on Apple Silicon (ARM / M1)

If you experience problems installing on a newer generation Apple silicon based device, this solution from StackOverflow before retrying install has been found to help.

brew install openblas gfortran
export OPENBLAS="$(brew --prefix openblas)"

License

Copyright © 2022-26 Autotrader Group plc.

Apache-2.0

Examples

Simple

Create

Create a file main.py containing:

from fastapi_mlflow.applications import build_app
from mlflow.pyfunc import load_model

model = load_model("/Users/me/path/to/local/model")
app = build_app(model)

Run

Run the server with:

uvicorn main:app

Check

Open your browser at http://127.0.0.1:8000/docs

You 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.

Serve multiple models

It should be possible to host multiple models (assuming that they have compatible dependencies...) by leveraging FastAPIs Sub Applications:

from fastapi import FastAPI
from fastapi_mlflow.applications import build_app
from mlflow.pyfunc import load_model

app = FastAPI()

model1 = load_model("/Users/me/path/to/local/model1")
model1_app = build_app(model1)
app.mount("/model1", model1_app)

model2 = load_model("/Users/me/path/to/local/model2")
model2_app = build_app(model2)
app.mount("/model2", model2_app)

Run and Check as above.

Custom routing

If 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:

from inspect import signature

from fastapi import FastAPI
from fastapi_mlflow.predictors import build_predictor
from mlflow.pyfunc import load_model

model = load_model("/Users/me/path/to/local/model")
predictor = build_predictor(model)
app = FastAPI()
app.add_api_route(
    "/classify",
    predictor,
    response_model=signature(predictor).return_annotation,
    methods=["POST"],
)

Run and Check as above.

Release files for fastapi-mlflow 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-mlflow 0.8.0
File Size Uploaded
fastapi_mlflow-0.8.0.tar.gz 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-mlflow 0.8.0
File Interpreter ABI Platform
fastapi_mlflow-0.8.0-py3-none-any.whl Python 3 none any Details

Total release size:19.1 kB

Release files / fastapi_mlflow-0.8.0.tar.gz

Download URL fastapi_mlflow-0.8.0.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3f7ca2123a8e06fc5cfb9ee2deee66302b5fb45e8cfdb34ae87f178b5b8e3774
BLAKE2b-256 checksum
How to use checksums
e5eb75043089baecb47f3ceea0bf2e19fe1ab0a5446eec4e944cf9ba94f9fd86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / fastapi_mlflow-0.8.0-py3-none-any.whl

Download URL fastapi_mlflow-0.8.0-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c997aafbf23db4641ab40dc28845c5dc1f2765bcd7ed3e6641942aaf51d83ebc
BLAKE2b-256 checksum
How to use checksums
56c25e53030df2e341bb06a68e1a3b7e58c90a6c6cad1bd1e20d8b2cc9d0c843
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.8.0 This release

2 release files

0.7.0

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page