PyJPEG
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
Imageobjects - Comprehensive JPEG feature support, including modes most libraries omit
Supported JPEG coding processes:
- Baseline sequential DCT — the standard JPEG process used by most
.jpgfiles - 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:
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyjpeg-0.9.tar.gz.
File metadata
- Download URL: pyjpeg-0.9.tar.gz
- Upload date:
- Size: 111.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b4842a03e74bbfdddca73a918c5f2297b96b3a4774de9b07c1dc9645ddd6b91
|
|
| MD5 |
8fe0246c548e680acb6825ac0e7ed326
|
|
| BLAKE2b-256 |
57d2efdf1202de9e4e6b4d5b30e6294c993f167c86702baaada18a762653dd3b
|
Provenance
The following attestation bundles were made for pyjpeg-0.9.tar.gz:
Publisher:
publish.yml on robert-ancell/pyjpeg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyjpeg-0.9.tar.gz -
Subject digest:
3b4842a03e74bbfdddca73a918c5f2297b96b3a4774de9b07c1dc9645ddd6b91 - Sigstore transparency entry: 2299555330
- Sigstore integration time:
-
Permalink:
robert-ancell/pyjpeg@fad5d9f39f71fe2a074c373844f250a955d169a8 -
Branch / Tag:
refs/tags/v0.9 - Owner: https://github.com/robert-ancell
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fad5d9f39f71fe2a074c373844f250a955d169a8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyjpeg-0.9-py3-none-any.whl.
File metadata
- Download URL: pyjpeg-0.9-py3-none-any.whl
- Upload date:
- Size: 86.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
613a5703d56f426a5d5e947ad78aa99d24c7380915ec7d19e696ea75f9e356db
|
|
| MD5 |
aaff0b637a6bcfbea930a34cc4448c3e
|
|
| BLAKE2b-256 |
76f6b118088e7623d624079fe0dbacad593ff98814cb6fc4d315227e235802d5
|
Provenance
The following attestation bundles were made for pyjpeg-0.9-py3-none-any.whl:
Publisher:
publish.yml on robert-ancell/pyjpeg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyjpeg-0.9-py3-none-any.whl -
Subject digest:
613a5703d56f426a5d5e947ad78aa99d24c7380915ec7d19e696ea75f9e356db - Sigstore transparency entry: 2299555344
- Sigstore integration time:
-
Permalink:
robert-ancell/pyjpeg@fad5d9f39f71fe2a074c373844f250a955d169a8 -
Branch / Tag:
refs/tags/v0.9 - Owner: https://github.com/robert-ancell
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fad5d9f39f71fe2a074c373844f250a955d169a8 -
Trigger Event:
push
-
Statement type: