Skip to main content

A Python library for reading and writing PNG metadata (tEXt, iTXt, zTXt chunks and XMP)

Project description

pngmeta

A Python library for reading and writing PNG metadata, similar to iptcinfo3 for JPEG files.

PyPI version GitHub stars Downloads License

📖 View Full Documentation Site - Complete guide with live examples and API reference


Ever wish you could add information to your PNG images like a caption, author, copyright, and keywords? You already can! PNG files support metadata through text chunks (tEXt, iTXt, zTXt) and XMP. This module makes it easy to read and write that metadata in your Python programs.

Installation

Install from PyPI:

pip install pngmeta

Or with uv:

uv pip install pngmeta

Requirements

  • Python 3.8 or higher
  • No external dependencies required

Usage

from pngmeta import PngMeta

Create new info object

meta = PngMeta('photo.png')

Access metadata

# Get specific attributes
title = meta['Title']
author = meta['Author']
copyright_text = meta.get('Copyright')

Modify metadata

# Add/change attributes
meta['Title'] = 'Sunset Over Mountains'
meta['Author'] = 'Jane Photographer'
meta['Copyright'] = '© 2025 Jane Photographer. All rights reserved.'
meta['Description'] = 'A stunning sunset over the mountains'

Common metadata fields

meta['Creation Time'] = '2025-10-05T12:00:00'
meta['Software'] = 'pngmeta 0.1.0'
meta['Comment'] = 'What a beautiful day!'

Work with XMP metadata

# Get XMP
xmp = meta.get_xmp()

# Set XMP
meta.set_xmp('<?xml version="1.0"?><x:xmpmeta>...</x:xmpmeta>')

Check if metadata exists

if 'Author' in meta:
    print(f"Photo by {meta['Author']}")

Iterate over all metadata

for key, value in meta.items():
    print(f"{key}: {value}")

Save changes

# Save back to the same file
meta.save()

# Or save to a new file
meta.save('photo_with_metadata.png')

Create object for file that may not have metadata

# Reads existing file, ready to add metadata
meta = PngMeta('new_photo.png')
meta['Title'] = 'My First Metadata'
meta.save()

Complete Example

from pngmeta import PngMeta

# Open an image
meta = PngMeta('photo.png')

# Add comprehensive metadata
meta['Title'] = 'Golden Gate Bridge at Sunset'
meta['Author'] = 'Jane Photographer'
meta['Copyright'] = '© 2025 Jane Photographer. All rights reserved.'
meta['Description'] = 'A stunning view of the Golden Gate Bridge during golden hour'
meta['Creation Time'] = '2025-10-05T18:30:00'
meta['Software'] = 'pngmeta 0.1.0'
meta['Comment'] = 'Shot with telephoto lens'

# Save the changes
meta.save()

# Read it back to verify
meta2 = PngMeta('photo.png')
print(f"Title: {meta2['Title']}")
print(f"Author: {meta2['Author']}")

Common PNG Metadata Fields

Field Description Example
Title Short title or caption "Golden Gate Bridge"
Author Image creator "Jane Photographer"
Description Longer description "A stunning sunset view..."
Copyright Copyright notice "© 2025 Jane Photographer"
Creation Time When image was created "2025-10-05T18:30:00"
Software Software used "pngmeta 0.1.0"
Comment Miscellaneous comment "Shot with telephoto lens"
XML:com.adobe.xmp XMP metadata (use set_xmp() method)

PNG Metadata Background

PNG files store metadata in "ancillary chunks":

  • tEXt - Latin-1 text (uncompressed)
  • iTXt - UTF-8 text (optionally compressed), used for XMP
  • zTXt - Compressed Latin-1 text

Unlike JPEG, PNG doesn't natively use IPTC, but XMP can be embedded in iTXt chunks for cross-format compatibility.

Examples

Interactive Demo

Run the comprehensive demo to see all features in action with colored output:

python examples/demo_all_operations.py

This demo shows:

  • Reading existing metadata
  • Adding/modifying fields
  • Working with XMP
  • Dictionary operations
  • Saving and verifying
  • Complete colored reporting

Basic Usage Script

See examples/basic_usage.py for additional examples including:

  • Reading metadata from files
  • Batch operations
  • Copying metadata between images
  • XMP handling

Development

# Clone the repository
git clone https://github.com/james-see/pngmeta.git
cd pngmeta

# Install with uv
uv venv
source .venv/bin/activate  # or `.venv\Scripts\activate` on Windows
uv pip install -e ".[dev]"

# Run tests
pytest

# Format code
black pngmeta tests

# Run the demo
python examples/demo_all_operations.py

License

This is free and unencumbered software released into the public domain (Unlicense).

API Compatibility with iptcinfo3

If you're familiar with iptcinfo3, pngmeta follows a similar pattern:

# iptcinfo3 (for JPEG)
from iptcinfo3 import IPTCInfo
info = IPTCInfo('photo.jpg')
info['caption/abstract'] = 'My photo'
info.save()

# pngmeta (for PNG)
from pngmeta import PngMeta
meta = PngMeta('photo.png')
meta['Description'] = 'My photo'
meta.save()

Both use dictionary-style access and similar save patterns for a consistent experience.

See Also

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

pngmeta-0.1.1.tar.gz (3.8 MB view details)

Uploaded Source

Built Distribution

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

pngmeta-0.1.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file pngmeta-0.1.1.tar.gz.

File metadata

  • Download URL: pngmeta-0.1.1.tar.gz
  • Upload date:
  • Size: 3.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.23

File hashes

Hashes for pngmeta-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2cda12fa2790b87eaafe4bfaf1bc69e45f8d63d4fe0669fc92081080afca7746
MD5 6610f659df30c07225608b28aff466da
BLAKE2b-256 b8437af2295fa20c0d40b17c253044a5aafc54466af1ccf46f84ba7f0cbaabd2

See more details on using hashes here.

File details

Details for the file pngmeta-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pngmeta-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.23

File hashes

Hashes for pngmeta-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7eeec5c0fd1beb127488ef513fe4503693d8a9716ed165878a5bada5addccadc
MD5 25c4e008fb583708aab5d1abf668ed3c
BLAKE2b-256 a96e2adb354c2873d6ae2fbb69182e78c2f7c475279a1b234ab65ad24318d21b

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