Skip to content

 zarr.open

zarr.open

open(
    store: StoreLike | None = None,
    *,
    mode: AccessModeLiteral | None = None,
    zarr_format: ZarrFormat | None = None,
    path: str | None = None,
    storage_options: dict[str, Any] | None = None,
    **kwargs: Any,
) -> AnyArray | Group

Open a group or array using file-mode-like semantics.

Parameters:

  • store (StoreLike or None, default: None ) –

    StoreLike object to open. See the storage documentation in the user guide for a description of all valid StoreLike values.

  • mode (('r', 'r+', 'a', 'w', 'w-'), default: 'r' ) –

    Persistence mode: 'r' means read only (must exist); 'r+' means read/write (must exist); 'a' means read/write (create if doesn't exist); 'w' means create (overwrite if exists); 'w-' means create (fail if exists). If the store is read-only, the default is 'r'; otherwise, it is 'a'.

  • zarr_format ((2, 3, None), default: 2 ) –

    The zarr format to use when saving.

  • path (str or None, default: None ) –

    The path within the store to open.

  • storage_options (dict, default: None ) –

    If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.

  • **kwargs (Any, default: {} ) –

    Additional parameters are passed through to zarr.open_array or zarr.open_group.

Returns:

  • z ( array or group ) –

    Return type depends on what exists in the given store.

See Also

load

Notes

open returns a lazy Array or Group backed by the store, so data is read and written incrementally. Use load instead when you want the data eagerly read into an in-memory array (a NumPy array by default).

Source code in zarr/api/synchronous.py
def open(
    store: StoreLike | None = None,
    *,
    mode: AccessModeLiteral | None = None,
    zarr_format: ZarrFormat | None = None,
    path: str | None = None,
    storage_options: dict[str, Any] | None = None,
    **kwargs: Any,  # TODO: type kwargs as valid args to async_api.open
) -> AnyArray | Group:
    """Open a group or array using file-mode-like semantics.

    Parameters
    ----------
    store : StoreLike or None, default=None
        StoreLike object to open. See the
        [storage documentation in the user guide][user-guide-store-like]
        for a description of all valid StoreLike values.
    mode : {'r', 'r+', 'a', 'w', 'w-'}, optional
        Persistence mode: 'r' means read only (must exist); 'r+' means
        read/write (must exist); 'a' means read/write (create if doesn't
        exist); 'w' means create (overwrite if exists); 'w-' means create
        (fail if exists).
        If the store is read-only, the default is 'r'; otherwise, it is 'a'.
    zarr_format : {2, 3, None}, optional
        The zarr format to use when saving.
    path : str or None, optional
        The path within the store to open.
    storage_options : dict
        If using an fsspec URL to create the store, these will be passed to
        the backend implementation. Ignored otherwise.
    **kwargs
        Additional parameters are passed through to `zarr.open_array` or
        `zarr.open_group`.

    Returns
    -------
    z : array or group
        Return type depends on what exists in the given store.

    See Also
    --------
    load

    Notes
    -----
    `open` returns a lazy [`Array`][zarr.Array] or [`Group`][zarr.Group] backed by
    the store, so data is read and written incrementally. Use [`load`][zarr.load]
    instead when you want the data eagerly read into an in-memory array (a
    NumPy array by default).
    """
    obj = sync(
        async_api.open(
            store=store,
            mode=mode,
            zarr_format=zarr_format,
            path=path,
            storage_options=storage_options,
            **kwargs,
        )
    )
    if isinstance(obj, AsyncArray):
        return Array(obj)
    else:
        return Group(obj)