Databricks

Databricks Workspace Files: Code Layout and Dependency Management

2026-03-26
更新: 2026-03-27
NicheeLab Editorial Team

In Databricks you often need to place Python modules, SQL files, configuration files, requirements.txt, and other assets in the workspace in addition to notebooks. Workspace Files is the feature that lets you put files of any type in the same file tree as your notebooks, enabling relative imports and dependency management.

This article walks through what Workspace Files is, how it compares to Repos, how relative imports work, how to manage packages with requirements.txt, and the dependency management patterns most commonly used in production.

What Are Workspace Files?

Workspace Files is the umbrella term for non-notebook files placed under the /Workspace/ path of a Databricks workspace. Since 2023, Databricks lets you upload, create, and edit Python files (.py), text files (.txt/.csv/.json), YAML, and configuration files directly from the workspace file browser.

Before Workspace Files, managing non-notebook files on Databricks required either uploading them to DBFS or calling other notebooks with the %run magic command. With Workspace Files, you can use the same directory structure and import style as any standard Python project.

Repos vs Workspace Files

AspectReposWorkspace Files
Git integrationYes (Clone/Pull/Push/Branch)No (manual upload or via API)
Main use caseTeam development, version control, PR reviewPersonal working files, helper modules, dependency files
File path/Workspace/Repos/<user>/<repo>//Workspace/Users/<user>/ or /Workspace/Shared/
Relative importsSupported (current directory is added to sys.path)Supported (also added to sys.path)
Access controlWorkspace ACL + Git permissionsWorkspace ACL only
Size limit10 GB across the repository500 MB per file
Version controlFull Git features (history, diff, branches)None (overwrite only)

The common pattern is to manage core team code in Repos, while keeping personal experimentation scripts and temporary configuration files in Workspace Files.

How Relative Imports Work

In Workspace Files (including Repos), Python files placed in the same directory as a notebook can be imported with standard import statements. This is because the current directory is automatically added to sys.path when the notebook runs.

Example Directory Structure

/Workspace/Users/[email protected]/my-project/
├── main_notebook.py        # メインのノートブック
├── utils.py                # ユーティリティ関数
├── config.yaml             # 設定ファイル
├── requirements.txt        # 依存パッケージ定義
└── transformations/
    ├── __init__.py          # パッケージ化に必要
    ├── clean.py             # データクレンジング関数
    └── aggregate.py         # 集約処理関数

Importing from a Notebook

# main_notebook.py

# 同じディレクトリのモジュールをインポート
from utils import validate_schema, log_metrics

# サブディレクトリのパッケージをインポート
from transformations.clean import remove_duplicates
from transformations.aggregate import daily_summary

# 設定ファイルの読み込み
import yaml
with open("config.yaml", "r") as f:
    config = yaml.safe_load(f)

# 処理の実行
df = spark.read.format("delta").load(config["input_path"])
df_clean = remove_duplicates(df)
df_summary = daily_summary(df_clean)
df_summary.write.format("delta").mode("overwrite").save(config["output_path"])

It is critical that __init__.py exists in the subdirectory. Without it, Python will not recognize the directory as a package, and from transformations.clean import ... will fail.

Package Management with requirements.txt

Placing a requirements.txt inside Workspace Files and installing from it with %pip in the notebook is a simple pattern for dependency management.

# requirements.txt
pandas==2.2.0
requests==2.31.0
pyyaml==6.0.1
great-expectations==0.18.0
# ノートブックの先頭セルで実行
%pip install -r ./requirements.txt

%pip performs a notebook-scoped package install and does not affect the cluster-wide environment. However, running a %pip cell restarts the Python process, so you must run it at the very top of the notebook.

Comparison of Dependency Management Patterns

PatternHowWhen to useProsCons
%pip installRun %pip install package in the notebookPersonal experimentation, exploratory analysisInstall instantlyVersion pinning tends to become loose
requirements.txtList dependencies in a file and run %pip install -rProject-level package managementExplicit versions, highly reproducibleInstall takes time every run
Cluster librariesPre-install libraries via cluster configurationShared dependencies across the teamNo %pip needed in notebooksRequires cluster restart
Init ScriptAuto-install with a script on cluster startOS-dependent libraries or system configurationRuns automatically at startupHard to debug, increases startup time
Wheel fileBuild your own package into .whl and installDistributing internal shared librariesFast install, clear version controlRequires setting up a build process

Managing Workspace Files via the API

Workspace Files can be managed not only via browser upload but also via the REST API and the Databricks CLI. This is convenient for automated deployment in CI/CD pipelines.

# Databricks CLIでファイルをアップロード
databricks workspace import \
  --path /Workspace/Shared/etl-project/utils.py \
  --file ./src/utils.py \
  --format SOURCE \
  --language PYTHON

# REST APIでファイル一覧を取得
curl -X GET \
  "https://<workspace-url>/api/2.0/workspace/list" \
  -H "Authorization: Bearer <token>" \
  -d '{"path": "/Workspace/Shared/etl-project"}'

# REST APIでファイルをエクスポート
curl -X GET \
  "https://<workspace-url>/api/2.0/workspace/export" \
  -H "Authorization: Bearer <token>" \
  -d '{"path": "/Workspace/Shared/etl-project/utils.py", "format": "SOURCE"}'

Best Practices

  • Structure directories by project: group notebooks, modules, and configuration files into a single directory so that relative paths work naturally.
  • Put shared files under /Workspace/Shared/: place utility modules used across the team in the shared folder rather than a personal folder, and make access control explicit.
  • Do not put large data files in Workspace Files: store CSV, Parquet, and other data files in cloud storage (S3/ADLS/GCS) or Unity Catalog Volumes.
  • Use Repos for real version control: Workspace Files has no version control, so manage core team code in Repos and keep Workspace Files for auxiliary purposes only.

Key Exam Points

  • "How do you import an external Python module from a notebook?" → Place a .py file in Workspace Files / Repos and import it
  • "How do you manage dependencies per notebook?" → %pip install -r requirements.txt
  • "What is the difference between Workspace Files and DBFS?" → Workspace Files is under /Workspace/ for code; DBFS is under /dbfs/ for data
  • "How do you import a module from a subdirectory?" → Add an __init__.py to turn it into a package

Check Your Understanding

Development Tools

問題 1

A data engineer wants to extract validation functions shared by several notebooks into a Python module (validators.py). To import it as from validators import check_schema, which file placement is most appropriate?

  1. Place validators.py in the same Workspace Files directory as the notebook
  2. Upload validators.py to DBFS (/dbfs/FileStore/)
  3. Put the contents of validators.py in another notebook and call it with the %run magic command
  4. Register validators.py as a cluster init script

正解: A

Placing a .py file in the same Workspace Files directory as the notebook works because the current directory is automatically added to sys.path, so standard import statements work. Files placed on DBFS are not on sys.path and cannot be imported directly. %run can be used to reuse functions but cannot be invoked through an import statement. An init script is for cluster-level system configuration at startup and is not the right place for a Python module.

Frequently Asked Questions

What is the difference between Workspace Files and DBFS (Databricks File System)?

Workspace Files live in the workspace file tree (under /Workspace/) and are managed alongside notebooks and Python modules. DBFS is a Databricks-managed file system mounted under /dbfs/ and accessed directly from clusters. Workspace Files are best for code, configuration files, and small dependency files, while DBFS is better suited for large data files. In the Unity Catalog era, directly using DBFS is no longer recommended; access via Volumes is becoming the standard.

How do you write relative imports with Workspace Files?

Python modules inside Workspace Files can be referenced with the standard Python relative/absolute import syntax. For example, if utils.py is placed under /Workspace/Users/[email protected]/project/, a notebook in the same directory can use import utils or from utils import my_function. For subdirectories, place an __init__.py to turn them into packages and reference them with from subdir.module import func. Inside Repos the current directory is added to sys.path in the same way, so relative imports work naturally.

How are Workspace Files tested on the Databricks certification exam?

They appear in the Development Tools domain of the Data Engineer Associate exam. The main question patterns are: how to import an external Python module from a notebook, where to put dependency files such as requirements.txt, and when to use Workspace Files versus Repos. It is important to clearly understand the Workspace Files path format (/Workspace/...) and how it differs from DBFS.

Check what you learned with practice questions

Practice with certification-focused question sets

無料で問題を解いてみる
Author

NicheeLab Editorial Team

NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.


Related articles
Databricks

Databricks Certifications: All 7 Exams, Difficulty & Study Plan (2026)

Complete guide to all 7 Databricks certifications — Data Eng...

Databricks

Databricks Exam Difficulty Ranking: All 7 Certs Compared (2026)

Every Databricks certification ranked by difficulty, with st...

Databricks

Databricks Study Guide: Fastest Pass Route & Time Estimates (2026)

How to pass Databricks certifications efficiently. Official ...

Databricks

Databricks Data Engineer Associate: Complete Guide (2026)

Domain-by-domain breakdown of the Databricks Certified Data ...

Databricks

Databricks Data Engineer Professional: Complete Guide (2026)

Tactics for the Databricks Certified Data Engineer Professio...

Browse all Databricks articles (110)
© 2026 NicheeLab All rights reserved.