Python Client
For a Python model to be deployed to Promote, the model needs to include information from the Promote library. The library includes a number of methods used in the various stages of deployment.
Please visit our Github repository for more information on how to deploy models using the Python client.
Directory Structure Requirements
For all model dependencies to be correctly transferred to Alteryx Promote, you must follow a particular directory structure with the model folder containing:
- promote.sh: A file that is executed before your model is built. This file can be used to install low-level system packages, such as Linux.
- main.py: The primary model deployment script.
- helpers/: An optional directory where helper functions can be saved.
- objects/: An optional directory where pickle files or other data fields needed for model execution can be saved.
- requirements.txt: A file containing a list of the packages required to run your model. This file must include the promote package.
Functions and methods
Promote.metadata: A method that assigns related metadata to the model so the metadata is visible from within the Promote platform. Metadata is assigned individually, with a maximum of six metadata values per model, each with no more than 50 characters.
Promote.metadata["name"] = value
p.metadata["voting"] = ENSEMBLE.voting
Promote.deploy: A method that captures promoteModel() and the related files in the model directory to send to the Promote servers.
Promote.deploy(name, model, testdata, confirm=False, dry_run=False, verbose=0)
name: String. The model being deployed to Promote.
model: String. The promoteModel function being captured.
testdata: Object. A valid data object that the model will make predictions on.
confirm: Boolean. An option to allow the user to confirm deployment. Set to True to prompt confirmation.
dry_run: Boolean. An option to verify if the model can be pickled. Set to True to test the model. This option does not deploy the model.
verbose: Integer. An option that determines the how much information is logged during deployment. Enter a value 0 - 4, with 4 being the most information getting logged.
p.deploy("LPOptimizer_model", promoteModel, TESTDATA, confirm=False)
Promote.predict: A method that sends data to a deployed model for a prediction. This method uses a REST API request from R.
Promote.predict(model, data)
model: String. The name of the model.
data: dict or dataframe. The data required to make a prediction.
p.predict("LPOptimizer_model", {"activities": ["sleep", "work", "leisure"], "required_hours": [7, 10, 0], "happiness_per_hour": [1.5, 1, 2]})
@promote.validate_json: An optional decorator used to validate data passed into a model. This function requires the schema package to validate JSON.
from schema import Schema @promote.validate_json(Schema({'name': And(str, len)}))
import promote
@promote.validate_json(Schema({'name': And(str, lambda s: len(s) > 1)}))
def promoteModel(data):
return {'response': 'Hello ' + data['name'] + '!'}
This examples ensures that all data passed to the model:
- Is an object.
- Contains the key 'name'.
- Contains a string with a length greater than 1 character.
If the data does not meet these conditions, the data is not passed to the model.