Skip to main content

Lepton JPEG Compression

This is a port of the C++ Lepton JPEG compression tool that was released by DropBox dropbox/lepton. We developed a port of the library to Rust, which has basically the same performance characteristics with the advantage of all the safety features that Rust has to offer, due to the work involved in performing an exhaustive security check on the C++ code and the fact that DropBox has deprecated the codebase.

With precise bit-by-bit recovery of the original JPEG, the Lepton compression library is designed for lossless compression of baseline and progressive JPEGs up to 22%. JPEG storage in a cloud storage system is the main application case. Even metadata headers and invalid content are kept in good condition.

How to Use This Library

The library exposes two methods, compress and decompress, which can be invoked as follows:

    with open("my image", "rb") as f:
        jpg_data = f.read()

    config = {"max_jpeg_width": 4096 }
    compressed = lepton_jpeg_python.compress_bytes(jpg_data, config)
    decompressed = lepton_jpeg_python.decompress_bytes(compressed)

    assert jpg_data == decompressed

The following config options are supported:

  • max_jpeg_width: reject compressing images wider than this
  • max_jpeg_height: reject compressioning images taller than this
  • progressive: false to forbid compressing progressive JPEGs
  • reject_dqts_with_zeros: true if we should reject JPEGs with 0 in their quantitization table
  • max_partitions: maximum number of partitions to split JPEG into in order to allow for parallel compression/decompression
  • max_jpeg_file_size: reject JPEGs larger than this
  • max_jpeg_pixels: reject JPEGs with more pixels (width * height) than this
  • max_progressive_scans: reject progressive JPEGs with more scans than this
  • max_jpeg_coefficient_bytes: reject JPEGs whose coefficient buffers would exceed this peak byte estimate
  • max_jpeg_work_units: reject JPEGs whose component blocks multiplied by scan count exceed this value

Requires Python 3.14 or later.

Development

The Python package is managed with uv. From the python directory:

uv sync          # installs Python 3.14 and the dev tools, then builds the extension
uv run pytest    # runs the tests

Contributing

There are many ways in which you can participate in this project, for example:

  • Submit bugs and feature requests, and help us verify as they are checked in
  • Review source code changes or submit your own features as pull requests.
  • The library uses only stable features, so if you want to take advantage of SIMD features such as AVX2, use the Wide crate (see the idct.rs as an example) rather than intrinsics.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the Apache 2.0 license.

Metadata

Release files for lepton-jpeg-python 0.5.9

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

Built distributions (wheels)

Table of built distributions (wheels) for lepton-jpeg-python 0.5.9
File Interpreter ABI Platform Actions
lepton_jpeg_python-0.5.9-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for lepton_jpeg_python-0.5.9-cp314-cp314-win_amd64.whl
lepton_jpeg_python-0.5.9-cp314-cp314-manylinux_2_34_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.34+ x86-64 Details for lepton_jpeg_python-0.5.9-cp314-cp314-manylinux_2_34_x86_64.whl
lepton_jpeg_python-0.5.9-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details for lepton_jpeg_python-0.5.9-cp314-cp314-macosx_11_0_arm64.whl

Total release size: 4.0 MB

Release files / lepton_jpeg_python-0.5.9-cp314-cp314-win_amd64.whl

Download URL lepton_jpeg_python-0.5.9-cp314-cp314-win_amd64.whl
Size 434.3 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
dc4f4ca5866479e7253daa51ca6baa3900944841f00e3cff4ec0531d9d757ed2
BLAKE2b-256 checksum
How to use checksums
ab6c697d5f6aaae3366f10dbb71c356e3046809a49b9e744f1505ed8a00f2c89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

Release files / lepton_jpeg_python-0.5.9-cp314-cp314-manylinux_2_34_x86_64.whl

Download URL lepton_jpeg_python-0.5.9-cp314-cp314-manylinux_2_34_x86_64.whl
Size 3.1 MB
Tags CPython 3.14 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
18326fa95b83a0fa230c93f6588d6b6caa9a83f1c34ddb69a6a21a6886d4ba29
BLAKE2b-256 checksum
How to use checksums
d45e5671ba1148db9f89ff584967f8fdbba6dc94b4c5e97cbd9cba603c770569
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

Release files / lepton_jpeg_python-0.5.9-cp314-cp314-macosx_11_0_arm64.whl

Download URL lepton_jpeg_python-0.5.9-cp314-cp314-macosx_11_0_arm64.whl
Size 477.0 kB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e70b18a5fec4da31e2e65d0bcdf98ac4d5f1986632659e237fa37c45fd5900a0
BLAKE2b-256 checksum
How to use checksums
f1d0c3a3312e1c2388eca940773ff2638c8b47f8965719804ec7b3171d6e815e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

Security for lepton-jpeg-python 0.5.9

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