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.
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.
| Aspect | Repos | Workspace Files |
|---|---|---|
| Git integration | Yes (Clone/Pull/Push/Branch) | No (manual upload or via API) |
| Main use case | Team development, version control, PR review | Personal working files, helper modules, dependency files |
| File path | /Workspace/Repos/<user>/<repo>/ | /Workspace/Users/<user>/ or /Workspace/Shared/ |
| Relative imports | Supported (current directory is added to sys.path) | Supported (also added to sys.path) |
| Access control | Workspace ACL + Git permissions | Workspace ACL only |
| Size limit | 10 GB across the repository | 500 MB per file |
| Version control | Full 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.
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.
/Workspace/Users/[email protected]/my-project/
├── main_notebook.py # メインのノートブック
├── utils.py # ユーティリティ関数
├── config.yaml # 設定ファイル
├── requirements.txt # 依存パッケージ定義
└── transformations/
├── __init__.py # パッケージ化に必要
├── clean.py # データクレンジング関数
└── aggregate.py # 集約処理関数# 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.
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.
| Pattern | How | When to use | Pros | Cons |
|---|---|---|---|---|
| %pip install | Run %pip install package in the notebook | Personal experimentation, exploratory analysis | Install instantly | Version pinning tends to become loose |
| requirements.txt | List dependencies in a file and run %pip install -r | Project-level package management | Explicit versions, highly reproducible | Install takes time every run |
| Cluster libraries | Pre-install libraries via cluster configuration | Shared dependencies across the team | No %pip needed in notebooks | Requires cluster restart |
| Init Script | Auto-install with a script on cluster start | OS-dependent libraries or system configuration | Runs automatically at startup | Hard to debug, increases startup time |
| Wheel file | Build your own package into .whl and install | Distributing internal shared libraries | Fast install, clear version control | Requires setting up a build process |
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"}'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?
正解: 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.
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.
Practice with certification-focused question sets
無料で問題を解いてみる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.
Databricks Certifications: All 7 Exams, Difficulty & Study Plan (2026)
Complete guide to all 7 Databricks certifications — Data Eng...
Databricks Exam Difficulty Ranking: All 7 Certs Compared (2026)
Every Databricks certification ranked by difficulty, with st...
Databricks Study Guide: Fastest Pass Route & Time Estimates (2026)
How to pass Databricks certifications efficiently. Official ...
Databricks Data Engineer Associate: Complete Guide (2026)
Domain-by-domain breakdown of the Databricks Certified Data ...
Databricks Data Engineer Professional: Complete Guide (2026)
Tactics for the Databricks Certified Data Engineer Professio...