Skip to content

Ready-to-use Flask application template for a rapid custom application development

License

Notifications You must be signed in to change notification settings

datarobot-oss/flask-app-base

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Flask app base template

In this repository you will find an empty Flask application base template to kickstart custom app development. The Datarobot client is already set up for you to use, it uses the Application creator's API key by default.

Setup

You can run the Flask app in DataRobot using a custom application or by running the app locally. Custom applications can be created either via the NextGen Registry's Applications page or by using DRApps.

Be sure to define the required variables for the app to communicate with DataRobot. If you run the app locally or in another environment than a custom application, you'll need to set the env variables. When this app is run via a custom application, the variables are set automatically.

#start-app.sh
export token="$DATAROBOT_API_TOKEN"  # Your API key, accessed from DataRobot's Developer Tools page
export endpoint="$DATAROBOT_ENDPOINT"  # Example: https://app.datarobot.com/api/v2/

Add and use runtime parameters

To add runtime parameters, create a metadata.yaml file in your application source folder. Here is an example of a DEPLOYMENT_ID that creates an environment variable called MLOPS_RUNTIME_PARAM_DEPLOYMENT_ID:

runtimeParameterDefinitions:
- fieldName: DEPLOYMENT_ID
  type: string

Once this file is part of your application source in DataRobot, it displays the new runtime parameter(s) as part of the app configuration.

To use the parameters, DataRobot recommends you add them via start-app.sh. Add the following conditional export before gunicorn starts:

if [ -n "$MLOPS_RUNTIME_PARAM_DEPLOYMENT_ID" ]; then
  export deployment_id="$MLOPS_RUNTIME_PARAM_DEPLOYMENT_ID"
fi

Now you can use os.getenv("deployment_id") within your application code.

Add pages

You can find a sample index page in the ./src/templates directory. You can add additional HTML templates here, and call them by adding new routes in the flask_app.py, as shown in the example below:

@flask_app.route("/new-page")
def new_page_route():
    return render_template("new-page.html", message="Hello World!")

Contents of new-page.html:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Flask Template</title>
</head>
<body>
<h1>{{ message }}</h1>
</body>
</html>

About

Ready-to-use Flask application template for a rapid custom application development

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •