Skip to main content

A FastAPI/ASGI middleware to simplify development of FastAPI apps on DataRobot

Project description

DataRobot ASGI Middleware

A middleware to simplify front-proxy handling and health checks in DataRobot.

Usage

Simply add to your FastAPI application that you expect to run in DataRobot

from fastapi import FastAPI

from datarobot_asgi_middleware import DataRobotASGIMiddleware

app = FastAPI()
app.add_middleware(DataRobotASGIMiddleware)


@app.get("/")
async def root():
    return {"message": "hello"}

Doing so will enable the automatic URLs such as docs/ and openapi.json to work as expected both in DataRobot and locally.

If you'd like to do proper Kubernetes health checks to let DataRobot know your application is healthy, the middleware adds a way to tell DataRobot to use a specific health URL endpoint like:/healthto validate your app is working as expected using kube-probe.

So, similar to the example above, but this time with health_endpoint="/health":

from fastapi import FastAPI

from datarobot_asgi_middleware import DataRobotASGIMiddleware


app = FastAPI()
app.add_middleware(DataRobotASGIMiddleware, health_endpoint="/health")


@app.get("/")
async def root():
    return {"message": "hello"}


@app.get("/health")
async def health():
    # Check on database connections, memory utilization, etc. If it returns
    # any error code like a 404 or 500, the app is marked as unhealthy
    return {"status": "healthy"}

Development

Development is designed to run with uv and Taskfile/go-task.

You can run tests, linters, etc. by setting these two up to work together

Testing realistically with Traefic

To test through a DataRobot-like proxy the examples/basic folder it contains a basic app and traefik configuration to start up with docker-compose -f examples/basic/docker-compose.yml up from the repo root folder, and validate by going to http://localhost:9999/front-proxy or run the baked-in task for it with:

task run-example-basic

Technically DataRobot does a double front-proxy for applications, so this configuration mimics the double proxy with one traefic instance.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datarobot_asgi_middleware-0.2.0.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datarobot_asgi_middleware-0.2.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file datarobot_asgi_middleware-0.2.0.tar.gz.

File metadata

File hashes

Hashes for datarobot_asgi_middleware-0.2.0.tar.gz
Algorithm Hash digest
SHA256 44588d6b16a8420ed8b6b8a198a8326be61f48d39a27f7df1a6511dc319b467b
MD5 4595993b8f82fcdac6334dd7b25ad3ca
BLAKE2b-256 3710b7651ffa919c76ec808db0af521e30e43adb18af9f4ee2413a4f854e7b6f

See more details on using hashes here.

File details

Details for the file datarobot_asgi_middleware-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for datarobot_asgi_middleware-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac6f999a568c04964673d6f2f5134e2ce4ad67ef3eebb4c2896981c0f5291493
MD5 94d23c93ec53f17a5f008e6d9ff3b9a1
BLAKE2b-256 429cdf8319321f8b606580cc0dab2884dcf58373aa567b8539c4a0681c96dfcc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page