Dependencies

Learn how to manage dependencies of your applications.

When building a dstack application, you can use your own packages and modules as well as third-party libraries.

The information on these packages, modules, and libraries must be specified within the call of the dstack.app() function. Here's an example:

import dstack as ds
from handlers import fake_handler
# Create an instance of an application an pass over
# dependencies to local modules "handlers" and "utils" and third-party packages
app = ds.app(depends=["handlers", "utils"], requirements="requirements.txt")
# The line above is equal to the line below
# app = ds.app(depends=["numpy", "pandas", "faker==5.5.0", "handlers", "utils"])
# An output with a handler from one of the modules the application depends on
app.output(handler=fake_handler)
# Deploy the application with the name "faker" and print its URL
url = app.deploy("faker")
print(url)

As you see here, we use the depends and requirements arguments to specify what modules, packages, and libraries the application depends on. In this case, the application depends on the module handlers, the package utils, and on all libraries specified in the requirements.txt.

Be careful, when you run the script that deploys a dstack application with dependencies to local modules or packages, make sure that the root folder from where you run the script is exactly the folder that contains these packages and modules.

When you run the application the first time, dstack makes sure all dependencies are installed on the first run.