Private packages
Upload your private Python libraries and helper code to Modelbit so they can be available in your Deployment environments. Modelbit has different workflows for uploading private packages depending on how you and your team share code:
- Files: If you have one or two
.py
files that your notebook code is importing, you're adding files. - Modules: If you have a directory of
.py
files that you import into your notebook, you're adding modules. - Packages: If you have a
setup.py
orpyproject.toml
and usepip install
to make your libraries available for import, you're adding packages. - Wheels: If you have a prebuilt
.whl
. or.tar.gz
for your package, you're adding wheels.
Adding files
If your notebook 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
that's in the same directory as your notebook, use:
mb.deploy(my_function, extra_files=["utils.py"])
If utils.py
is in a different directory but is still importable as import utils
, then:
mb.deploy(my_function, extra_files={ "path/to/utils.py": "utils.py" })
However, if utils.py
is one of many helper files in a directory, see the next section on adding modules.
Adding modules
Modules are added to Modelbit from within a notebook. Authenticate with Modelbit, import your module, and call mb.add_module
:
import my_module
mb.add_module(my_module)
Modelbit will create a package and version for the module, and upload it to your Modelbit workspace. The next time you deploy from a notebook you'll see my_module==0.0.1
installed into your environment and listed in your requirements.txt
.
Adding packages
Packages are directories of Python files that can be installed using pip
. Packages differ from Modules in that they typically specify a name, version and dependencies in a setup.py
or pyproject.toml
.
To add your package to Modelbit from the command line, run:
modelbit package add /path/to/the/package
Or from within a notebook authenticated with Modelbit:
mb.add_package("/path/to/the/package")
The /path/to/the/package
should be the directory containing the setup.py
or pyproject.toml
.
After adding your package to Modelbit, it will be automatically included in deployments made from notebooks with mb.deploy()
. If you are creating a deployment with git, add the package and version to the requirements.txt
file, (e.g. my_package==0.1.2
).
Overwriting existing versions
If you made changes to your package and want to replace the version in Modelbit without incrementing the version number, use the force
parameter.
On the command line:
modelbit package add --force /path/to/the/package
From within a notebook:
mb.add_package("/path/to/the/package", force=True)
New deployments will install the new version of the package. Previously created deployments models will not receive the updated package.
Adding wheels
Prebuilt packages can be wheels (.whl
) or source distributions (.tar.gz
). To upload a prebuilt package to Modelbit, use the same syntax as in adding packages, but point to the package's file instead of the source directory.
On the command line:
modelbit package add /path/to/the/package.whl
# or, if overwriting a version
modelbit package add --force /path/to/the/package.whl
Or from a notebook:
mb.add_package("/path/to/the/package.whl")
# or, if overwriting a version
mb.add_package("/path/to/the/package.whl", force=True)
Using uploaded modules
No code changes are needed to use your private packages from within a Modelbit deployment. You can use both import my_package
and from my_package import foo
import formats with your inference function:
from my_package import foo
def predict(a: int):
return foo(a)
mb.deploy(predict)
Viewing and deleting private packages
To see the private packages stored in Modelbit, head to the Packages area of in the top navigation. Deleting a package from here will remove it from the list of packages to install for new deployments. Deployments already using the package will not be affected, as the package is already installed in the deployment's environment.