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. If additional files are only needed for one deployment, use extra files.

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

Adding common files to Modelbit

Common files can be added from your Python 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, add your common files to the common directory at the root of your Modelbit repository.

Using common files

Common files are linked into the deployment when the deployment version is created using mb.deploy(...). For deployments created using git instead of the Python API, common files must be added to the deployment with symlinks.

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. The next time you run mb.deploy, the new deployment version will have alongside


In git, after adding your to common/ in your Modelbit repo, you'd then create a symlink to link into the deployments of your choosing.

The easiest way to create symlinks for common files in git is using the modelbit add_common_files CLI command.

However, if you prefer to make your own symlinks you can, of course. To create a symlink from common/ to deployments/example_deployment/utils/py without using the CLI helper, run the following command:

cd deployments/example_deployment
ln -s ../../common/

Automatic linking of common files

By default, all common files are added to each new deployment when the deployment is created with mb.deploy(...). You can disable this behavior by toggling the the 'Link automatically' setting for individual common files in the web app. Turning off this toggle will skip including it the next time a deployment is created with md.deploy().

In git, you can manage the settings for which common files are linked by updating common/settings.yaml. The settings file can include file paths or path prefixes using asterisks, relative to the common directory.

schemaVersion: 1
- checkpoints/*

In a Python notebook you can tell Modelbit to include common files that would have otherwise been skipped with the common_files parameter of mb.deploy(). In git, of course, you only symlink the common files you want in the deployment.

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, delete files in common, and git push.

See also

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