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
utils.py in the same directory as your notebook. Your notebook code might look like this:
Before deploying, add
utils.py to common files so it'll be available to your deployment:
Now, when you
utils.py 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
# adds one file, ./utils.py, to common
# adds two files
# adds all files in the local lib directory
# adds utils.py from a different directory
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
utils.py to your common files. When a new deployment is created it'll have
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
In a notebook, that could look like this:
In git, you'd place your
common/lib/utils.py in your Modelbit repo.
Managing common files
You can list and remove common files in your notebook:
# delete two common files
# list all the common files
In git, the same can be accomplished with
git pull and
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.
When updating common files during local development, be sure to
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.
More information is available in the API reference for common files: