Skip to main content

deploy

Deploy a Python function and dependencies to Modelbit. Return values of the function must be JSON-serializable.

Parameters

mb.deploy({deployment_function}, python_version=, ...)

Standard parameters

  • deployment_function: Callable The function to deploy to Modelbit. If the function uses Python type hints for its parameters and return type, Modelbit will generate smarter sample code.
  • python_version: Optional["3.6"|"3.7"|"3.8"|"3.9"|"3.10"|"3.11"|"3.12"] Python version to run in production.
  • python_packages: Optional[List[str]] The pip packages to install in the deployment's environment. E.g. ["scikit-learn==1.0.2"].
  • requirements_txt_path: Optional[str] The filepath of a pip-compatible requirements.txt that specifies all of the packages needed for this deployment.
  • system_packages: Optional[List[str]] The apt-get packages to install in the deployment's environment. E.g. ["libgomp1"].
  • require_gpu: Optional[bool|"T4"|"A10G"] Configures the deployment to run in an environment with a GPU.
  • name: Optional[str] The name of the deployment. If omitted, the name of the deployment_function is used.
  • tags: Optional[List[str]] Specify the tags to associate with the deployment. Any tags currently associated with the deployment are preserved when calling mb.deploy if tags= is not specified.

DataFrame mode parameters

Setup parameters

  • setup: Optional[Union[str, List[str]]] One or more names of modelbit.setup blocks to include with the deployment.

Extra and common files parameters

  • extra_files: Optional[str, List[str], Dict[str, str]] Additional files to include with the deployment.
    • as str: The path to a single file or directory.
    • as List[str]: Paths to multiple files or directories.
    • as Dict[str, str]: Pairs of file paths or directories. The key is the local file path, the value is the file path in the deployment. This format is for advanced use cases where the name or path of a file is different in the deployment vs. locally.
  • skip_extra_files_dependencies: Optional[bool] If True then mb.deploy will not parse extra_files to determine additional Python package dependencies. Default is False.
  • skip_extra_files_discovery: Optional[bool] If True then mb.deploy will not include additional files it discovers while parsing the files listed extra_files. Use this to limit mb.deploy to only include the extra_files specified. Default is False.
  • common_files: Optional[str, List[str], Dict[str, str]] All common files will be automatically included in the deployment unless their automatic linking setting has been disabled. To include common files that have automatic linking disabled, include them here.
    • as str: The path to a single file or directory.
    • as List[str]: Paths to multiple files or directories.
    • as Dict[str, str]: Pairs of file paths or directories. The key is the common file path, the value is the file path in the deployment.

Snowflake parameters

  • snowflake_max_rows: Optional[int] For deployments that will be used from Snowflake, limit the number of rows the deployment will receive in each batch created by Snowflake. This is used to tune performance and avoid data size limitations.
  • snowflake_mock_return_value: Optional[Any] Snowflake deployments can run in MOCK mode, where they return a static value instead of calling the deployment. This can be useful for testing Snowflake changes unrelated to deployment changes. Set this parameter to the value this deployment should return when running in MOCK mode. Default is SQL's null.

Returns

The call to mb.deploy is typically done in an interactive environment, like a Python notebook. The command will print out status, and then show link to open the deployment in Modelbit.

Examples

The following examples use the simple example_deployment_function as an example deployment function:

def example_deployment_function(a: int):
return a * 2

Deploying a simple function

Pass the inference function to mb.deploy to create a deployment:

mb.deploy(example_deployment_function)

Deploying into a specific Python version

Specify the Python version with python_version=

mb.deploy(example_deployment_function, python_version="3.8")

Deploying with specific Python packages

Specify custom Python environments with python_packages= and system_packages=:

mb.deploy(example_deployment_function, python_packages=["pandas==2.0.3"])

Deploying with a requirements.txt file

Specify the path to a pip-compatible requirements.txt file that defines your custom Python environment with requirements_txt_path= :

mb.deploy(example_deployment_function, requirements_txt_path="my_requirements.txt")

Deploying with dataframe_mode

Use DataFrame mode to create deployments that perform inferences on DataFrames:

mb.deploy(get_predictions, dataframe_mode=True, example_dataframe=X_train)

Deploying with a package built from git

Python packages be built from public GitHub repositories:

mb.deploy(find_cat, python_packages=["git+https://github.com/facebookresearch/segment-anything.git"])

Including local python files

Include additional files with the deployment by specifying extra_files=:

mb.deploy(example_deployment_function, extra_files=["utils.py"])

Deploying to a GPU-enabled environment

Enable GPUs when creating the deployment by setting require_gpu=:

mb.deploy(example_deployment, require_gpu=True)

See also