Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article describes how to use files to modularize your code, including how to create and import Python files.
Databricks also supports multi-task jobs which allow you to combine notebooks into workflows with complex dependencies. For more information, see Orchestration using Databricks Jobs.
With Databricks Runtime 11.3 LTS and above, you can create and manage source code files in the Azure Databricks workspace, and then import these files into your notebooks as needed. You can also use a Databricks repo to sync your files with a Git repository. For details, see Work with Python and R modules and Git integration for Databricks Git folders.
To create a file:
- In the left sidebar, click Workspace.
- Click Create > File. The file will open in an editor window and changes are saved automatically.
- Enter a name for the file ending in
.py
.
You can import a file into a notebook using standard Python import commands:
Suppose you have the following file:
You can import that file into a notebook and call the functions defined in the file:
If a helper file is in another folder, you need to use the full file path. To copy the full path, navigate to the file in your workspace and in the kebab menu, click Copy URL/path > Full path.
You can import a file from a different folder into a notebook as follows:
You can run a file from the editor. This is useful for testing. To run a file, place your cursor in the code area and select Shift + Enter to run the cell, or highlight code in the cell and press Shift + Ctrl + Enter to run only the selected code.
See Folders and Workspace object operations for information about how to access the workspace menu and delete files or other items in the workspace.
To change the title of an open file, click the title and edit inline or click File > Rename.
If your Azure Databricks account has the Premium plan, you can use Workspace access control to control who has access to a file.