mb.deploy(deployment_function, ...)
Deploys a Python function and dependencies to Modelbit. Return values of the function must be JSON-serializable.
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.name
:Optional[str]
The name of the deployment. If omitted, the name of thedeployment_function
is used.python_version
:Optional[str, 3.6|3.7|3.8|3.9|3.10|3.11]
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"]
. Git URLs to WHL files may also be specified, e.g. for Detectron2 packages.system_packages
:Optional[List[str]]
Theapt-get
packages to install in the deployment's environment. E.g.["libgomp1"]
.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
.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 common files.
- as
skip_extra_files_dependencies
:Optional[bool]
IfTrue
thenmb.deploy
will not parseextra_files
to determine additional environment dependencies. Default isFalse
.
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 an sklearn object
As a special case, you can pass a SciKit-Learn model or pipeline as the deployment function. When this model's API is called in production, sklearn_object.predict
will be called.
mb.deploy(my_sklearn_model)
See also
- Read the Deployments section of the docs for more info on deploying to Modelbit.