# xarray.save_mfdataset

### xarray.save_mfdataset(datasets, paths, mode='w', format=None, groups=None, engine=None, compute=True, \*\*kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/backends/writers.py#L498-L635)

Write multiple datasets to disk as netCDF files simultaneously.

This function is intended for use with datasets consisting of dask.array
objects, in which case it can write the multiple datasets to disk
simultaneously using a shared thread pool.

When not using dask, it is no different than calling `to_netcdf`
repeatedly.

* **Parameters:**
  * **datasets** ([`list`](https://docs.python.org/3/builtins/stdtypes.html#list) of [`Dataset`](xarray.Dataset.html.md#xarray.Dataset)) – List of datasets to save.
  * **paths** ([`list`](https://docs.python.org/3/builtins/stdtypes.html#list) of [`str`](https://docs.python.org/3/builtins/stdtypes.html#str) or [`list`](https://docs.python.org/3/builtins/stdtypes.html#list) of `path-like objects`) – List of paths to which to save each corresponding dataset.
  * **mode** (`{"w", "a"}`, *optional*) – Write (“w”) or append (“a”) mode. If mode=”w”, any existing file at
    these locations will be overwritten.
  * **format** (`{"NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT", "NETCDF3_CLASSIC"}`, *optional*) – File format for the resulting netCDF file:
    * NETCDF4: Data is stored in an HDF5 file, using netCDF4 API
      features.
    * NETCDF4_CLASSIC: Data is stored in an HDF5 file, using only
      netCDF 3 compatible API features.
    * NETCDF3_64BIT: 64-bit offset version of the netCDF 3 file format,
      which fully supports 2+ GB files, but is only compatible with
      clients linked against netCDF version 3.6.0 or later.
    * NETCDF3_CLASSIC: The classic netCDF 3 file format. It does not
      handle 2+ GB files very well.

    All formats are supported by the netCDF4-python library.
    scipy.io.netcdf only supports the last two formats.

    The default format is NETCDF4 if you are saving a file to disk and
    have the netCDF4-python library available. Otherwise, xarray falls
    back to using scipy to write netCDF files and defaults to the
    NETCDF3_64BIT format (scipy does not support netCDF4).
  * **groups** ([`list`](https://docs.python.org/3/builtins/stdtypes.html#list) of [`str`](https://docs.python.org/3/builtins/stdtypes.html#str), *optional*) – Paths to the netCDF4 group in each corresponding file to which to save
    datasets (only works for format=”NETCDF4”). The groups will be created
    if necessary.
  * **engine** (`{"netcdf4", "h5netcdf", "scipy"}`, *optional*) – Engine to use when writing netCDF files. If not provided, the
    default engine is chosen based on available dependencies, by default
    preferring “netcdf4” over “h5netcdf” over “scipy” (customizable via
    `netcdf_engine_order` in `xarray.set_options()`).
  * **compute** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If true compute immediately, otherwise return a
    `dask.delayed.Delayed` object that can be computed later.
  * **\*\*kwargs** ([`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), *optional*) – Additional arguments are passed along to `to_netcdf`.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('40a1ed47-2d73-4f8e-b64b-60e3728de4a6','6c456dcd-d8df-4295-9b90-7a7b2c0e247e','35ffd07b-e3d1-487e-86c0-0c467d376c52','../lite/tree/../notebooks/index.html?path=75af0f02_5573_4c5a_8ab5_0747b9ea4984.ipynb','None')">Try it in your browser!</button></div>

Save a dataset into one netCDF per year of data:

```pycon
>>> ds = xr.Dataset(
...     {"a": ("time", np.linspace(0, 1, 48))},
...     coords={"time": pd.date_range("2010-01-01", freq="ME", periods=48)},
... )
>>> ds
<xarray.Dataset> Size: 768B
Dimensions:  (time: 48)
Coordinates:
  * time     (time) datetime64[us] 384B 2010-01-31 2010-02-28 ... 2013-12-31
Data variables:
    a        (time) float64 384B 0.0 0.02128 0.04255 ... 0.9574 0.9787 1.0
>>> years, datasets = zip(*ds.groupby("time.year"))
>>> paths = [f"{y}.nc" for y in years]
>>> xr.save_mfdataset(datasets, paths)
```

<div id="35ffd07b-e3d1-487e-86c0-0c467d376c52" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('40a1ed47-2d73-4f8e-b64b-60e3728de4a6','35ffd07b-e3d1-487e-86c0-0c467d376c52')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('40a1ed47-2d73-4f8e-b64b-60e3728de4a6','35ffd07b-e3d1-487e-86c0-0c467d376c52')">Open In Tab</button></div><div id="6c456dcd-d8df-4295-9b90-7a7b2c0e247e" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
