Python Client
Promote uses Python's Built-in Modules or Standard Library.
Importante
We recommend that you build Python models using version 3.9 to ensure compatibility with Promote. If you upgrade from a previous installation of Promote (for example, 2020.4.0), you might need to update your models and their dependencies to work with this Python version. If you have questions about Python versions, contact Support.
Nota
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 (for example, 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:
# Replace "USERNAME" with your Promote username. # Replace "APIKEY" with your API key. # Replace "PROMOTE_URL" with the URL of your instance. p = promote.Promote(USERNAME, APIKEY, PROMOTE_URL)
Functions and Methods
Promote.metadata
Use the Promote.metadatamethod to assign related metadata to the model so the Promote platform can view it.
Avvertimento
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
promote.metadata["name"] = value
Example
promote.metadata["voting"] = ENSEMBLE.voting
Promote.deploy
Use the Promote.deploymethod 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
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
promote.deploy("SimpleMarkovChain", MarkovChain, TESTDATA, confirm=True, dry_run=False, verbose=4)
Promote.predict
Use the Promote.predictmethod to send data to a deployed model and request a prediction.
Usage
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
# Providing test data TESTDATA = {'step': 344, 'TransMatrix': [[0.69, 0.24, 0, 0, 0, 0.06], [0, 0.49, 0.05, 0.46, 0, 0], [0.5, 0, 0, 0.5, 0, 0], [0.76, 0.24, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0]], 'InitState': [[1, 0, 0, 0, 0, 0]]} # After the model is online, sending data and receiving predictions promote.predict("SimpleMarkovChain", TESTDATA)
@promote.validate_json
Use the @promote.validate_jsondecorator to validate data passed into your model. If the data fails the checks for validation, it doesn't pass to your model.
Nota
This function requires the schema package to validate JSON data.
Usage
@promote.validate_json(Schema({'name': And(DATATYPE)}))
Example
import promote from schema import Schema # https://pypi.python.org/pypi/Schema @promote.validate_json(Schema({'step': int, 'TransMatrix': [[float, int]], 'InitState': [[float, int]]}))