Skip to content

Testing your deployment locally

When you have made your deployment package you might want to test it out before you deploy it to UbiOps, to make sure your code runs as expected and to quickly filter out small mistakes. You can do so by simulating how UbiOps would initialize your deployment and how it would handle a request. You can use the ubiops.utils.run_local function from the UbiOps Python client library or the ubiops run_local command from the CLI.

For both options, we assume the following file structure:

└── Root Folder
    ├── Deployment Package Directory (e.g. "deployment_package")
    └── Local Testing Script (Python file containing the relevant code snippets)

Both methods will initialize your deployment and make a request to it, just like UbiOps would, but in your local environment.
These methods run the request function of your deployment in the current (virtual) environment. This means that all necessary libraries should be installed in the current (virtual) environment.

Python Client Library

The ubiops.utils.run_local function is part of the UbiOps Python client library. This library can be installed using pip:

pip install ubiops

After installing the Client Library, the ubiops.utils.run_local can be used with the following arguments:

Name Type Description
deployment_directory str The name of the deployment directory, absolute or relative to the current working directory, e.g. 'deployment_package'
data dict or str Input data of the deployment request function
init_context dict [optional] Context data of the deployment init function, defaults to Dummy init context
request_context dict [optional] Context data of the deployment request function, defaults to Dummy request context

Example

from ubiops import utils

# TODO: Enter your local relative/absolute path here
deployment_directory = "deployment_package"

# TODO: Adjust this example to mimic your input data
request_data = {"input": 123}

result = utils.run_local(deployment_directory, request_data)
print(f"Result: {result}")

CLI

The ubiops run_local command is part of the UbiOps CLI. This CLI can be installed using pip:

pip install ubiops-cli

After installing the CLI, the ubiops run_local command can be used with the following options:

Options Required/Optional Description
-dir/--directory Required Path to a directory that contains at least a 'deployment.py'
--data Optional The input data of the request
This option can be provided multiple times in a single command
-f/--json_file Optional Path to json file containing the input data of the request
--plain Optional Set the input data as plain text

Examples

ubiops run_local -dir deployment_package --data '{"input": 123}'
ubiops run_local -dir deployment_package -f input.json
ubiops run_local -dir deployment_package --plain "This is plain text"

If you are having any troubles in using the provided code snippets, do not hesitate to ask for help in our Slack community.