Skip to content

numcodec

zarr.abc.numcodec

Numcodec

Bases: Protocol

A protocol that models the numcodecs.abc.Codec interface.

This protocol should be considered experimental. Expect the type annotations for buf and out to narrow in the future.

Source code in zarr/abc/numcodec.py
class Numcodec(Protocol):
    """
    A protocol that models the ``numcodecs.abc.Codec`` interface.

    This protocol should be considered experimental. Expect the type annotations for ``buf`` and
    ``out`` to narrow in the future.
    """

    codec_id: str

    def encode(self, buf: Any) -> Any:
        """Encode data from ``buf``.

        Parameters
        ----------
        buf : Any
            Data to be encoded.

        Returns
        -------
        enc: Any
            Encoded data.
        """
        ...

    def decode(self, buf: Any, out: Any | None = None) -> Any:
        """
        Decode data in ``buf``.

        Parameters
        ----------
        buf : Any
            Encoded data.
        out : Any
            Writeable buffer to store decoded data. If provided, this buffer must
            be exactly the right size to store the decoded data.

        Returns
        -------
        dec : Any
            Decoded data.
        """
        ...

    def get_config(self) -> Any:
        """
        Return a JSON-serializable configuration dictionary for this
        codec. Must include an ``'id'`` field with the codec identifier.
        """
        ...

    @classmethod
    def from_config(cls, config: Any) -> Self:
        """
        Instantiate a codec from a configuration dictionary.

        Parameters
        ----------
        config : Any
            A configuration dictionary for this codec.
        """
        ...

codec_id instance-attribute

codec_id: str

decode

decode(buf: Any, out: Any | None = None) -> Any

Decode data in buf.

Parameters:

  • buf (Any) –

    Encoded data.

  • out (Any, default: None ) –

    Writeable buffer to store decoded data. If provided, this buffer must be exactly the right size to store the decoded data.

Returns:

  • dec ( Any ) –

    Decoded data.

Source code in zarr/abc/numcodec.py
def decode(self, buf: Any, out: Any | None = None) -> Any:
    """
    Decode data in ``buf``.

    Parameters
    ----------
    buf : Any
        Encoded data.
    out : Any
        Writeable buffer to store decoded data. If provided, this buffer must
        be exactly the right size to store the decoded data.

    Returns
    -------
    dec : Any
        Decoded data.
    """
    ...

encode

encode(buf: Any) -> Any

Encode data from buf.

Parameters:

  • buf (Any) –

    Data to be encoded.

Returns:

  • enc ( Any ) –

    Encoded data.

Source code in zarr/abc/numcodec.py
def encode(self, buf: Any) -> Any:
    """Encode data from ``buf``.

    Parameters
    ----------
    buf : Any
        Data to be encoded.

    Returns
    -------
    enc: Any
        Encoded data.
    """
    ...

from_config classmethod

from_config(config: Any) -> Self

Instantiate a codec from a configuration dictionary.

Parameters:

  • config (Any) –

    A configuration dictionary for this codec.

Source code in zarr/abc/numcodec.py
@classmethod
def from_config(cls, config: Any) -> Self:
    """
    Instantiate a codec from a configuration dictionary.

    Parameters
    ----------
    config : Any
        A configuration dictionary for this codec.
    """
    ...

get_config

get_config() -> Any

Return a JSON-serializable configuration dictionary for this codec. Must include an 'id' field with the codec identifier.

Source code in zarr/abc/numcodec.py
def get_config(self) -> Any:
    """
    Return a JSON-serializable configuration dictionary for this
    codec. Must include an ``'id'`` field with the codec identifier.
    """
    ...