Skip to main content
Version: 0.91

snorkelflow.sdk.Deployment

class snorkelflow.sdk.Deployment(deployment_uid, **kwargs)

Bases: ABC

The Deployment object represents a deployment in Snorkel Flow. Deployments help you deploy your Snorkel Flow applications to production. This class acts an interface between Snorkel Flow and external deployment services. Every deployment in Snorkel Flow is identified by a unique deployment_uid.

To create a deployment, use MLflowDeployment.create method. This will create a deployment in Snorkel Flow and register it with an MLflow Model Registry of your choice. You can then download the deployment artifacts and use the MLflow CLI to deploy it to production. SnorkelFlowPackage Deployment is deprecated and is only supported for backward compatibility. We recommend using MLflowDeployment instead.

This class also provides various methods to manage your deployments, like Deployment.list, Deployment.get, Deployment.delete etc.

A typical workflow for deploying an application to production is as follows:

from snorkelflow.sdk import MLflowDeployment, Deployment

my_deployment = MLflowDeployment.create("my-application", "my-deployment")
my_deployment.execute(df)

Follow with MLflow client calls to deploy your workflow to production.

__init__(deployment_uid, **kwargs)

Initializes a Deployment object. This constructor should not be called directly. Instead, use the Deployment.create method to create a deployment.

Parameters:

deployment_uid (int) – The unique identifier of the deployment.

Methods

__init__(deployment_uid, **kwargs)

Initializes a Deployment object.

create(application, name)

Creates a deployment.

delete(deployment_uid)

Delete a deployment based on the provided identifier.

execute(df)

Execute a deployment on a pandas DataFrame.

get(deployment_uid)

Fetches a Deployment object based on the provided identifier.

list([application])

List all deployments for an application.

update(name)

Update the metadata for the deployment.

abstract classmethod create(application, name)

Creates a deployment. This method is abstract and must be implemented by the child class.

Parameters:
  • application (Union[str, int]) – The name or UID of the application to be exported

  • name (Optional[str]) – The name of the deployment. If this is not provided, deployment name will be created using the application name. Deployment names are not unique and re-running this method with the same name will create a new deployment.

Return type:

Deployment

classmethod delete(deployment_uid)

Delete a deployment based on the provided identifier.

Examples

>>> from snorkelflow.sdk import Deployment
>>> Deployment.delete(deployment_uid=123)
Successfully deleted deployment with uid 123
Parameters:

deployment_uid (int) – The unique identifier of the deployment.

Return type:

None

execute(df)

Execute a deployment on a pandas DataFrame. This method can be used to test a deployment within Snorkel Flow environment before deploying it to production.

Examples

>>> from snorkelflow.sdk import Deployment
>>> deployment = Deployment.get(deployment_uid=123)
>>> deployment.execute(df=pd.DataFrame({"text": ["hello world"]}))
context_uid text preds preds_str probs
__DATAPOINT_UID
doc::0 0 this is sample text 1 services [0.2509882183599772, 0.25098841065990574, 0.24...
doc::1 1 this is another text paragraph 0 employment [0.25402374467456923, 0.24917708783941298, 0.2...
Parameters:

df (DataFrame) – A pandas DataFrame containing the data to execute the deployment on. The DataFrame must contain a column with the same name as the data schema of the deployment.

Returns:

A pandas DataFrame containing the output of the deployment. The output will be a DataFrame with the following columns: context_uid, preds, preds_str, probs. The preds column contains the predicted label, preds_str contains the predicted label as a string, and probs contains the predicted probabilities for each label.

Return type:

pd.DataFrame

classmethod get(deployment_uid)

Fetches a Deployment object based on the provided identifier. This object can be used to interact with the deployment.

Examples

>>> from snorkelflow.sdk import Deployment
>>> deployment = Deployment.get(deployment_uid=123)
>>> deployment.name
"my-deployment"
Parameters:

deployment_uid (int) – The unique identifier of the deployment.

Returns:

A Deployment object that can be used to interact with the deployment.

Return type:

Deployment

classmethod list(application=None)

List all deployments for an application. If application is not specified, lists all deployments in user’s current workspace. Note that this method can be expensive if there are a large number of deployments in the given workspace.

Examples

>>> from snorkelflow.sdk import Deployment
>>> Deployment.list(application="my-application")
Parameters:

application (Union[str, int, None], default: None) – Name or unique identifier of the application to list deployments for.

Returns:

A list of Deployment objects.

Return type:

List[“Deployment”]

update(name)

Update the metadata for the deployment. Currently, the only metadata that can be updated is the name.

Examples

>>> from snorkelflow.sdk import Deployment
>>> deployment = Deployment.get(deployment_uid=123)
>>> deployment.update(name="new-name")
>>> deployment.name
"new-name"
Parameters:

name (str) – The new name for the deployment.

Return type:

None