---
title: Databricks Utilities (dbutils) reference
description: Understand and learn how to use Databricks Utilities to work with files, object storage, and secrets.
canonical_url: https://docs.databricks.com/aws/en/dev-tools/databricks-utils
---

# Databricks Utilities (`dbutils`) reference

This page contains reference for Databricks Utilities (`dbutils`). The utilities provide modules with commands that enable you to work with your Databricks environment from notebooks. For example, you can manage files and object storage, and work with secrets. `dbutils` are available in Python, R, and Scala notebooks.

> [!NOTE]
>
> `dbutils` only supports compute environments that use DBFS.

## <a id="dbutils-commands" />Utility modules

The following table lists the Databricks Utilities modules, which you can retrieve using `dbutils.help()`.

| Module                                                                                              | Description                                                              |
| --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| [credentials](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-credentials) | Utilities for interacting with credentials within notebooks              |
| [data](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-data)               | Utilities for understanding and interacting with datasets (EXPERIMENTAL) |
| [fs](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs)                   | Utilities for accessing the Databricks file system (DBFS)                |
| [jobs](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-jobs)               | Utilities for leveraging job features                                    |
| [library](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-library)         | Deprecated. Utilities for managing session-scoped libraries              |
| meta                                                                                                | Utilities to hook into the compiler (EXPERIMENTAL)                       |
| [notebook](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-workflow)       | Utilities for managing the control flow of notebooks (EXPERIMENTAL)      |
| preview                                                                                             | Utilities in preview                                                     |
| [secrets](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-secrets)         | Utilities for leveraging secrets within notebooks                        |
| [widgets](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-widgets)         | Utilities for parameterizing notebooks.                                  |
| [api](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-api)                 | Utilities for managing application builds                                |

## <a id="dbutils-help" />Command help

To list commands for a utility module along with a short description of each command, append `.help()` after the name of the utility module. The following example lists available commands for the notebook utility:

```
dbutils.notebook.help()
```

```output
The notebook module.

exit(value: String): void -> This method lets you exit a notebook with a value
run(path: String, timeoutSeconds: int, arguments: Map): String -> This method runs a notebook and returns its exit value
```

To output help for a command, run `dbutils.<utility-name>.help("<command-name>")`. The following example displays help for the file system utilities copy command, `dbutils.fs.cp`:

```
dbutils.fs.help("cp")
```

```output
/**
* Copies a file or directory, possibly across FileSystems.
*
* Example: cp("/mnt/my-folder/a", "dbfs:/a/b")
*
* @param from FileSystem URI of the source file or directory
* @param to FileSystem URI of the destination file or directory
* @param recurse if true, all files and directories will be recursively copied
* @return true if all files were successfully copied
*/
cp(from: java.lang.String, to: java.lang.String, recurse: boolean = false): boolean
```

## <a id="dbutils-credentials" />Credentials utility (dbutils.credentials)

The credentials utility module contains commands to interact with credentials within notebooks. This utility is usable only on clusters with [credential passthrough](https://docs.databricks.com/aws/en/archive/credential-passthrough/iam-passthrough.md) enabled.

The following table lists the available commands for this utility, which you can retrieve using `dbutils.credentials.help()`.

| Command                                                                                                                                             | Description                                                                       |
| --------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| [assumeRole](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-credentials-assumerole)                                       | Sets the role ARN to assume when looking for credentials to authenticate with S3. |
| [getServiceCredentialsProvider](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-credentials-getservicecredentialsprovider) | Returns a service credentials provider for the given service credential.          |
| [showCurrentRole](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-credentials-showcurrentrole)                             | Shows the currently set role.                                                     |
| [showRoles](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-credentials-showroles)                                         | Shows the set of possible assumed roles.                                          |

### <a id="dbutils-credentials-assumerole" />assumeRole command (dbutils.credentials.assumeRole)

`assumeRole(role: String): boolean`

Sets the Amazon Resource Name (ARN) for the AWS Identity and Access Management (IAM) role to assume when looking for credentials to authenticate with Amazon S3. After you run this command, you can run S3 access commands, such as `sc.textFile("s3a://my-bucket/my-file.csv")` to access an object.

To display complete help for this command, run:

```
dbutils.credentials.help("assumeRole")
```

#### Example

##### Python

```python
dbutils.credentials.assumeRole("arn:aws:iam::123456789012:roles/my-role")

# Out[1]: True
```

##### R

```r
dbutils.credentials.assumeRole("arn:aws:iam::123456789012:roles/my-role")

# TRUE
```

##### Scala

```scala
dbutils.credentials.assumeRole("arn:aws:iam::123456789012:roles/my-role")

// res0: Boolean = true
```

### <a id="dbutils-credentials-getservicecredentialsprovider" />getServiceCredentialsProvider command (dbutils.credentials.getServiceCredentialsProvider)

`getServiceCredentialsProvider(credentialName: String): Object`

Returns a service credentials provider for the given service credential. The return object type is specific to the cloud provider.

To display complete help for this command, run:

```
dbutils.credentials.help("getServiceCredentialsProvider")
```

#### Example

##### Python

```python
dbutils.credentials.getServiceCredentialsProvider("my-credential")
```

##### R

This utility is not supported in R.

##### Scala

```scala
dbutils.credentials.getServiceCredentialsProvider("my-credential")
```

### <a id="dbutils-credentials-showcurrentrole" />showCurrentRole command (dbutils.credentials.showCurrentRole)

`showCurrentRole: List`

Lists the currently set AWS Identity and Access Management (IAM) role.

To display complete help for this command, run:

```
dbutils.credentials.help("showCurrentRole")
```

#### Example

##### Python

```python
dbutils.credentials.showCurrentRole()

# Out[1]: ['arn:aws:iam::123456789012:role/my-role-a']
```

##### R

```r
dbutils.credentials.showCurrentRole()

# [[1]]
# [1] "arn:aws:iam::123456789012:role/my-role-a"
```

##### Scala

```scala
dbutils.credentials.showCurrentRole()

// res0: java.util.List[String] = [arn:aws:iam::123456789012:role/my-role-a]
```

### <a id="dbutils-credentials-showroles" />showRoles command (dbutils.credentials.showRoles)

`showRoles: List`

Lists the set of possible assumed AWS Identity and Access Management (IAM) roles.

To display complete help for this command, run:

```
dbutils.credentials.help("showRoles")
```

#### Example

##### Python

```python
dbutils.credentials.showRoles()

# Out[1]: ['arn:aws:iam::123456789012:role/my-role-a', 'arn:aws:iam::123456789012:role/my-role-b']
```

##### R

```r
dbutils.credentials.showRoles()

# [[1]]
# [1] "arn:aws:iam::123456789012:role/my-role-a"
#
# [[2]]
# [1] "arn:aws:iam::123456789012:role/my-role-b"
```

##### Scala

```scala
dbutils.credentials.showRoles()

// res0: java.util.List[String] = [arn:aws:iam::123456789012:role/my-role-a, arn:aws:iam::123456789012:role/my-role-b]
```

## <a id="dbutils-data" />Data utility (dbutils.data)

> [!NOTE]
> **Preview**
>
> This feature is in [Public Preview](https://docs.databricks.com/aws/en/release-notes/release-types.md).

> [!NOTE]
>
> Available in Databricks Runtime 9.0 and above.

The data utility module contains commands to understand and interact with datasets.

The following table lists the available commands for this utility, which you can retrieve using `dbutils.data.help()`.

| Command                                                                                              | Description                                                                    |
| ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| [summarize](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-data-summarize) | Summarize a Spark DataFrame and visualize the statistics to get quick insights |

### <a id="dbutils-data-summarize" />summarize command (dbutils.data.summarize)

> [!NOTE]
>
> This feature is in [Public Preview](https://docs.databricks.com/aws/en/release-notes/release-types.md).

`summarize(df: Object, precise: boolean): void`

Calculates and displays summary statistics of an Apache Spark DataFrame or pandas DataFrame. This command is available for Python, Scala and R.

> [!IMPORTANT]
>
> This command analyzes the complete contents of the DataFrame. Running this command for very large DataFrames can be very expensive.

To display complete help for this command, run:

```
dbutils.data.help("summarize")
```

In Databricks Runtime 10.4 LTS and above, you can use the additional `precise` parameter to adjust the precision of the computed statistics.

* When `precise` is set to false (the default), some returned statistics include approximations to reduce run time.
  * The number of distinct values for categorical columns may have \~5% relative error for high-cardinality columns.
  * The frequent value counts may have an error of up to 0.01% when the number of distinct values is greater than 10000.
  * The histograms and percentile estimates may have an error of up to 0.01% relative to the total number of rows.
* When `precise` is set to true, the statistics are computed with higher precision. All statistics except for the histograms and percentiles for numeric columns are now exact.
  * The histograms and percentile estimates may have an error of up to 0.0001% relative to the total number of rows.

The tooltip at the top of the data summary output indicates the mode of the current run.

#### Example

This example displays summary statistics for an Apache Spark DataFrame with approximations enabled by default. To see the
results, run this command in a notebook. This example is based on [Sample datasets](https://docs.databricks.com/aws/en/discover/databricks-datasets.md).

##### Python

```python
df = spark.read.format('csv').load(
  '/databricks-datasets/Rdatasets/data-001/csv/ggplot2/diamonds.csv',
  header=True,
  inferSchema=True
)
dbutils.data.summarize(df)
```

##### R

```r
df <- read.df("/databricks-datasets/Rdatasets/data-001/csv/ggplot2/diamonds.csv", source = "csv", header="true", inferSchema = "true")
dbutils.data.summarize(df)
```

##### Scala

```scala
val df = spark.read.format("csv")
  .option("inferSchema", "true")
  .option("header", "true")
  .load("/databricks-datasets/Rdatasets/data-001/csv/ggplot2/diamonds.csv")
dbutils.data.summarize(df)
```

The visualization uses [SI notation](https://en.wikipedia.org/wiki/International_System_of_Units#Prefixes) to concisely render numerical values smaller than 0.01 or larger than 10000. As an example, the numerical value `1.25e-15` will be rendered as `1.25f`. One exception: the visualization uses “`B`” for `1.0e9` ([giga](https://en.wikipedia.org/wiki/Giga-)) instead of “`G`”.

## <a id="dbutils-fs" />File system utility (dbutils.fs)

The file system utility module contains commands to access [What is DBFS?](https://docs.databricks.com/aws/en/dbfs/index.md). To access [workspace files](https://docs.databricks.com/aws/en/files/workspace.md), use shell commands such as `%sh ls`, as there are some [limitations](https://docs.databricks.com/aws/en/files/workspace.md#limits) when using `dbutils.fs` commands with workspace files.

> [!WARNING]
>
> The Python implementation of all `dbutils.fs` methods uses `snake_case` rather than `camelCase` for keyword formatting.
>
> For example, `dbutils.fs.help()` displays the option `extraConfigs` for `dbutils.fs.mount()`. However, in Python you would use the keyword `extra_configs`.

The following table lists the available commands for this utility, which you can retrieve using `dbutils.fs.help()`.

| Command                                                                                                    | Description                                                                                                         |
| ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| [cp](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs-cp)                       | Copies a file or directory, possibly across FileSystems                                                             |
| [head](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs-head)                   | Returns up to the first 'max\_bytes' bytes of the given file as a String encoded in UTF-8                           |
| [ls](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs-ls)                       | Lists the contents of a directory                                                                                   |
| [mkdirs](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs-mkdirs)               | Creates the given directory if it does not exist, also creating any necessary parent directories                    |
| [mount](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs-mount)                 | Mounts the given source directory into DBFS at the given mount point                                                |
| [mounts](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs-mounts)               | Displays information about what is mounted within DBFS                                                              |
| [mv](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs-mv)                       | Moves a file or directory, possibly across FileSystems                                                              |
| [put](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs-put)                     | Writes the given String out to a file, encoded in UTF-8                                                             |
| [refreshMounts](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs-refreshmounts) | Forces all machines in this cluster to refresh their mount cache, ensuring they receive the most recent information |
| [rm](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs-rm)                       | Removes a file or directory                                                                                         |
| [unmount](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs-unmount)             | Deletes a DBFS mount point                                                                                          |
| [updateMount](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs-updatemount)     | Similar to mount(), but updates an existing mount point instead of creating a new one                               |

> [!TIP]
>
> In notebooks, you can use the `%fs` magic command to access DBFS. For example, `%fs ls /Volumes/main/default/my-volume/` is the same as `dbutils.fs.ls("/Volumes/main/default/my-volume/")`. See [magic commands](https://docs.databricks.com/aws/en/notebooks/notebooks-code.md#mix-languages).

### <a id="dbutils-fs-cp" />cp command (dbutils.fs.cp)

`cp(from: String, to: String, recurse: boolean = false): boolean`

Copies a file or directory, possibly across filesystems.

To display complete help for this command, run:

```
dbutils.fs.help("cp")
```

#### Example

This example copies the file named `data.csv` from `/Volumes/main/default/my-volume/` to `new-data.csv` in the same volume.

##### Python

```python
dbutils.fs.cp("/Volumes/main/default/my-volume/data.csv", "/Volumes/main/default/my-volume/new-data.csv")

# Out[4]: True
```

##### R

```r
dbutils.fs.cp("/Volumes/main/default/my-volume/data.csv", "/Volumes/main/default/my-volume/new-data.csv")

# [1] TRUE
```

##### Scala

```scala
dbutils.fs.cp("/Volumes/main/default/my-volume/data.csv", "/Volumes/main/default/my-volume/new-data.csv")

// res3: Boolean = true
```

### <a id="dbutils-fs-head" />head command (dbutils.fs.head)

`head(file: String, max_bytes: int = 65536): String`

Returns up to the specified maximum number of bytes in the given file. The bytes are returned as a UTF-8 encoded string.

To display complete help for this command, run:

```
dbutils.fs.help("head")
```

#### Example

This example displays the first 25 bytes of the file `data.csv` located in `/Volumes/main/default/my-volume/`.

##### Python

```python
dbutils.fs.head("/Volumes/main/default/my-volume/data.csv", 25)

# [Truncated to first 25 bytes]
# Out[12]: 'Year,First Name,County,Se'
```

##### R

```r
dbutils.fs.head("/Volumes/main/default/my-volume/data.csv", 25)

# [1] "Year,First Name,County,Se"
```

##### Scala

```scala
dbutils.fs.head("/Volumes/main/default/my-volume/data.csv", 25)

// [Truncated to first 25 bytes]
// res4: String =
// "Year,First Name,County,Se"
```

### <a id="dbutils-fs-ls" />ls command (dbutils.fs.ls)

`ls(dir: String): Seq`

Lists the contents of a directory.

To display complete help for this command, run:

```
dbutils.fs.help("ls")
```

#### Example

This example displays information about the contents of `/Volumes/main/default/my-volume/`. The `modificationTime` field is available in Databricks Runtime 10.4 LTS and above. In R, `modificationTime` is returned as a string.

##### Python

```python
dbutils.fs.ls("/Volumes/main/default/my-volume/")

# Out[13]: [FileInfo(path='dbfs:/Volumes/main/default/my-volume/data.csv', name='data.csv', size=2258987, modificationTime=1711357839000)]
```

##### R

```r
dbutils.fs.ls("/Volumes/main/default/my-volume/")

# For prettier results from dbutils.fs.ls(<dir>), please use `%fs ls <dir>`

# [[1]]
# [[1]]$path
# [1] "/Volumes/main/default/my-volume/data.csv"

# [[1]]$name
# [1] "data.csv"

# [[1]]$size
# [1] 2258987

# [[1]]$isDir
# [1] FALSE

# [[1]]$isFile
# [1] TRUE

# [[1]]$modificationTime
# [1] "1711357839000"
```

##### Scala

```scala
dbutils.fs.ls("/tmp")

// res6: Seq[com.databricks.backend.daemon.dbutils.FileInfo] = WrappedArray(FileInfo(/Volumes/main/default/my-volume/data.csv, 2258987, 1711357839000))
```

### <a id="dbutils-fs-mkdirs" />mkdirs command (dbutils.fs.mkdirs)

`mkdirs(dir: String): boolean`

Creates the given directory if it does not exist. Also creates any necessary parent directories.

To display complete help for this command, run:

```
dbutils.fs.help("mkdirs")
```

#### Example

This example creates the directory `my-data` within `/Volumes/main/default/my-volume/`.

##### Python

```python
dbutils.fs.mkdirs("/Volumes/main/default/my-volume/my-data")

# Out[15]: True
```

##### R

```r
dbutils.fs.mkdirs("/Volumes/main/default/my-volume/my-data")

# [1] TRUE
```

##### Scala

```scala
dbutils.fs.mkdirs("/Volumes/main/default/my-volume/my-data")

// res7: Boolean = true
```

### <a id="dbutils-fs-mount" />mount command (dbutils.fs.mount)

`mount(source: String, mountPoint: String, encryptionType: String = "",`
`   owner: String = null, extraConfigs: Map = Map.empty[String, String]): boolean`

Mounts the specified source directory into DBFS at the specified mount point.

> [!NOTE]
>
> Databricks recommends moving away from `dbutils.fs.mount` as it is not compatible with Databricks serverless compute architecture. Use Unity Catalog external location with external volumes instead.

To display complete help for this command, run:

```
dbutils.fs.help("mount")
```

#### Example

##### Python

```python
aws_bucket_name = "my-bucket"
mount_name = "s3-my-bucket"

dbutils.fs.mount("s3a://%s" % aws_bucket_name, "/mnt/%s" % mount_name)
```

##### Scala

```scala
val AwsBucketName = "my-bucket"
val MountName = "s3-my-bucket"

dbutils.fs.mount(s"s3a://$AwsBucketName", s"/mnt/$MountName")
```

For additional code examples, see [Connect to Amazon S3](https://docs.databricks.com/aws/en/archive/storage/amazon-s3.md).

### <a id="dbutils-fs-mounts" />mounts command (dbutils.fs.mounts)

`mounts: Seq`

Displays information about what is currently mounted within DBFS.

> [!NOTE]
>
> Databricks recommends moving away from `dbutils.fs.mounts` as it is not compatible with Databricks serverless compute architecture.

To display complete help for this command, run:

```
dbutils.fs.help("mounts")
```

#### Example

> [!WARNING]
>
> Call `dbutils.fs.refreshMounts()` on all other running clusters to propagate the new mount. See [refreshMounts command (dbutils.fs.refreshMounts)](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs-refreshmounts).

##### Python

```python
dbutils.fs.mounts()

# Out[11]: [MountInfo(mountPoint='/mnt/databricks-results', source='databricks-results', encryptionType='sse-s3')]
```

##### Scala

```scala
dbutils.fs.mounts()
```

For additional code examples, see [Connect to Amazon S3](https://docs.databricks.com/aws/en/archive/storage/amazon-s3.md).

### <a id="dbutils-fs-mv" />mv command (dbutils.fs.mv)

`mv(from: String, to: String, recurse: boolean = false): boolean`

Moves a file or directory, possibly across filesystems. A move is a copy followed by a delete, even for moves within filesystems.

To display complete help for this command, run:

```
dbutils.fs.help("mv")
```

#### Example

This example moves the file `rows.csv` from `/Volumes/main/default/my-volume/` to `/Volumes/main/default/my-volume/my-data/`.

##### Python

```python
dbutils.fs.mv("/Volumes/main/default/my-volume/rows.csv", "/Volumes/main/default/my-volume/my-data/")

# Out[2]: True
```

##### R

```r
dbutils.fs.mv("/Volumes/main/default/my-volume/rows.csv", "/Volumes/main/default/my-volume/my-data/")

# [1] TRUE
```

##### Scala

```scala
dbutils.fs.mv("/Volumes/main/default/my-volume/rows.csv", "/Volumes/main/default/my-volume/my-data/")

// res1: Boolean = true
```

### <a id="dbutils-fs-put" />put command (dbutils.fs.put)

`put(file: String, contents: String, overwrite: boolean = false): boolean`

Writes the specified string to a file. The string is UTF-8 encoded.

To display complete help for this command, run:

```
dbutils.fs.help("put")
```

#### Example

This example writes the string `Hello, Databricks!` to a file named `hello.txt` in `/Volumes/main/default/my-volume/`. If the file exists, it will be overwritten.

##### Python

```python
dbutils.fs.put("/Volumes/main/default/my-volume/hello.txt", "Hello, Databricks!", True)

# Wrote 2258987 bytes.
# Out[6]: True
```

##### R

```r
dbutils.fs.put("/Volumes/main/default/my-volume/hello.txt", "Hello, Databricks!", TRUE)

# [1] TRUE
```

##### Scala

```scala
dbutils.fs.put("/Volumes/main/default/my-volume/hello.txt", "Hello, Databricks!", true)

// Wrote 2258987 bytes.
// res2: Boolean = true
```

### <a id="dbutils-fs-refreshmounts" />refreshMounts command (dbutils.fs.refreshMounts)

`refreshMounts: boolean`

Forces all machines in the cluster to refresh their mount cache, ensuring they receive the most recent information.

To display complete help for this command, run:

```
dbutils.fs.help("refreshMounts")
```

#### Example

##### Python

```python
dbutils.fs.refreshMounts()
```

##### Scala

```scala
dbutils.fs.refreshMounts()
```

For additional code examples, see [Connect to Amazon S3](https://docs.databricks.com/aws/en/archive/storage/amazon-s3.md).

### <a id="dbutils-fs-rm" />rm command (dbutils.fs.rm)

`rm(dir: String, recurse: boolean = false): boolean`

Removes a file or directory and, optionally, all of its contents. If a file is specified, the `recurse` parameter is ignored. If a directory is specified, an error occurs when `recurse` is disabled and the directory is not empty.

To display complete help for this command, run:

```
dbutils.fs.help("rm")
```

#### Example

This example removes the entire directory `/Volumes/main/default/my-volume/my-data/` including its contents.

##### Python

```python
dbutils.fs.rm("/Volumes/main/default/my-volume/my-data/", True)

# Out[8]: True
```

##### R

```r
dbutils.fs.rm("/Volumes/main/default/my-volume/my-data/", TRUE)

# [1] TRUE
```

##### Scala

```scala
dbutils.fs.rm("/Volumes/main/default/my-volume/my-data/", true)

// res6: Boolean = true
```

### <a id="dbutils-fs-unmount" />unmount command (dbutils.fs.unmount)

`unmount(mountPoint: String): boolean`

Deletes a DBFS mount point.

> [!WARNING]
>
> To avoid errors, never modify a mount point while other jobs are reading or writing to it. After modifying a mount, always run `dbutils.fs.refreshMounts()` on all other running clusters to propagate any mount updates. See [refreshMounts command (dbutils.fs.refreshMounts)](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs-refreshmounts).

To display complete help for this command, run:

```
dbutils.fs.help("unmount")
```

#### Example

```python
dbutils.fs.unmount("/mnt/<mount-name>")
```

For additional code examples, see [Connect to Amazon S3](https://docs.databricks.com/aws/en/archive/storage/amazon-s3.md).

### <a id="dbutils-fs-updatemount" />updateMount command (dbutils.fs.updateMount)

`updateMount(source: String, mountPoint: String, encryptionType: String = "",`
`   owner: String = null, extraConfigs: Map = Map.empty[String, String]): boolean`

Similar to the `dbutils.fs.mount` command, but updates an existing mount point instead of creating a new one. Returns an error if the mount point is not present.

> [!WARNING]
>
> To avoid errors, never modify a mount point while other jobs are reading or writing to it. After modifying a mount, always run `dbutils.fs.refreshMounts()` on all other running clusters to propagate any mount updates. See [refreshMounts command (dbutils.fs.refreshMounts)](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-fs-refreshmounts).

This command is available in Databricks Runtime 10.4 LTS and above.

To display complete help for this command, run:

```
dbutils.fs.help("updateMount")
```

#### Example

##### Python

```python
aws_bucket_name = "my-bucket"
mount_name = "s3-my-bucket"

dbutils.fs.updateMount("s3a://%s" % aws_bucket_name, "/mnt/%s" % mount_name)
```

##### Scala

```scala
val AwsBucketName = "my-bucket"
val MountName = "s3-my-bucket"

dbutils.fs.updateMount(s"s3a://$AwsBucketName", s"/mnt/$MountName")
```

## <a id="dbutils-jobs" />Jobs utility (dbutils.jobs)

The jobs utility module contains jobs features commands.

> [!NOTE]
>
> This utility is available only for Python.

The following table lists the available modules for this utility, which you can retrieve using `dbutils.jobs.help()`.

| Submodule                                                                                              | Description                                       |
| ------------------------------------------------------------------------------------------------------ | ------------------------------------------------- |
| [taskValues](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-jobs-taskvalues) | Provides utilities for leveraging job task values |

### <a id="dbutils-jobs-taskvalues" />taskValues subutility (dbutils.jobs.taskValues)

> [!NOTE]
>
> This subutility is available only for Python.

Provides commands for leveraging job task values.

Use this sub-utility to set and get arbitrary values during a job run. These values are called *task values*. Any task can get values set by upstream tasks and set values for downstream tasks to use.

Each task value has a unique key within the same task. This unique key is known as the task value's key. A task value is accessed with the task name and the task value's key. You can use this to pass information downstream from task to task within the same job run. For example, you can pass identifiers or metrics, such as information about the evaluation of a machine learning model, between different tasks within a job run.

The following table lists available commands for this subutility, which you can retrieve using `dbutils.jobs.taskValues.help()`.

| Command                                                                                             | Description                                                                                  |
| --------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| [get](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-jobs-taskvalues-get) | Gets the contents of the specified task value for the specified task in the current job run. |
| [set](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-jobs-taskvalues-set) | Sets or updates a task value. You can set up to 250 task values for a job run.               |

#### <a id="dbutils-jobs-taskvalues-get" />get command (dbutils.jobs.taskValues.get)

> [!NOTE]
>
> This command is available only for Python.
>
> On Databricks Runtime 10.4 and earlier, if `get` cannot find the task, a [Py4JJavaError](https://www.py4j.org/py4j_java_protocol.html#py4jjavaerror) is raised instead of a `ValueError`.

`get(taskKey: String, key: String, default: int, debugValue: int): Seq`

Gets the contents of the specified task value for the specified task in the current job run.

When the specified task ran inside a `For each` task, `get` returns a list with one element per iteration, ordered by iteration index, instead of a single value. See [Read values from a `For each` task's iterations](https://docs.databricks.com/aws/en/jobs/task-values.md#for-each-outputs).

To display complete help for this command, run:

```
dbutils.jobs.taskValues.help("get")
```

#### Example

For example:

```python
dbutils.jobs.taskValues.get(taskKey    = "my-task", \
                            key        = "my-key", \
                            default    = 7, \
                            debugValue = 42)
```

In the preceding example:

* `taskKey` is the name of the task that sets the task value. If the command cannot find this task, a `ValueError` is raised.
* `key` is the name of the task value's key that you set with the [set command (dbutils.jobs.taskValues.set)](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-jobs-taskvalues-set). If the command cannot find this task value's key, a `ValueError` is raised (unless `default` is specified).
* `default` is an optional value that is returned if `key` cannot be found. `default` cannot be `None`.
* `debugValue` is an optional value that is returned if you try to get the task value from within a notebook that is running outside of a job. This can be useful during debugging when you want to run your notebook manually and return some value instead of raising a `TypeError` by default. `debugValue` cannot be `None`.

If you try to get a task value from within a notebook that is running outside of a job, this command raises a `TypeError` by default. However, if the `debugValue` argument is specified in the command, the value of `debugValue` is returned instead of raising a `TypeError`.

#### <a id="dbutils-jobs-taskvalues-set" />set command (dbutils.jobs.taskValues.set)

> [!NOTE]
>
> This command is available only for Python.

`set(key: String, value: String): boolean`

Sets or updates a task value. You can set up to 250 task values for a job run.

To display complete help for this command, run:

```
dbutils.jobs.taskValues.help("set")
```

#### Example

Some examples include:

```python
dbutils.jobs.taskValues.set(key   = "my-key", \
                            value = 5)

dbutils.jobs.taskValues.set(key   = "my-other-key", \
                            value = "my other value")
```

In the preceding examples:

* `key` is the task value's key. This key must be unique to the task. That is, if two different tasks each set a task value with key `K`, these are two different task values that have the same key `K`.
* `value` is the value for this task value's key. This command must be able to represent the value internally in JSON format. The size of the JSON representation of the value cannot exceed 48 KiB.

If you try to set a task value from within a notebook that is running outside of a job, this command does nothing.

## <a id="dbutils-library" />Library utility (dbutils.library)

Most methods in the `dbutils.library` module are deprecated. The `install` and `installPyPI` methods are removed in Databricks Runtime 11.0 and above. See [Library utility (dbutils.library) (legacy)](https://docs.databricks.com/aws/en/archive/dev-tools/dbutils-library.md).

You might need to programmatically restart the Python process on Databricks to ensure that locally installed or upgraded libraries function correctly in the Python kernel for your current SparkSession. To do this, run the `dbutils.library.restartPython` command. See [Restart the Python process on Databricks](https://docs.databricks.com/aws/en/libraries/restart-python-process.md).

## <a id="dbutils-workflow" />Notebook utility (dbutils.notebook)

The notebook utility module contains commands to chain together notebooks and act on their results. See [Orchestrate Databricks notebooks and modularize code](https://docs.databricks.com/aws/en/notebooks/notebook-workflows.md).

The following table lists the available commands for this utility, which you can retrieve using `dbutils.notebook.help()`.

| Command                                                                                        | Description                                |
| ---------------------------------------------------------------------------------------------- | ------------------------------------------ |
| [exit](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-workflow-exit) | Exits a notebook with a value              |
| [run](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-workflow-run)   | Runs a notebook and returns its exit value |

### <a id="dbutils-workflow-exit" />exit command (dbutils.notebook.exit)

`exit(value: String): void`

Exits a notebook with a value.

To display complete help for this command, run:

```
dbutils.notebook.help("exit")
```

#### Example

This example exits the notebook with the value `Exiting from My Other Notebook`.

##### Python

```python
dbutils.notebook.exit("Exiting from My Other Notebook")

# Notebook exited: Exiting from My Other Notebook
```

##### R

```r
dbutils.notebook.exit("Exiting from My Other Notebook")

# Notebook exited: Exiting from My Other Notebook
```

##### Scala

```scala
dbutils.notebook.exit("Exiting from My Other Notebook")

// Notebook exited: Exiting from My Other Notebook
```

> [!NOTE]
>
> If the run has a query with [structured streaming](https://docs.databricks.com/aws/en/structured-streaming/production.md) running in the background, calling `dbutils.notebook.exit()` does not terminate the run. The run will continue to execute for as long as the query is executing in the background. You can stop the query running in the background by clicking **Cancel** in the cell of the query or by running `query.stop()`. When the query stops, you can terminate the run with `dbutils.notebook.exit()`.

### <a id="dbutils-workflow-run" />run command (dbutils.notebook.run)

`run(path: String, timeoutSeconds: int, arguments: Map): String`

Runs a notebook and returns its exit value. The notebook will run in the current cluster.

> [!NOTE]
>
> The maximum length of the string value returned from the `run` command is 5 MB. See [Get the output for a single run](https://docs.databricks.com/api/workspace/jobs) (`GET /jobs/runs/get-output`).

To display complete help for this command, run:

```
dbutils.notebook.help("run")
```

#### Example

This example runs a notebook named `My Other Notebook` in the same location as the calling notebook. The called notebook ends with the line of code `dbutils.notebook.exit("Exiting from My Other Notebook")`. If the called notebook does not finish running within 60 seconds, an exception is thrown.

##### Python

```python
dbutils.notebook.run("My Other Notebook", 60)

# Out[14]: 'Exiting from My Other Notebook'
```

##### Scala

```scala
dbutils.notebook.run("My Other Notebook", 60)

// res2: String = Exiting from My Other Notebook
```

## <a id="dbutils-secrets" />Secrets utility (dbutils.secrets)

The secrets utility module contains commands to store and access sensitive credential information without making them visible in notebooks. See [Secret management](https://docs.databricks.com/aws/en/security/secrets/index.md) and [Read a secret](https://docs.databricks.com/aws/en/security/secrets/unity-catalog-secrets.md#read-a-secret).

The `get`, `getBytes`, and `list` commands work with both workspace secret scopes and Unity Catalog secrets. To read a workspace secret, pass a scope and key. To read a Unity Catalog secret, pass a catalog, schema, and key. Unity Catalog secrets are supported in Python and Scala. For compute requirements, see [Requirements](https://docs.databricks.com/aws/en/security/secrets/unity-catalog-secrets.md#requirements).

The following table lists the available commands for this utility, which you can retrieve using `dbutils.secrets.help()`.

| Command                                                                                                   | Description                                                                                           |
| --------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| [get](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-secrets-get)               | Gets the string representation of a secret value with scope and key, or with catalog, schema, and key |
| [getBytes](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-secrets-getbytes)     | Gets the bytes representation of a secret value with scope and key, or with catalog, schema, and key  |
| [list](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-secrets-list)             | Lists secret metadata for secrets within a scope, or within a catalog and schema                      |
| [listScopes](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-secrets-listscopes) | Lists secret scopes                                                                                   |

### <a id="dbutils-secrets-get" />get command (dbutils.secrets.get)

`get(scope: String, key: String): String`

`get(catalog: String, schema: String, key: String): String`

Gets the string representation of a secret value for the specified secrets scope and key, or for the specified Unity Catalog catalog, schema, and secret name.

> [!WARNING]
>
> Administrators, secret creators, and users granted [permission](https://docs.databricks.com/aws/en/security/secrets/workspace-secret-scopes.md#permissions) can read Databricks secrets. While
> Databricks makes an effort to redact secret values that might be displayed in notebooks, it is not possible to prevent such users from reading secrets. For more information, see [Secret redaction](https://docs.databricks.com/aws/en/security/secrets/workspace-secret-scopes.md#redaction).
>
> To read a Unity Catalog secret value, you need ownership of the secret, or `READ SECRET` on the secret or on its schema or catalog. See [Read a secret](https://docs.databricks.com/aws/en/security/secrets/unity-catalog-secrets.md#read-a-secret).

To display complete help for this command, run:

```
dbutils.secrets.help("get")
```

#### Example

This example gets the string representation of the secret value for the scope named `my-scope` and the key named `my-key`.

##### Python

```python
dbutils.secrets.get(scope="my-scope", key="my-key")

# Out[14]: '[REDACTED]'
```

##### R

```r
dbutils.secrets.get(scope="my-scope", key="my-key")

# [1] "[REDACTED]"
```

##### Scala

```scala
dbutils.secrets.get(scope="my-scope", key="my-key")

// res0: String = [REDACTED]
```

This example gets the string representation of the Unity Catalog secret named `db_password` in the `main.orders_app` schema.

##### Python

```python
dbutils.secrets.get(catalog="main", schema="orders_app", key="db_password")

# Out[15]: '[REDACTED]'
```

##### Scala

```scala
dbutils.secrets.get(catalog="main", schema="orders_app", key="db_password")

// res1: String = [REDACTED]
```

### <a id="dbutils-secrets-getbytes" />getBytes command (dbutils.secrets.getBytes)

`getBytes(scope: String, key: String): byte[]`

`getBytes(catalog: String, schema: String, key: String): byte[]`

Gets the bytes representation of a secret value for the specified scope and key, or for the specified Unity Catalog catalog, schema, and secret name.

To display complete help for this command, run:

```
dbutils.secrets.help("getBytes")
```

#### Example

This example gets the byte representation of the secret value (in this example, `a1!b2@c3#`) for the scope named `my-scope` and the key named `my-key`.

##### Python

```python
dbutils.secrets.getBytes(scope="my-scope", key="my-key")

# Out[1]: b'a1!b2@c3#'
```

##### R

```r
dbutils.secrets.getBytes(scope="my-scope", key="my-key")

# [1] 61 31 21 62 32 40 63 33 23
```

##### Scala

```scala
dbutils.secrets.getBytes(scope="my-scope", key="my-key")

// res1: Array[Byte] = Array(97, 49, 33, 98, 50, 64, 99, 51, 35)
```

This example gets the byte representation of the Unity Catalog secret named `db_password` in the `main.orders_app` schema.

##### Python

```python
dbutils.secrets.getBytes(catalog="main", schema="orders_app", key="db_password")

# Out[2]: b'a1!b2@c3#'
```

##### Scala

```scala
dbutils.secrets.getBytes(catalog="main", schema="orders_app", key="db_password")

// res2: Array[Byte] = Array(97, 49, 33, 98, 50, 64, 99, 51, 35)
```

### <a id="dbutils-secrets-list" />list command (dbutils.secrets.list)

`list(scope: String): Seq`

`list(catalog: String, schema: String): Seq`

Lists the metadata for secrets within the specified scope, or for the Unity Catalog secrets within the specified catalog and schema. For Unity Catalog secrets, `list` can return secrets that you can't read with `get` or `getBytes`.

To display complete help for this command, run:

```
dbutils.secrets.help("list")
```

#### Example

This example lists the metadata for secrets within the scope named `my-scope`.

##### Python

```python
dbutils.secrets.list("my-scope")

# Out[10]: [SecretMetadata(key='my-key')]
```

##### R

```r
dbutils.secrets.list("my-scope")

# [[1]]
# [[1]]$key
# [1] "my-key"
```

##### Scala

```scala
dbutils.secrets.list("my-scope")

// res2: Seq[com.databricks.dbutils_v1.SecretMetadata] = ArrayBuffer(SecretMetadata(my-key))
```

This example lists the metadata for Unity Catalog secrets within the `main.orders_app` schema.

##### Python

```python
dbutils.secrets.list(catalog="main", schema="orders_app")

# Out[11]: [SecretMetadata(key='main.orders_app.db_password'), SecretMetadata(key='main.orders_app.db_username')]
```

##### Scala

```scala
dbutils.secrets.list(catalog="main", schema="orders_app")

// res3: Seq[com.databricks.dbutils_v1.SecretMetadata] = ArrayBuffer(SecretMetadata(main.orders_app.db_password), SecretMetadata(main.orders_app.db_username))
```

### <a id="dbutils-secrets-listscopes" />listScopes command (dbutils.secrets.listScopes)

`listScopes: Seq`

Lists the available scopes.

To display complete help for this command, run:

```
dbutils.secrets.help("listScopes")
```

#### Example

This example lists the available scopes.

##### Python

```python
dbutils.secrets.listScopes()

# Out[14]: [SecretScope(name='my-scope')]
```

##### R

```r
dbutils.secrets.listScopes()

# [[1]]
# [[1]]$name
# [1] "my-scope"
```

##### Scala

```scala
dbutils.secrets.listScopes()

// res3: Seq[com.databricks.dbutils_v1.SecretScope] = ArrayBuffer(SecretScope(my-scope))
```

## <a id="dbutils-widgets" />Widgets utility (dbutils.widgets)

The widgets utility module contains commands to parameterize notebooks. See [Databricks widgets](https://docs.databricks.com/aws/en/notebooks/widgets.md).

The following table lists the available commands for this utility, which you can retrieve using `dbutils.widgets.help()`.

| Command                                                                                                     | Description                                                                      |
| ----------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| [combobox](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-widgets-combobox)       | Creates a combobox input widget with a given name, default value, and choices    |
| [dropdown](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-widgets-dropdown)       | Creates a dropdown input widget a with given name, default value, and choices    |
| [get](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-widgets-get)                 | Retrieves current value of an input widget                                       |
| [getAll](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-widgets-getall)           | Retrieves a map of all widget names and their values                             |
| [getArgument](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-widgets-getargument) | Deprecated. Equivalent to get                                                    |
| [multiselect](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-widgets-multiselect) | Creates a multiselect input widget with a given name, default value, and choices |
| [remove](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-widgets-remove)           | Removes an input widget from the notebook                                        |
| [removeAll](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-widgets-removeall)     | Removes all widgets in the notebook                                              |
| [text](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-widgets-text)               | Creates a text input widget with a given name and default value                  |

### <a id="dbutils-widgets-combobox" />combobox command (dbutils.widgets.combobox)

`combobox(name: String, defaultValue: String, choices: Seq, label: String): void`

Creates and displays a combobox widget with the specified programmatic name, default value, choices, and optional label.

To display complete help for this command, run:

```
dbutils.widgets.help("combobox")
```

#### Example

This example creates and displays a combobox widget with the programmatic name `fruits_combobox`. It offers the choices `apple`, `banana`, `coconut`, and `dragon fruit` and is set to the initial value of `banana`. This combobox widget has an accompanying label `Fruits`. This example ends by printing the initial value of the combobox widget, `banana`.

##### Python

```python
dbutils.widgets.combobox(
  name='fruits_combobox',
  defaultValue='banana',
  choices=['apple', 'banana', 'coconut', 'dragon fruit'],
  label='Fruits'
)

print(dbutils.widgets.get("fruits_combobox"))

# banana
```

##### R

```r
dbutils.widgets.combobox(
  name='fruits_combobox',
  defaultValue='banana',
  choices=list('apple', 'banana', 'coconut', 'dragon fruit'),
  label='Fruits'
)

print(dbutils.widgets.get("fruits_combobox"))

# [1] "banana"
```

##### Scala

```scala
dbutils.widgets.combobox(
  "fruits_combobox",
  "banana",
  Array("apple", "banana", "coconut", "dragon fruit"),
  "Fruits"
)

print(dbutils.widgets.get("fruits_combobox"))

// banana
```

##### SQL

```sql
CREATE WIDGET COMBOBOX fruits_combobox DEFAULT "banana" CHOICES SELECT * FROM (VALUES ("apple"), ("banana"), ("coconut"), ("dragon fruit"))

SELECT :fruits_combobox

-- banana
```

### <a id="dbutils-widgets-dropdown" />dropdown command (dbutils.widgets.dropdown)

`dropdown(name: String, defaultValue: String, choices: Seq, label: String): void`

Creates and displays a dropdown widget with the specified programmatic name, default value, choices, and optional label.

To display complete help for this command, run:

```
dbutils.widgets.help("dropdown")
```

#### Example

This example creates and displays a dropdown widget with the programmatic name `toys_dropdown`. It offers the choices `alphabet blocks`, `basketball`, `cape`, and `doll` and is set to the initial value of `basketball`. This dropdown widget has an accompanying label `Toys`. This example ends by printing the initial value of the dropdown widget, `basketball`.

##### Python

```python
dbutils.widgets.dropdown(
  name='toys_dropdown',
  defaultValue='basketball',
  choices=['alphabet blocks', 'basketball', 'cape', 'doll'],
  label='Toys'
)

print(dbutils.widgets.get("toys_dropdown"))

# basketball
```

##### R

```r
dbutils.widgets.dropdown(
  name='toys_dropdown',
  defaultValue='basketball',
  choices=list('alphabet blocks', 'basketball', 'cape', 'doll'),
  label='Toys'
)

print(dbutils.widgets.get("toys_dropdown"))

# [1] "basketball"
```

##### Scala

```scala
dbutils.widgets.dropdown(
  "toys_dropdown",
  "basketball",
  Array("alphabet blocks", "basketball", "cape", "doll"),
  "Toys"
)

print(dbutils.widgets.get("toys_dropdown"))

// basketball
```

##### SQL

```sql
CREATE WIDGET DROPDOWN toys_dropdown DEFAULT "basketball" CHOICES SELECT * FROM (VALUES ("alphabet blocks"), ("basketball"), ("cape"), ("doll"))

SELECT :toys_dropdown

-- basketball
```

### <a id="dbutils-widgets-get" />get command (dbutils.widgets.get)

`get(name: String): String`

Gets the current value of the widget with the specified programmatic name. This programmatic name can be either:

* The name of a custom widget in the notebook, for example, `fruits_combobox` or `toys_dropdown`.
* The name of a custom parameter passed to the notebook as part of a notebook task, for example `name` or `age`. For more information, see the coverage of [parameters for notebook tasks](https://docs.databricks.com/aws/en/jobs/task-parameters.md) in the jobs UI or the `notebook_params` field in the [Trigger a new job run](https://docs.databricks.com/api/workspace/jobs) (`POST /jobs/run-now`) operation in the Jobs API.

To display complete help for this command, run:

```
dbutils.widgets.help("get")
```

#### Example

This example gets the value of the widget that has the programmatic name `fruits_combobox`.

##### Python

```python
dbutils.widgets.get('fruits_combobox')

# banana
```

##### R

```r
dbutils.widgets.get('fruits_combobox')

# [1] "banana"
```

##### Scala

```scala
dbutils.widgets.get("fruits_combobox")

// res6: String = banana
```

##### SQL

```sql
SELECT :fruits_combobox

-- banana
```

This example gets the value of the notebook task parameter that has the programmatic name `age`. This parameter was set to `35` when the related notebook task was run.

##### Python

```python
dbutils.widgets.get('age')

# 35
```

##### R

```r
dbutils.widgets.get('age')

# [1] "35"
```

##### Scala

```scala
dbutils.widgets.get("age")

// res6: String = 35
```

##### SQL

```sql
SELECT :age

-- 35
```

### <a id="dbutils-widgets-getall" />getAll command (dbutils.widgets.getAll)

`getAll: map`

Gets a mapping of all current widget names and values. This can be especially useful to quickly pass widget values to a `spark.sql()` query.

This command is available in Databricks Runtime 13.3 LTS and above. It is only available for Python and Scala.

To display complete help for this command, run:

```
dbutils.widgets.help("getAll")
```

#### Example

This example gets the map of widget values and passes it as parameter arguments in a Spark SQL query.

##### Python

```python
df = spark.sql("SELECT * FROM table where col1 = :param", dbutils.widgets.getAll())
df.show()

# Query output
```

##### Scala

```scala
val df = spark.sql("SELECT * FROM table where col1 = :param", dbutils.widgets.getAll())
df.show()

// res6: Query output
```

### <a id="dbutils-widgets-getargument" />getArgument command (dbutils.widgets.getArgument)

`getArgument(name: String, optional: String): String`

Gets the current value of the widget with the specified programmatic name. If the widget does not exist, an optional message can be returned.

> [!NOTE]
>
> This command is deprecated. Use [dbutils.widgets.get](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-widgets-get) instead.

To display complete help for this command, run:

```
dbutils.widgets.help("getArgument")
```

#### Example

This example gets the value of the widget that has the programmatic name `fruits_combobox`. If this widget does not exist, the message `Error: Cannot find fruits combobox` is returned.

##### Python

```python
dbutils.widgets.getArgument('fruits_combobox', 'Error: Cannot find fruits combobox')

# Deprecation warning: Use dbutils.widgets.text() or dbutils.widgets.dropdown() to create a widget and dbutils.widgets.get() to get its bound value.
# Out[3]: 'banana'
```

##### R

```r
dbutils.widgets.getArgument('fruits_combobox', 'Error: Cannot find fruits combobox')

# Deprecation warning: Use dbutils.widgets.text() or dbutils.widgets.dropdown() to create a widget and dbutils.widgets.get() to get its bound value.
# [1] "banana"
```

##### Scala

```scala
dbutils.widgets.getArgument("fruits_combobox", "Error: Cannot find fruits combobox")

// command-1234567890123456:1: warning: method getArgument in trait WidgetsUtils is deprecated: Use dbutils.widgets.text() or dbutils.widgets.dropdown() to create a widget and dbutils.widgets.get() to get its bound value.
// dbutils.widgets.getArgument("fruits_combobox", "Error: Cannot find fruits combobox")
//                 ^
// res7: String = banana
```

### <a id="dbutils-widgets-multiselect" />multiselect command (dbutils.widgets.multiselect)

`multiselect(name: String, defaultValue: String, choices: Seq, label: String): void`

Creates and displays a multiselect widget with the specified programmatic name, default value, choices, and optional label.

To display complete help for this command, run:

```
dbutils.widgets.help("multiselect")
```

#### Example

This example creates and displays a multiselect widget with the programmatic name `days_multiselect`. It offers the choices `Monday` through `Sunday` and is set to the initial value of `Tuesday`. This multiselect widget has an accompanying label `Days of the Week`. This example ends by printing the initial value of the multiselect widget, `Tuesday`.

##### Python

```python
dbutils.widgets.multiselect(
  name='days_multiselect',
  defaultValue='Tuesday',
  choices=['Monday', 'Tuesday', 'Wednesday', 'Thursday',
    'Friday', 'Saturday', 'Sunday'],
  label='Days of the Week'
)

print(dbutils.widgets.get("days_multiselect"))

# Tuesday
```

##### R

```r
dbutils.widgets.multiselect(
  name='days_multiselect',
  defaultValue='Tuesday',
  choices=list('Monday', 'Tuesday', 'Wednesday', 'Thursday',
    'Friday', 'Saturday', 'Sunday'),
  label='Days of the Week'
)

print(dbutils.widgets.get("days_multiselect"))

# [1] "Tuesday"
```

##### Scala

```scala
dbutils.widgets.multiselect(
  "days_multiselect",
  "Tuesday",
  Array("Monday", "Tuesday", "Wednesday", "Thursday",
    "Friday", "Saturday", "Sunday"),
  "Days of the Week"
)

print(dbutils.widgets.get("days_multiselect"))

// Tuesday
```

##### SQL

```sql
CREATE WIDGET MULTISELECT days_multiselect DEFAULT "Tuesday" CHOICES SELECT * FROM (VALUES ("Monday"), ("Tuesday"), ("Wednesday"), ("Thursday"), ("Friday"), ("Saturday"), ("Sunday"))

SELECT :days_multiselect

-- Tuesday
```

### <a id="dbutils-widgets-remove" />remove command (dbutils.widgets.remove)

`remove(name: String): void`

Removes the widget with the specified programmatic name.

To display complete help for this command, run:

```
dbutils.widgets.help("remove")
```

> [!IMPORTANT]
>
> If you add a command to remove a widget, you cannot add a subsequent command to create a widget in the same cell. You must create the widget in another cell.

#### Example

This example removes the widget with the programmatic name `fruits_combobox`.

##### Python

```python
dbutils.widgets.remove('fruits_combobox')
```

##### R

```r
dbutils.widgets.remove('fruits_combobox')
```

##### Scala

```scala
dbutils.widgets.remove("fruits_combobox")
```

##### SQL

```sql
REMOVE WIDGET fruits_combobox
```

### <a id="dbutils-widgets-removeall" />removeAll command (dbutils.widgets.removeAll)

`removeAll: void`

Removes all widgets from the notebook.

To display complete help for this command, run:

```
dbutils.widgets.help("removeAll")
```

> [!IMPORTANT]
>
> If you add a command to remove all widgets, you cannot add a subsequent command to create any widgets in the same cell. You must create the widgets in another cell.

#### Example

This example removes all widgets from the notebook.

##### Python

```python
dbutils.widgets.removeAll()
```

##### R

```r
dbutils.widgets.removeAll()
```

##### Scala

```scala
dbutils.widgets.removeAll()
```

### <a id="dbutils-widgets-text" />text command (dbutils.widgets.text)

`text(name: String, defaultValue: String, label: String): void`

Creates and displays a text widget with the specified programmatic name, default value, and optional label.

To display complete help for this command, run:

```
dbutils.widgets.help("text")
```

#### Example

This example creates and displays a text widget with the programmatic name `your_name_text`. It is set to the initial value of `Enter your name`. This text widget has an accompanying label `Your name`. This example ends by printing the initial value of the text widget, `Enter your name`.

##### Python

```python
dbutils.widgets.text(
  name='your_name_text',
  defaultValue='Enter your name',
  label='Your name'
)

print(dbutils.widgets.get("your_name_text"))

# Enter your name
```

##### R

```r
dbutils.widgets.text(
  name='your_name_text',
  defaultValue='Enter your name',
  label='Your name'
)

print(dbutils.widgets.get("your_name_text"))

# [1] "Enter your name"
```

##### Scala

```scala
dbutils.widgets.text(
  "your_name_text",
  "Enter your name",
  "Your name"
)

print(dbutils.widgets.get("your_name_text"))

// Enter your name
```

##### SQL

```sql
CREATE WIDGET TEXT your_name_text DEFAULT "Enter your name"

SELECT :your_name_text

-- Enter your name
```

## <a id="dbutils-api" />Databricks Utilities API library

> [!IMPORTANT]
>
> The Databricks Utilities API (`dbutils-api`) library is [deprecated](https://docs.databricks.com/aws/en/release-notes/runtime/databricks-runtime-ver.md#platform-feature-lifecycle). Databricks recommends that you use one of the following instead:
>
> * [Databricks Utilities for Python](https://docs.databricks.com/aws/en/dev-tools/sdk-python.md#dbutils)
> * [Databricks Utilities for Scala, with Java](https://docs.databricks.com/aws/en/dev-tools/sdk-java.md#dbutils-java)
> * [Databricks Utilities for Scala, with Scala](https://docs.databricks.com/aws/en/dev-tools/sdk-java.md#dbutils-scala)

To accelerate application development, it can be helpful to compile, build, and test applications before you deploy them as production jobs. To enable you to compile against Databricks Utilities, Databricks provides the `dbutils-api` library. You can download the `dbutils-api` library from the [DBUtils API](https://mvnrepository.com/artifact/com.databricks/dbutils-api) webpage on the Maven Repository website or include the library by adding a dependency to your build file:

* SBT

  ```scala
  libraryDependencies += "com.databricks" % "dbutils-api_TARGET" % "VERSION"
  ```

* Maven

  ```xml
  <dependency>
      <groupId>com.databricks</groupId>
      <artifactId>dbutils-api_TARGET</artifactId>
      <version>VERSION</version>
  </dependency>
  ```

* Gradle

  ```bash
  compile 'com.databricks:dbutils-api_TARGET:VERSION'
  ```

Replace `TARGET` with the desired target (for example, `2.12`) and `VERSION` with the desired version (for example, `0.0.5`). For a list of available targets and versions, see the [DBUtils API](https://mvnrepository.com/artifact/com.databricks/dbutils-api) webpage on the Maven Repository website.

Once you build your application against this library, you can deploy the application.

> [!IMPORTANT]
>
> The `dbutils-api` library only allows you to locally compile an application that uses `dbutils`, not to run it. To run the application, you must deploy it in Databricks.

## Limitations

Calling `dbutils` inside of executors can produce unexpected results or errors.

If you need to run file system operations on executors using `dbutils`, refer to [Parallelize filesystem operations](https://kb.databricks.com/dbfs/parallelize-fs-operations.html).

For information about executors, see [Cluster Mode Overview](https://spark.apache.org/docs/latest/cluster-overview.html) on the Apache Spark website.
