Skip to main content

Read and write Netpbm files

Project description

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:

Christoph Gohlke

License:

BSD-3-Clause

Version:

2026.7.25

DOI:

10.5281/zenodo.17903402

Quickstart

Install the netpbmfile package and all dependencies from the Python Package Index:

python -m pip install -U "netpbmfile[all]"

See Examples 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):

  • CPython 3.12.10, 3.13.14, 3.14.6, 3.15.0b4 64-bit

  • Numpy 2.5.1

Revisions

2026.7.25

  • Drop support for Python 3.11 and numpy 2.0 (SPEC0), support Python 3.15.

2026.1.29

  • Fix code review issues.

2026.1.8

  • Improve code quality.

2025.12.12

  • Drop support for Python 3.10, support Python 3.14.

2025.5.8

  • Remove doctest command line option.

2025.1.1

  • Improve type hints.

  • Drop support for Python 3.9, support Python 3.13.

2024.5.24

Refer to the CHANGES file for older revisions.

Examples

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

Project details


Download files

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

Source Distribution

netpbmfile-2026.7.25.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

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

netpbmfile-2026.7.25-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file netpbmfile-2026.7.25.tar.gz.

File metadata

  • Download URL: netpbmfile-2026.7.25.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for netpbmfile-2026.7.25.tar.gz
Algorithm Hash digest
SHA256 7e8556b0a4507ef062158a2ae26a93e1e7e9419530c30d209ce5474e68ee4e6e
MD5 9c0b2ca9738f79e649ec3efe4a732f45
BLAKE2b-256 21f46a7af6a72cad868fcfe40ed5a13b1216b230b04ef454f4da7249d2308c0e

See more details on using hashes here.

File details

Details for the file netpbmfile-2026.7.25-py3-none-any.whl.

File metadata

  • Download URL: netpbmfile-2026.7.25-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for netpbmfile-2026.7.25-py3-none-any.whl
Algorithm Hash digest
SHA256 d14d90ec0c17a223e3732f16a190b8681b3801993e6bbb33a1d3dfcae4f2448d
MD5 7b4c2efce6b187138b00aada5a40335d
BLAKE2b-256 ef6ce7b55367f35b35c7cda412a48cdf4767c20d23b58ef7c03265f329b1c312

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page