Skip to main content

Common files for all deployments

Use common files to share code that all deployments will depend on. Common files are especially useful for utilities that all deployments can use: shared logging and analysis code, or shared data processing helpers.

Common files are stored in git which means they can be changed, tested and reviewed on branches.


Suppose you have a in the same directory as your notebook. Your notebook code might look like this:

import utils

def predict(inputs):
return 5

Before deploying, add to common files so it'll be available to your deployment:


Now, when you mb.deploy(...), your will be included in the deployment's environment.

Adding common files

Common files can be added from your notebook or git.

In your notebook, run mb.add_common_files(...):

# adds one file, ./, to common

# adds two files
mb.add_common_files(["", ""])

# adds all files in the local lib directory

# adds from a different directory
mb.add_common_files({"path/to/": ""})

When using git, just add your common files to the common directory at the root of your Modelbit repository.

Using common files

Common files are copied into the deployment when the deployment version is created. Updating common files does not update existing deployments to prevent changes in common files from breaking past versions. To include the latest versions of your common files in a deployment, redeploy it.

Suppose you've added to your common files. When a new deployment is created it'll have alongside


Common files supports directories. For example, if you want your common files to be copied into your deployments in a lib directory, put your common files in a sub directory called lib.

In a notebook, that could look like this:

mb.add_common_files({"path/to/": "lib/"})

In git, you'd place your in common/lib/ in your Modelbit repo.

Managing common files

You can list and remove common files in your notebook:

# delete two common files
mb.delete_common_files(["", "lib/"])

# list all the common files

In git, the same can be accomplished with git pull and git push.

Working with common files locally

You can append your Modelbit git repository's common directory to your Python sys.path to simulate your deployment's access to common files in your local environment.

import sys

When updating common files during local development, be sure to mb.add_common_files or git push them before deploying new versions of your deployment. Your local changes will only be available to new versions of your deployment if they've been uploaded to Modelbit before the deployment version is created.

See also

More information is available in the API reference for common files: