Python Client

Version:
2019.3
Last modified: April 02, 2020

To deploy a Python model to Promote, you need to include information from the Promote library in your code. The library includes a number of methods you can use at various stages of deployment.

We recommend that you build Python models using version 3.6.5. If you have questions about Python versions, contact Support.

Visit our GitHub repository for technical information about how to deploy models with the Python client.

There, you can also find specialized instructions for how to deploy models using the H2O Python module.

Structure Your Directory

To correctly transfer all model dependencies to Promote, you have to structure your directory in a particular way. Create a folder that contains these files:

promote.sh (optional) This file executes before Promote builds your model. Include low-level system packages here.
main.py (required) This file contains your primary model deployment script.
helpers/ (optional) Include helper functions in this directory.
objects/ (optional) Include data fields needed for model execution (e.g., pickle files) here.
requirements.txt (required) This file contains a list of the packages you need to run your model. You must include the promote package here.

Set Authentication Credentials

You must include your Promote username, API key, and instance URL to deploy your model:

Python
  1. # Replace "USERNAME" with your Promote username. 
  2. # Replace "APIKEY" with your API key. 
  3. # Replace "PROMOTE_URL" with the URL of your instance.
  4.  
  5. p = promote.Promote(USERNAME, APIKEY, PROMOTE_URL)

Functions and Methods

Promote.metadata

Use the Promote.metadata method to assign related metadata to the model so the Promote platform can view it.

The Python client assigns metadata individually, with a maximum of six metadata values per model and with no more than 50 characters for each value.

 Usage

Python
  1. Promote.metadata["name"] = value

Example

Python
  1. Promote.metadata["voting"] = ENSEMBLE.voting

Promote.deploy

Use the Promote.deploy method to capture a model you've created as a function and any related files in the model directory, then send that information to the Promote platform.

Usage

Python
  1. Promote.deploy(name, model, testdata, confirm=False, dry_run=False, verbose=0)

Arguments

name (required) Data type: string Name the model you want to deploy to Promote.  
model (required) Data type: string Name the promoteModel() function you want to capture.  
testdata (required) Data type: object Provide a data object that the model can use to make predictions.   
confirm (optional) Data type: boolean Specify whether you want a confirmation prompt when you deploy your model. Default: False
dry_run (optional) Data type: boolean Specify whether you want Promote to determine if it can pickle the model. (This option doesn't deploy the model.) Default: False
verbose (optional) Data type: integer Specify how much information you want to log during deployment. Enter a value from 0 to 4, with 4 being the most information logged. Default: 0

Example

Python
  1. Promote.deploy("SimpleMarkovChain", MarkovChain, TESTDATA, confirm=True, dry_run=False, verbose=4)

Promote.predict

Use the Promote.predict method to send data to a deployed model and request a prediction.

Usage

Python
  1. Promote.predict(model, data)

Arguments

model (required) Data type: string Name the model you want to query.
data (required) Data type: dictionary or dataframe Provide the data that the model needs to make a prediction.

Example

Python
  1. # Providing test data
  2.  
  3. TESTDATA = {'step': 344, 'TransMatrix': [[0.69, 0.24, 0, 0, 0, 0.06],
  4.                                          [0, 0.49, 0.05, 0.46, 0, 0],
  5.                                          [0.5, 0, 0, 0.5, 0, 0],
  6.                                          [0.76, 0.24, 0, 0, 0, 0],
  7.                                          [0, 0, 0, 0, 0, 0],
  8.                                          [1, 0, 0, 0, 0, 0]], 'InitState': [[1, 0, 0, 0, 0, 0]]}
  9.  
  10. # After the model is online, sending data and receiving predictions
  11.  
  12. Promote.predict("SimpleMarkovChain", TESTDATA)

@promote.validate_json

Use the @promote.validate_json decorator to validate data passed into your model. If the data fails the checks for validation, it doesn't pass to your model.

This function requires the schema package to validate JSON data.

Usage

Python
  1. @promote.validate_json(Schema({'name': And(DATATYPE)}))

Example

Python
  1. import Promote
  2. from schema import Schema # https://pypi.python.org/pypi/Schema
  3.  
  4. @promote.validate_json(Schema({'step': int, 'TransMatrix': [[float, int]], 'InitState': [[float, int]]}))
Was This Helpful?

Running into problems or issues with your Alteryx product? Visit the Alteryx Community or contact support.