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.1.0.tar.gz (13.9 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.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for datarobot_asgi_middleware-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9f27b784bf8a6c0dc99f5a58c71edbaf8d7d38b0fd33fbc9e0d1d1813f4527ab
MD5 e978a5c645e9dabbbb7ff5c0d432f260
BLAKE2b-256 ba083a431316a837107b6d898dd9efd93c42f51a28a21aee6581fe16e0cc9aa6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datarobot_asgi_middleware-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71282edcb5aadc85df3def91bfc37baada7291c0c1e3ada5e7781d69017ea788
MD5 fdf6daa06a173667c0a83a4c455e5040
BLAKE2b-256 69178a94788f6d8cb924742b6099b21f89e3ed3e2249b63e3d6b0be17087db38

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