Skip to main content

Extra files for one deployment

info

This feature is useful for users of Python notebooks. Users working with git can simply add the file(s) to their deployment's directory.

If your deployment depends on one or two helper files you can include them in your deployment with the extra_files parameter.

For example, if you use import utils to access the code within a utils.py, you can include the utils.py file when you run mb.deploy:

import utils # stored at ./utils.py

def my_function(...):
return utils.example()

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

Importing a directory

If you have many additional files they're probably in a directory next to your notebook. In that case, capture the whole directory with extra_files to include necessary files like __init__.py. For example, suppose your files are in the directory my_lib:

mb.deploy(my_function, extra_files=["my_lib"])

Advanced usage

Some notebook environments change the PYTHON_PATH envvar to import files that aren't siblings your notebook. In these cases you can use the dictionary format of extra_files use a different path in the deployment than in the notebook.

For example, if utils.py is in a different directory but is still importable as import utils, then remap the filepath when deploying:

mb.deploy(my_function, extra_files={ "path/to/utils.py": "utils.py" })

For more information on using extra_files, see the API reference for extra_files.

When multiple deployments need these files

Instead of using extra_files for code that'll be shared between deployments, use common files. Common files are files made available to all deployments.

Adding files to an existing deployment

You can add files to a deployment that's already been deployed using the mb.add_files command.

mb.add_files("deployment_name", ["path/to/local/file1.pkl"])

After successfully adding the file to the deployment a new deployment version will be deployed.