modal.create_package_mounts

@typechecked
def create_package_mounts(module_names: Sequence[str]) -> List[_Mount]:

Returns a modal.Mount that makes local modules listed in module_names available inside the container. This works by mounting the local path of each module’s package to a directory inside the container that’s on PYTHONPATH.

Usage

import modal
import my_local_module

stub = modal.Stub()

@stub.function(mounts=[
    *modal.create_package_mounts(["my_local_module", "my_other_module"]),
    modal.Mount(local_dir="/my_local_dir", remote_dir="/"),
])
def f():
    my_local_module.do_stuff()