Skip to main content

PyJPEG

PyPI

A pure Python encoder and decoder for the JPEG image format, aiming to be a complete implementation of all the JPEG standards still in active use — including processes that most libraries skip, such as arithmetic coding, lossless coding, and JPEG-LS.

Being pure Python (no C extensions), it is not intended to be the fastest or most efficient way to decode/encode JPEGs in Python — libraries like pylibjpeg or Pillow will perform much better for general image loading/saving. PyJPEG is instead most useful when you want to understand how JPEG works, or need to analyze or generate JPEG files at the bitstream/segment level in plain, readable Python.

Features

  • Pure Python — no compiled dependencies, easy to install anywhere Python runs
  • Simple, inspectable object model (Image, Component, FileReader, FileWriter)
  • Work at whichever level suits your task — manipulate files at the raw stream/segment level, or through high-level Image objects
  • Comprehensive JPEG feature support, including modes most libraries omit

Supported JPEG coding processes:

  • Baseline sequential DCT — the standard JPEG process used by most .jpg files
  • Progressive DCT — encodes images in multiple passes of increasing detail, including successive approximation scans, so images can be displayed at low quality before the full file has loaded
  • Lossless coding — a predictive coding mode that reconstructs the exact original pixel values, with no loss of image quality
  • 12-bit precision — supports 12-bit sample precision as well as the standard 8-bit, which many other JPEG libraries don't support or make difficult to use
  • Arithmetic coding — an alternative entropy coder to Huffman, supported across all modes
  • JPEG-LS — the separate lossless/near-lossless standard (ITU-T T.87), including LSE (JPEG-LS preset parameters) support
  • Huffman table optimization — generate optimized Huffman tables rather than using the standard/default ones
  • Obscure marker support — including rarely-implemented markers like DNL (define number of lines), which most libraries skip

Also reads and writes the metadata formats JPEG files are commonly wrapped in, including JFIF (with thumbnails), Exif, SPIFF, and the Adobe APP14 marker used to signal color space (RGB/CMYK, YCbCr, or YCCK).

Installation

Install from PyPI:

pip install pyjpeg

Usage

See API documentation for details.

Reading a JPEG

import pyjpeg

reader = pyjpeg.FileReader(open('test.jpg', 'rb'))
image = pyjpeg.Image.read(reader)
print(image.components[0].samples)

Writing a JPEG

import pyjpeg

# A tiny 8x8 single-component (greyscale) image
samples = [
    0,   0,   0,   0,   0,   0,   0,   0,
    0,   0,   0,   255, 255, 255, 0,   0,
    0,   0,   0,   0,   255, 0,   0,   0,
    0,   0,   0,   0,   255, 0,   0,   0,
    0,   0,   255, 0,   255, 0,   0,   0,
    0,   0,   255, 0,   255, 0,   0,   0,
    0,   0,   0,   255, 0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,   0,   0,
]
out_image = pyjpeg.Image(8, 8, [pyjpeg.Component(1, samples)])
writer = pyjpeg.FileWriter(open('test_out.jpg', 'wb'))
out_image.write(writer)

Contributing

PyJPEG is an open source project with an LGPL-3.0 license. It is still under active development, and APIs may change between releases. Contributions, bug reports, and testing against real-world JPEG files are welcome — see the project homepage to get started.

Alternatives

If you just need fast, general-purpose JPEG reading/writing in Python (not a pure-Python implementation, and not full standards coverage), consider:

  • Pillow — the standard general-purpose Python imaging library, backed by libjpeg
  • pylibjpeg — a Python framework for JPEG decoding built on compiled plugins, with a focus on DICOM use cases

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyjpeg-0.7.tar.gz (111.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyjpeg-0.7-py3-none-any.whl (85.8 kB view details)

Uploaded Python 3

File details

Details for the file pyjpeg-0.7.tar.gz.

File metadata

  • Download URL: pyjpeg-0.7.tar.gz
  • Upload date:
  • Size: 111.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyjpeg-0.7.tar.gz
Algorithm Hash digest
SHA256 d51d6d2977b088b9396ab580ab39f2b7845cf9eccfa1ae0de208b053f96b699f
MD5 f759c4066e5bd0c444f1b39fe93ce4f8
BLAKE2b-256 1e9a1740e856b068e37be5bb5b9193654afa5471874a0926d7bb3dcb6c707f5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyjpeg-0.7.tar.gz:

Publisher: publish.yml on robert-ancell/pyjpeg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyjpeg-0.7-py3-none-any.whl.

File metadata

  • Download URL: pyjpeg-0.7-py3-none-any.whl
  • Upload date:
  • Size: 85.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyjpeg-0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6676663a47c9f8bf387b08dbb3c6f5ab430237de14c81ce36c6fb6dc20006b91
MD5 4ed1516153cf90360c983d515fe56162
BLAKE2b-256 8882f80f65d095683b65ef8e856a08dbbc4cc7449067ae34ad441c9542e5bbf2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyjpeg-0.7-py3-none-any.whl:

Publisher: publish.yml on robert-ancell/pyjpeg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.9

2 files

0.8

2 files

This release

0.7 This release

2 files

0.6

2 files

0.5

2 files

0.4

2 files

0.3

2 files

0.2

2 files

0.1

2 files

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