Read and write Netpbm files
Netpbmfile is a Python library to read and write image files in the Netpbm or related formats:
PBM (Portable Bit Map): P1 (text) and P4 (binary)
PGM (Portable Gray Map): P2 (text) and P5 (binary)
PPM (Portable Pixel Map): P3 (text) and P6 (binary)
PNM (Portable Any Map): shorthand for PBM, PGM, and PPM collectively
PAM (Portable Arbitrary Map): P7, bilevel, gray, rgb, and arbitrary depths
PGX (Portable Graymap Signed): PG, signed grayscale
PFM (Portable Float Map): Pf (gray), PF (rgb), and PF4 (rgba), read-only
XV thumbnail: P7 332 (rgb332), read-only
The Netpbm formats are specified at https://netpbm.sourceforge.net/doc/.
The PGX format is specified in ITU-T Rec. T.803.
No gamma correction or scaling is performed.
- Author:
- License:
BSD-3-Clause
- Version:
2026.10.15
- DOI:
Quickstart
Install the netpbmfile package and all dependencies from the Python Package Index:
python -m pip install -U "netpbmfile[all]"
See Examples and Documentation for using the programming interface.
Source code and support are available on GitHub.
Requirements
This revision was tested with the following requirements and dependencies (other versions may work):
Revisions
2026.10.15
Fix silent truncation of samples not fitting dtype of maxval.
Write to open files at current position (breaking).
Do not close caller-owned file handle on parsing error.
Raise when writing XV format instead of writing PAM (breaking).
2026.7.25
Drop support for Python 3.11 and numpy 2.0 (SPEC0), support Python 3.15.
2026.1.29
…
Refer to the CHANGES file for older revisions.
Examples
Import functions and classes used in these examples:
>>> from netpbmfile import NetpbmFile, imread, imwrite
Write a numpy array to a Netpbm file in grayscale binary format:
>>> import numpy
>>> data = numpy.array([[0, 1], [65534, 65535]], dtype=numpy.uint16)
>>> imwrite('_tmp.pgm', data)
Read the image data from a Netpbm file as numpy array:
>>> image = imread('_tmp.pgm')
>>> numpy.testing.assert_equal(image, data)
Access meta and image data in a Netpbm file:
>>> with NetpbmFile('_tmp.pgm') as pgm:
... pgm.magicnumber
... pgm.axes
... pgm.shape
... pgm.dtype
... pgm.maxval
... pgm.asarray().tolist()
...
'P5'
'YX'
(2, 2)
dtype('>u2')
65535
[[0, 1], [65534, 65535]]
View the image and metadata in the Netpbm file from the command line:
$ python -m netpbmfile _tmp.pgm
Metadata
Release files for netpbmfile 2026.10.15
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 |
|---|---|---|---|---|
| netpbmfile-2026.10.15.tar.gz | 32.0 kB | Without provenance | Details for netpbmfile-2026.10.15.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| netpbmfile-2026.10.15-py3-none-any.whl | Python 3 | none | any | Details for netpbmfile-2026.10.15-py3-none-any.whl |
Total release size: 46.7 kB
Release files / netpbmfile-2026.10.15.tar.gz
| Download URL | netpbmfile-2026.10.15.tar.gz |
|---|---|
| Size | 32.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd8b646c34aeccfe7f7dc221843790a558fa2c5ede6d8d8df795010b14f4c4ba
|
|
BLAKE2b-256 checksum How to use checksums |
6ce6a5886e471274cbe7b2e1d51148f1bb540cfe35adea399c8fc960db744dac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Release files / netpbmfile-2026.10.15-py3-none-any.whl
| Download URL | netpbmfile-2026.10.15-py3-none-any.whl |
|---|---|
| Size | 14.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c3bd697bea50fe332ab440ac0c87f9366f3be32dd31984966751e466d990b233
|
|
BLAKE2b-256 checksum How to use checksums |
460b1414101de0d5bb3a72f3cf9a89689555da1ff61e0781269e639e449c04db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Security for netpbmfile 2026.10.15
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.