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:
Metadata
Release files for pyjpeg 0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyjpeg-0.9.tar.gz | 111.5 kB | With provenance | Details for pyjpeg-0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyjpeg-0.9-py3-none-any.whl | Python 3 | none | any | Details for pyjpeg-0.9-py3-none-any.whl |
Total release size: 197.7 kB
Release files / pyjpeg-0.9.tar.gz
| Download URL | pyjpeg-0.9.tar.gz |
|---|---|
| Size | 111.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3b4842a03e74bbfdddca73a918c5f2297b96b3a4774de9b07c1dc9645ddd6b91
|
|
BLAKE2b-256 checksum How to use checksums |
57d2efdf1202de9e4e6b4d5b30e6294c993f167c86702baaada18a762653dd3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.
Transparency logRelease files / pyjpeg-0.9-py3-none-any.whl
| Download URL | pyjpeg-0.9-py3-none-any.whl |
|---|---|
| Size | 86.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
613a5703d56f426a5d5e947ad78aa99d24c7380915ec7d19e696ea75f9e356db
|
|
BLAKE2b-256 checksum How to use checksums |
76f6b118088e7623d624079fe0dbacad593ff98814cb6fc4d315227e235802d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.
Transparency logSecurity for pyjpeg 0.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pyjpeg-0.9.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.
Transparency logA 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.