Skip to main content

A Python interface to read and write Metadata Working Group fields using exiftool

Project description

EXIF Metadata Working Group Tool

PyPI - Version PyPI - Python Version codecov


Table of Contents

What

This library is a wrapper around PyExifTool to simplify the reading and writing of image metadata fields as defined by the Metadata Working Group. The specification Guidelines for Handling Image Metadata (PDF) defines a structured way to resolve certain common fields across the various versions and standards for image metadata.

Working with image metadata is challenging due to the multiple competing standards and implementation differences. This library abstracts away these complexities, providing a consistent interface for accessing and modifying metadata regardless of which standard is used in the image.

Features

  • Simplified Metadata Management: Wraps PyExifTool in a convenient interface, managing a single process for better performance
  • Strongly Typed Interface: Leverages Pydantic models for type checking and validation of metadata fields
  • Cross-Standard Support: Instructs ExifTool to use MWG guidelines to normalize access to metadata across different standards
  • Key Metadata Fields:
    • XMP-mwg-kw:KeywordInfo - Read and write hierarchical keyword/tag trees for images
    • XMP-mwg-rs:RegionInfo - Manage region annotations for images (face tagging, object recognition boxes)
    • MWG:Description - Access standardized image descriptions across metadata formats
    • Title - Manage image titles consistently

Requirements

  • Python 3.9 or higher
  • ExifTool installed and available in your system path
    • On Ubuntu/Debian: apt-get install exiftool
    • On MacOS: brew install exiftool
    • On Windows: Download and install from the official site

Installation

pip install exifmwg

Usage

Quick Start

from pathlib import Path
from exifmwg import ExifTool

# Read metadata from an image
with ExifTool() as tool:
    metadata = tool.read_image_metadata(Path("sample.jpg"))
    # Print the image title
    print(f"Image title: {metadata.Title}")

    # Set a new title and description
    metadata.Title = "Sunset at the Beach"
    metadata.Description = "Beautiful sunset captured at Malibu Beach"
    tool.write_image_metadata(metadata)

Reading and Modifying Image Regions

from pathlib import Path
from exifmwg import ExifTool

test_file = Path("sample.jpeg")

with ExifTool() as tool:
    # Read metadata from image
    metadata = tool.read_image_metadata(test_file)

    # Print the defined regions and their type for an image
    for region in metadata.RegionInfo.RegionList:
        print(f"Name: {region.Name}, Type: {region.Type}, Description: {region.Description or '(None)'}")

    # Change the person's name in the first region
    metadata.RegionInfo.RegionList[0].Name = "Billy Bob"
    tool.write_image_metadata(metadata)

Example output:

Name: John Smith, Type: Face, Description: Family member
Name: Rover, Type: Pet, Description: Family dog

Working with Keyword Hierarchies

from pathlib import Path
from exifmwg import ExifTool, models

test_file = Path("sample.jpeg")

with ExifTool() as tool:
    metadata = tool.read_image_metadata(test_file)

    # Create a new keyword hierarchy
    new_keyword = models.Keyword(
        Keyword="Vacation",
        Children=[
            models.Keyword(Keyword="Beach"),
            models.Keyword(Keyword="Mountain")
        ]
    )

    # Add to existing keywords
    metadata.KeywordInfo.KeywordList.append(new_keyword)

    # Write back to the image
    tool.write_image_metadata(metadata)

Documentation

For more detailed information about using this library, refer to:

Why

Although this could all be done directly with PyExifTool, using this wrapper provides several advantages:

  1. Strongly typed interface makes it easier to understand what fields are available
  2. Simplified API reduces the learning curve for managing image metadata
  3. Handles the complexity of different metadata standards and their implementations

License

exifmwg is distributed under the terms of the Mozilla Public License 2.0 license.

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

exifmwg-0.1.0.tar.gz (2.2 MB view details)

Uploaded Source

Built Distribution

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

exifmwg-0.1.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file exifmwg-0.1.0.tar.gz.

File metadata

  • Download URL: exifmwg-0.1.0.tar.gz
  • Upload date:
  • Size: 2.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for exifmwg-0.1.0.tar.gz
Algorithm Hash digest
SHA256 956643f515b052562e66c9e4a38c42872c678d441c25a8f486422f9b8b50a23e
MD5 7c1811803ca3bc23c11b3dc2fc0c1da6
BLAKE2b-256 1fd54e806f3f476bd1a509d91e91afebb64e70f8a8511172ec7aec7ec4c9e241

See more details on using hashes here.

Provenance

The following attestation bundles were made for exifmwg-0.1.0.tar.gz:

Publisher: ci.yml on stumpylog/exifmwg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exifmwg-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: exifmwg-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for exifmwg-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 37690a5288f6c6dfb4ab573a80fbcdd61d58f78c48de2f9e5f1c733cbc9bc05a
MD5 20ec31321ba43a08c98cd3b2cf5f2332
BLAKE2b-256 ad1a63f239f6f358203c963daa8bfd56d8b677ae7025bee24024e13c81a6952d

See more details on using hashes here.

Provenance

The following attestation bundles were made for exifmwg-0.1.0-py3-none-any.whl:

Publisher: ci.yml on stumpylog/exifmwg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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