or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-metadata.mdfile-operations.mdindex.mdutilities.md
tile.json

tessl/pypi-python-xmp-toolkit

Python library for working with XMP (Extensible Metadata Platform) metadata in files.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/python-xmp-toolkit@2.0.x

To install, run

npx @tessl/cli install tessl/pypi-python-xmp-toolkit@2.0.0

index.mddocs/

Python XMP Toolkit

A Python library for working with XMP (Extensible Metadata Platform) metadata in files. This library provides a comprehensive interface for reading, writing, and manipulating XMP metadata stored in various file formats through a Python wrapper around the Exempi library.

Package Information

  • Package Name: python-xmp-toolkit
  • Language: Python
  • Installation: pip install python-xmp-toolkit
  • Version: 2.0.1
  • License: BSD

Core Imports

import libxmp

Common imports for working with XMP metadata:

from libxmp import XMPMeta, XMPFiles, XMPError

Basic Usage

from libxmp import XMPMeta, XMPFiles

# Working with XMP metadata in memory
xmp = XMPMeta()
xmp.set_property("http://ns.adobe.com/xap/1.0/", "CreatorTool", "Python XMP Toolkit")
xmp.set_property("http://purl.org/dc/elements/1.1/", "creator", "John Doe")

# Serialize XMP to string
xmp_str = xmp.serialize_to_str()
print(xmp_str)

# Working with files
xmpfile = XMPFiles(file_path="example.jpg")
xmp_data = xmpfile.get_xmp()
if xmp_data:
    creator = xmp_data.get_property("http://purl.org/dc/elements/1.1/", "creator")
    print(f"Creator: {creator}")
xmpfile.close_file()

Architecture

The library provides three main layers of XMP metadata access:

  • XMPMeta: Core metadata object for parsing, manipulating, and serializing XMP data
  • XMPFiles: File-based XMP access with smart handlers for different file formats
  • Exempi Interface: Low-level ctypes interface to the underlying Exempi C library

This design enables both high-level object-oriented operations and fine-grained control over XMP metadata processing, supporting the complete XMP specification including arrays, structures, localized text, and standard namespace handling.

Capabilities

Core Metadata Operations

XMP metadata parsing, manipulation, and serialization with support for all XMP data types including simple properties, arrays, structures, and localized text. Provides comprehensive property access methods and namespace management.

class XMPMeta:
    def __init__(self, **kwargs): ...
    def get_property(self, schema_ns, prop_name): ...
    def set_property(self, schema_ns, prop_name, prop_value, **kwargs): ...
    def serialize_to_str(self, padding=0, **kwargs): ...
    def parse_from_str(self, xmp_packet_str, xmpmeta_wrap=False, input_encoding=None): ...

Core Metadata Operations

File Operations

File-based XMP metadata access with smart handlers for various file formats. Provides convenient reading and writing of XMP metadata directly from image files, PDFs, and other supported formats.

class XMPFiles:
    def __init__(self, **kwargs): ...
    def open_file(self, file_path, **kwargs): ...
    def get_xmp(self): ...
    def put_xmp(self, xmp_obj): ...
    def close_file(self, close_flags=0): ...

File Operations

Utilities and Constants

Utility functions for extracting XMP data to Python dictionaries, comprehensive XMP constants for namespaces and options, and library management functions.

def object_to_dict(xmp): ...
def file_to_dict(file_path): ...
def terminate(): ...

Utilities and Constants

Exception Handling

class XMPError(Exception):
    """General XMP Error for all XMP-related operations"""

class ExempiLoadError(Exception):
    """Error signaling that the Exempi library cannot be loaded"""

Common error handling pattern:

from libxmp import XMPFiles, XMPError

try:
    xmpfile = XMPFiles(file_path="example.jpg")
    xmp_data = xmpfile.get_xmp()
    # ... work with XMP data
except XMPError as e:
    print(f"XMP operation failed: {e}")
finally:
    if 'xmpfile' in locals():
        xmpfile.close_file()