madam.xmp module
XMP metadata processor for JPEG images.
Reads and writes XMP metadata embedded in the JPEG APP1 block using the
standard library xml.etree.ElementTree. No additional dependencies
beyond Pillow are required.
Only JPEG is currently supported. XMP is also present in PNG (iTXt chunk) and TIFF (tag 700), but those formats are not handled by this module.
- class madam.xmp.XMPMetadataProcessor(config: Mapping[str, Any] | None = None)[source]
Bases:
MetadataProcessorReads and writes XMP metadata embedded in JPEG files.
XMP data is stored in the JPEG APP1 block identified by the namespace URI
http://ns.adobe.com/xap/1.0/. Only JPEG is supported; attempts to read non-JPEG data raiseUnsupportedFormatError.Supported metadata keys under the
'xmp'namespace:title— dc:title (x-default language alternative)description— dc:description (x-default language alternative)subject— dc:subject, list of strings (RDF Bag)rights— dc:rights (x-default language alternative)creator— dc:creator, first item of RDF Seqcreate_date— xmp:CreateDate (ISO 8601 string)modify_date— xmp:ModifyDate (ISO 8601 string)
Added in version 0.24.
- __init__(config: Mapping[str, Any] | None = None) None[source]
Initializes a new
XMPMetadataProcessor.- Parameters:
config – Mapping with settings.
- combine(file: IO, metadata: Mapping[str, Mapping]) IO[source]
Returns a copy of the JPEG file with XMP metadata embedded.
Existing XMP data is replaced. Only the
'xmp'key of metadata is used; other keys are ignored.- Parameters:
file (IO) – Readable binary file-like object containing JPEG data.
metadata (Mapping) – Mapping with an
'xmp'key whose value is a dict of XMP field names and values.
- Returns:
File-like object with XMP data embedded.
- Return type:
IO
- Raises:
UnsupportedFormatError – if metadata contains an unknown XMP format key.
- read(file: IO) Mapping[str, Mapping][source]
Reads XMP metadata from a JPEG file.
- Parameters:
file (IO) – Readable binary file-like object containing JPEG data.
- Returns:
Mapping with a single
'xmp'key whose value is a dict of decoded metadata fields. Returns an empty mapping when the file contains no XMP data.- Return type:
Mapping[str, Mapping]
- Raises:
UnsupportedFormatError – if the data is not a JPEG file.
- strip(file: IO) IO[source]
Returns a copy of the JPEG file with all XMP (APP1 XMP) data removed.
- Parameters:
file (IO) – Readable binary file-like object containing JPEG data.
- Returns:
File-like object with XMP data removed.
- Return type:
IO
- Raises:
UnsupportedFormatError – if the data is not a JPEG file.