A module for parsing, manipulating, and serializing XMP data. The core module has no knowledge of files. The core API is provided by the XMPMeta and XMPIterator classes.
XMPMeta is the class providing the core services of the library
Adds an item to an array, creating the array if necessary.
This function simplifies construction of an array by not requiring that you pre-create an empty array. The array that is assigned is created automatically if it does not yet exist. If the array exists, it must have the form specified by the options. Each call appends a new item to the array.
Parameters: |
|
---|
Create a new XMP packet from this one.
Returns: | Copy of XMP packet. |
---|---|
Return type: | XMPMeta |
count_array_items returns the number of a given array’s items
Remove a localized property.
Parameters: |
|
---|---|
Raises: | XMPError if operation fails. |
Delete a property from XMP packet.
Deletes an XMP subtree rooted at a given property. It is not an error if the property does not exist.
Parameters: |
|
---|
Reports whether an item exists in an array.
Parameters: |
|
---|---|
Returns: | True if item is in array, False otherwise |
Return type: | bool |
Queries for existence of a property.
Parameters: |
|
---|---|
Returns: | True if the property exists, False otherwise. |
Get an item from an array property.
Items are accessed by an integer index
Parameters: |
|
---|---|
Raises: | IOError if exempi library routine fails. |
Todo
Make get_array_item optionally return keywords describing array item’s options
Returns information about a selected item in an alt-text array.
Parameters: |
|
---|---|
Raises: | IOError if operation fails. |
Returns: | The property’s value. |
Checks if a prefix is registered.
Parameters: | prefix (str) – The prefix to check. |
---|---|
Returns: | The associated namespace if registered. |
Raises: | IOError if exempi library routine fails. |
Check if a namespace is registered.
Parameters: :param str namespace: the namespace to check. :returns: the associated prefix if registered :raises: IOError if exempi library routine fails.
Retrieves property value.
This is the simplest property accessor: use this to retrieve the values of top-level simple properties.
Parameters: |
|
---|---|
Returns: | The property’s value if the property exists. |
Raises: | IOError if exempi library routine fails. |
Todo
Make get_property optionally return keywords describing property’s options
Retrieve a boolean property.
Parameters: |
|
---|---|
Raises: | IOError if operation fails. |
Returns: | The boolean property value. |
Todo
Make get_property_bool optionally return keywords describing property’s options
Retrieve a datetime property.
Parameters: |
|
---|---|
Returns: | datetime.datetime instance. |
Raises: | IOError if operation fails. |
Return a property value as floating point.
Parameters: |
|
---|---|
Raises: | IOError if operation fails. |
Returns: | The floating point property value. |
Todo
Make get_property_float optionally return keywords describing property’s options
Retrieve an integer property.
Parameters: |
|
---|---|
Raises: | IOError if operation fails. |
Returns: | The integer property value. |
Todo
Make get_property_int optionally return keywords describing property’s options
Retrieve a long (int64) property.
Parameters: |
|
---|---|
Raises: | IOError if operation fails. |
Returns: | The 64-bit integer property value. |
Todo
Make get_property_int optionally return keywords describing property’s options
Parses RDF from a string into a XMP object.
The input for parsing may be any valid Unicode encoding. ISO Latin-1 is also recognized, but its use is strongly discouraged.
Note RDF string must contain an outermost <x:xmpmeta> object.
Parameters: |
|
---|---|
Raises: | IOError if operation fails. |
Register a new namespace.
Parameters: |
|
---|---|
Returns: | the actual registered prefix for the namespace |
Serializes an XMPMeta object into a string as RDF.
Note, normally it is sufficient to use either serialize_to_str or serialize_to_unicode unless you need high degree of control over the serialization.
The specified parameters must be logically consistent, an exception is raised if not. You cannot specify both omit_packet_wrapper along with read_only_packet, include_thumbnail_pad, or exact_packet_length.
Parameters: |
|
---|---|
Returns: | XMPMeta object serialized into a string as RDF. |
Return type: | utf-8 string. |
Serialize into a string (8-bit, UTF-8 encoded) as RDF and format.
Parameters: |
|
---|---|
Returns: | str 8-bit string in UTF-8 encoding (ready to be written to a file). |
Serializes an XMPMeta object into a Unicode string as RDF and format. Note, this is wrapper around serialize_to_str.
The specified parameters must be logically consistent, an exception is raised if not. You cannot specify both omit_packet_wrapper along with read_only_packet, include_thumbnail_pad, or exact_packet_length.
Parameters: |
|
---|---|
Returns: | XMPMeta object serialized into a string as RDF. |
Return type: | unicode string. |
Creates or sets the value of an item within an array.
Items are accessed by an integer index, where the first item has index 1. This function creates the item if necessary, but the array itself must already exist: use append_array_item() to create arrays. A new item is automatically appended if the index is the array size plus 1; to insert a new item before or after an existing item, use kwargs.
Parameters: |
|
---|---|
Raises: | IOError if exempi library routine fails. |
Creates or sets a localized text value.
Parameters: |
|
---|---|
Raises: | IOError if exempi library routine fails. |
Creates or sets a property value.
The method takes optional keyword aguments that describe the property. You can use these functions to create empty arrays and structs by setting appropriate option flags. When you assign a value, all levels of a struct that are implicit in the assignment are created if necessary; append_array_item() implicitly creates the named array if necessary.
Parameters: |
|
---|---|
Raises: | IOError if exempi library routine fails. |
Set a boolean property.
Parameters: |
|
---|---|
Raises: | IOError if exempi library routine fails. |
Set a datetime property.
Parameters: |
|
---|---|
Raises: | IOError if exempi library routine fails. |
Set a floating point property.
Parameters: |
|
---|---|
Raises: | IOError if exempi library routine fails. |
Set an integer property.
Parameters: |
|
---|---|
Raises: | IOError if exempi library routine fails. |
Set a long integer (int64) property.
Parameters: |
|
---|---|
Raises: | IOError if exempi library routine fails. |
Provides means to iterate over a schema and properties.
XMPIterator provides a uniform means to iterate over the schema and properties within an XMP object. It is implemented according to Python’s iterator protocol and it is the iterator for XMPMeta class.
Parameters: |
|
---|---|
Returns: | an iterator for the given xmp_obj |
Implements iterator protocol for 2.X
Todo
Suppress this in sphinx docs
Raises: | StopIteration |
---|
Skips some portion of the remaining iterations.
Parameters: | **kwargs – Optional keyword parameters from XMP_SKIP_OPTIONS to control the iteration |
---|---|
Returns: | None |
Return type: | NoneType |
The Files module provides support for locating the XMP in a file, adding XMP to a file, or updating the XMP in a file. It returns the entire XMP packet, the core pacakage can then be used to manipulate the individual XMP properties. XMPFiles contains a number of “smart” file handlers that know how to efficiently access the XMP in specific file formats. It also includes a fallback packet scanner that can be used for unknown file formats.
API for access to the “main” metadata in a file.
XMPFiles provides the API for the Exempi’s File Handler component. This provides convenient access to the main, or document level, XMP for a file. The general model is to open a file, read and write the metadata, then close the file. While open, portions of the file might be maintained in RAM data structures. Memory usage can vary considerably depending on file format and access options. The file may be opened for read-only or read-write access, with typical exclusion for both modes.
Errors result in raising of an libxmp.XMPError exception.
Parameters: | file_path – Path to file to open. |
---|
Todo
Documentation
Determine if XMP can be written into the file.
Determines if a given libxmp.core.XMPMeta object can be written into the file.
Parameters: | xmp_obj – An libxmp.core.XMPMeta object |
---|---|
Returns: | true if libxmp.core.XMPMeta object writeable to file. |
Return type: | bool |
Close file after use. XMP will not be written to file until this method has been called.
Parameters: | close_flags – One of the close flags |
---|---|
Raises XMPError: | |
in case of errors. |
Todo
Change signature into using kwargs to set option flag
Get XMP from file.
Returns: | A new libxmp.core.XMPMeta instance. |
---|---|
Raises XMPError: | |
in case of errors. |
Open a given file and read XMP from file. File must be closed again with close_file()
Parameters: | file_path (str) – Path to file to open. |
---|---|
Raises XMPError: | |
in case of errors. |
Todo
Change signature into using kwargs to set option flag
Write XMPMeta object to file. See also can_put_xmp().
Parameters: | xmp_obj – An libxmp.core.XMPMeta object |
---|
Helper utilities.
Terminate usage of library.
Normally function should not be called. Cases however might exists where memory clean-up is needed, then this method may be called.
Warning
After this function have been called, any call to methods in libxmp will result in a crash of Python.
Extracts all XMP data from a given XMPMeta instance organizing it into a standard Python dictionary.
Extracts all XMP data from a given file organizing it into a standard Python dictionary.
Parameters: | file_path – Path to file to open. |
---|---|
Returns: | An empty dictionary if there’s no valid XMP in the file passed as an argument. |
Constants from exempi headers.
Creates the options bit mask for consumption by exempi C functions.
Example:
opt = consts.options_mask( consts.XMP_SERIAL_OPTIONS, **kwargs )
or:
opt = consts.options_mask( consts.XMP_SERIAL_OPTIONS, omit_packet_wrapper=True )