# xarray.DataTree.to_zarr

#### DataTree.to_zarr(store, mode='w-', encoding=None, consolidated=True, group=None, write_inherited_coords=False, compute=True, \*\*kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/datatree.py#L2181-L2253)

Write datatree contents to a Zarr store.

* **Parameters:**
  * **store** (`zarr.storage.StoreLike`) – Store or path to directory in file system
  * **mode** (`{{"w", "w-", "a", "r+", None}`, *default*: `"w-"`) – Persistence mode:
    - “w” means create (remove old if exists and write new);
    - “w-” means create (fail if exists);
    - “a” means override all existing variables including dimension coordinates (create if does not exist);
    - “r+” means modify existing array *values* only (raise an error if
      any metadata or shapes would change).

    The default mode is “w-”.

    #### NOTE
    When modifying an existing Zarr array that is lazily opened, the “w”
    behavior can be surprising since the underlying file that is being
    lazily read from might get deleted before the data is computed.
  * **encoding** ([`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), *optional*) – Nested dictionary with variable names as keys and dictionaries of
    variable specific encodings as values, e.g.,
    `{"root/set1": {"my_variable": {"dtype": "int16", "scale_factor": 0.1}, ...}, ...}`.
    See `xarray.Dataset.to_zarr` for available options.
  * **consolidated** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If True, apply zarr’s consolidate_metadata function to the store
    after writing metadata for all groups.
  * **group** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str), *optional*) – Group path. (a.k.a. path in zarr terminology.)
  * **write_inherited_coords** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`False`](https://docs.python.org/3/builtins/constants.html#False)) – If true, replicate inherited coordinates on all descendant nodes.
    Otherwise, only write coordinates at the level at which they are
    originally defined. This saves disk space, but requires opening the
    full tree to load inherited coordinates.
  * **compute** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`True`](https://docs.python.org/3/builtins/constants.html#True)) – If true compute immediately, otherwise return a
    `dask.delayed.Delayed` object that can be computed later. Metadata
    is always updated eagerly.
  * **kwargs** – Additional keyword arguments to be passed to `xarray.Dataset.to_zarr`

### Notes

Due to file format specifications the on-disk root group name
is always `"/"` overriding any given `DataTree` root node name.
