Python XMP Toolkit

2.1.0 · active · verified Fri Apr 17

Python XMP Toolkit (version 2.1.0) provides Python bindings for Adobe's XMP Toolkit SDK by wrapping the Exempi C++ library. It enables reading, writing, and manipulating XMP (Extensible Metadata Platform) metadata in various file formats (e.g., JPEG, TIFF, PDF). The library maintains an active release cadence, with recent updates focusing on stability and compatibility with newer Exempi versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create, manipulate, and serialize XMP metadata using the `XMPMeta` class, which handles XMP data in memory. It covers setting properties, adding array items, retrieving values, and converting the XMP object to an RDF/XML string.

from libxmp import XMPMeta, consts

# Create a new XMP metadata object
xmp = XMPMeta()

# Set properties in the Dublin Core namespace
xmp.set_property(consts.NS_DC, "title", "My Awesome Photo")
xmp.set_property(consts.NS_DC, "creator", "Jane Doe")

# Add items to an array property (e.g., keywords)
xmp.append_array_item(consts.NS_DC, "subject", "landscape", None, consts.XMP_ARRAY_LAST_ITEM)
xmp.append_array_item(consts.NS_DC, "subject", "mountains", None, consts.XMP_ARRAY_LAST_ITEM)

# Get a property
title = xmp.get_property(consts.NS_DC, "title")
print(f"Title: {title}")

# Iterate over array items
print("Subjects:")
for i in range(xmp.count_array_items(consts.NS_DC, "subject")):
    # Array items are 1-indexed in XMP
    item = xmp.get_array_item(consts.NS_DC, "subject", i + 1) 
    print(f"- {item}")

# Serialize XMP to RDF/XML string
rdf_string = xmp.dump_as_rdf()
print("\n--- XMP as RDF ---")
print(rdf_string)
print("------------------")

view raw JSON →