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.6" | "3.7" | "3.8" | "3.9" | "3.10" | "3.11" | "3.12"]
Python version to run in production.python_packages
:Optional[List[str]]
Thepip
packages to install in the deployment's environment. E.g.["scikit-learn==1.0.2"]
.system_packages
:Optional[List[str]]
Theapt-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 thedeployment_function
is used.
DataFrame Mode parameters
dataframe_mode
:Optional[bool]
Whether to deploy in [DataFrame mode]/deployments/dataframe-mode). IfTrue
,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 beTrue
.
Setup parameters
setup
:Optional[Union[str, List[str]]]
One or more names ofmodelbit.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 you want the name or path of a file to be different in the deployment vs. locally.
- as
skip_extra_files_dependencies
:Optional[bool]
IfTrue
thenmb.deploy
will not parseextra_files
to determine additional Python package dependencies. Default isFalse
.skip_extra_files_discovery
:Optional[bool]
IfTrue
thenmb.deploy
will not include additional files it discovers while parsing the files listedextra_files
. Use this to limitmb.deploy
to only include theextra_files
that you specify. Default isFalse
.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.
- as
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 inMOCK
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 inMOCK
mode. Default is SQL'snull
.
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
- Read the Deployments section of the docs for more info on deploying to Modelbit.
mb.get_inference