Skip to main content

zarr-ext-jpeg

Warning: the jpeg codec is not yet stable and may change.

The jpeg extension codec for zarr-python.

The JPEG codec is an array-to-bytes codec (aka "serializer") for compressing 2D data with 1 or 3 channels, where the channel axis must come last. Use the reshape and/or transpose codecs to rearrange any arrays which do not fit this pattern.

You may also be interested in the template chunk key encoding, to give all chunks the .jpeg extension so that they can be previewed by extension-sensitive browsers.

Usage

Simply installing zarr-ext-jpeg (e.g. with pip or uv) will allow you to decode JPEG-encoded chunks when using zarr-python.

To create JPEG-encoded arrays, use the builder pattern to ensure that your codec is valid:

from zarr.storage import MemoryStore
from zarr_ext_jpeg import JpegCodec
import numpy as np

my_codec = (
    JpegCodec
    # encoded color space:
    # determines which other parameters are valid
    .builder("ycbcr")
    # 2 horizontal and 2 vertical luminance pixels
    # per chrominance pixel
    .chroma_subsampling(2, 2)
    # defaults to 95 if not given
    .quality(75)
    .build()
)

store = MemoryStore()
rng = np.random.default_rng(1991)
data = rng.randint(0, 256, (10, 20), "uint8")
my_array = zarr.create_array(
    store,
    data=data,
    serializer=my_codec,
    # skip adding the default bytes-to-bytes codec(s)
    compressors=[],
)

Lossy encoding warning

JPEG encoding is lossy. Decoding and then re-encoding the same chunks will introduce more and more artifacts. The jpeg codec should only be used for write-once data when whole chunks can be written at once.

Parameter selection

Quality

The default is 95, on a scale of 0-100. Values above 95 lead to significantly larger files with very little perceptual gain. Lower values introduce more artifacts.

Channels

If your data doesn't have exactly 1 or 3 channels, consider using the chunk configuration or sharding to make the chunk's channel axis length 1, and then using grayscale encoding.

If you have 3 channels but they are not the red/green/blue (or YCbCr) of a natural scene, use RGB->RGB encoding. The default RGB->YCbCr color transform may introduce additional artifacts.

Chunk/ shard shape

JPEGs are encoded in Minimum Coded Units whose shape depends on the chroma subsampling used. MCUs are 8x8 pixels, multiplied by the chroma subsampling ratio: e.g. for a subsampling ratio of [4, 1], the MCU would have shape (32, 8). The first two elements of your chunk shape SHOULD be a multiple of this MCU shape.

Additional compression

At time of writing, by default zarr-python applies an additional bytes-to-bytes codec ("compressor") if none is specified. As JPEG compresses quite effectively, this will likely not reduce your data size much and cost processing time; explicitly set compressors=[] on array creation.

Difference between jpeg and imagecodecs_jpeg codecs

jpeg is a registered zarr extension with implementations in multiple languages, targeting a minimal common API surface. imagecodecs_jpeg supports more features, but is specified only by the details of a single implementation.

Difference between zarr-ext-jpeg and zarr-jpeg packages

zarr-jpeg is a Zarr v2-era package which predates the current jpeg extension codec specification, and indeed the Zarr v3 extension concept. It is non-standard and defined only by the one implementation.

Metadata

Release files for zarr-ext-jpeg 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zarr-ext-jpeg 0.1.0
File Size Uploaded Provenance Actions
zarr_ext_jpeg-0.1.0.tar.gz 7.7 kB Without provenance Details for zarr_ext_jpeg-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for zarr-ext-jpeg 0.1.0
File Interpreter ABI Platform Actions
zarr_ext_jpeg-0.1.0-py3-none-any.whl Python 3 none any Details for zarr_ext_jpeg-0.1.0-py3-none-any.whl

Total release size: 17.1 kB

Release files / zarr_ext_jpeg-0.1.0.tar.gz

Download URL zarr_ext_jpeg-0.1.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
469a69cc0ecce3c7d41852153dd004e170d9ff2fc7d6451cf0c3971417b3a0ed
BLAKE2b-256 checksum
How to use checksums
8d2f2538eedd59806fcaa8545089edf0d1b6d9c2c704562704b806670e62bb30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / zarr_ext_jpeg-0.1.0-py3-none-any.whl

Download URL zarr_ext_jpeg-0.1.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea955ec60d59d9d0106e3cc16b0f639e81a44bbe20892b02308768d0db847f7e
BLAKE2b-256 checksum
How to use checksums
97d63ad523f49d7b38050ed44dcd501aa96519def5c150e0891c3e9f82ef3fe8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for zarr-ext-jpeg 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page