Skip to main content

Common files for all deployments

Use common files to share code that many deployments will depend on. Common files are especially useful for utilities that multiple deployments can use like shared logging and analysis code or shared data processing helpers. If additional files are only needed for one deployment, use extra files instead.

Common files are copied into the deployment when the deployment is created (with mb.deploy or git push). 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, simply redeploy it.

There are two different APIs for working with common files in Modelbit:

  • Git -- Common files are most commonly managed via git
  • Python -- Python APIs for managing common files

Git

Common files live in the common directory at the root of your Modelbit repository. Using common files within deployments involves creating symlinks between those files and the deployments.

Adding and managing common files

All of your common files should be stored under the common directory within your Modelbit repo. Adding and removing files within that directory is as simple as making the changes and running git push.

After adding a common file to your Modelbit repo, create a symlink to link it 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:

modelbit add_common_files --deployment example_deployment

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

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

Python API

Adding and managing common files from a Python notebook can be done using the mb.add_common_files, mb.delete_common_files and mb.common_files commands.

Automatic linking for notebook users

For notebook users, 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.

You can also tell Modelbit to include common files that would have been skipped with the common_files parameter of mb.deploy().

For example, these commands add common files to your workspace:

# adds one file, ./utils.py, to common
mb.add_common_files("utils.py")

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

# adds all files in the local lib directory
mb.add_common_files("lib")

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

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

# list all the common files
mb.common_files()