Skip to main content

mb.deploy(deployment_function, ...)

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

Parameters

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[str, 3.7|3.8|3.9|3.10|3.11] 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"]. Git URLs to WHL files may also be specified, e.g. for Detectron2 packages.
  • 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.

DataFrame Mode parameters

  • dataframe_mode: Optional[bool] Whether to deploy in [DataFrame mode]/deployments/dataframe-mode). If True, example_dataframe must be specified.
  • example_dataframe: Optional[pandas.DataFrame] DataFrame with the columns and column types to expect in production in DataFrame mode. If specified, dataframe_mode must be True.

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.
  • skip_extra_files_dependencies: Optional[bool] If True then mb.deploy will not parse extra_files to determine additional environment dependencies. 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, you can limit the number of rows your 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

Deploying a simple function

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

mb.deploy(example_deployment_function)

Deploying into a specific Python version

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

Deploying with specific Python packages

See more examples in the custom Python environments documentation.

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

Deploying with dataframe_mode

See the DataFrame mode documentation for more examples.

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

Deploying with a package built from git

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

Including local python files

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

Deploying to a GPU-enabled environment

mb.deploy(example_deployment, require_gpu=True)

See also