Navigation

PyExifTool is a Python library to communicate with an instance of Phil
Harvey’s excellent ExifTool command-line application. The library
provides the class ExifTool that runs the command-line
tool in batch mode and features methods to send commands to that
program, including methods to extract meta-information from one or
more image files. Since exiftool is run in batch mode, only a
single instance needs to be launched and can be reused for many
queries. This is much more efficient than launching a separate
process for every single query.

The source code can be checked out from the github repository with

git clone git://github.com/smarnach/pyexiftool.git

Alternatively, you can download a tarball. There haven’t been any
releases yet.

You can pass the file name of the exiftool executable as an
argument to the constructor. The default value exiftool will
only work if the executable is in your PATH.

Most methods of this class are only available after calling
start(), which will actually launch the subprocess. To
avoid leaving the subprocess running, make sure to call
terminate() method when finished using the instance.
This method will also be implicitly called when the instance is
garbage collected, but there are circumstance when this won’t ever
happen, so you should not rely on the implicit process
termination. Subprocesses won’t be automatically terminated if
the parent process exits, so a leaked subprocess will stay around
until manually killed.

A convenient way to make sure that the subprocess is terminated is
to use the ExifTool instance as a context manager:

withExifTool()aset:...

Warning

Note that there is no error handling. Nonsensical
options will be silently ignored by exiftool, so there’s not
much that can be done in that regard. You should avoid passing
non-existent files to any of the methods, since this will lead
to undefied behaviour.

This method accepts any number of parameters and sends them to
the attached exiftool process. The process must be
running, otherwise ValueError is raised. The final
-execute necessary to actually run the batch is appended
automatically; see the documentation of start() for
the common options. The exiftool output is read up to the
end-of-output sentinel and returned as a raw bytes object,
excluding the sentinel.

The parameters must also be raw bytes, in whatever
encoding exiftool accepts. For filenames, this should be the
system’s filesystem encoding.

Note

This is considered a low-level method, and should
rarely be needed by application developers.

This method is similar to execute(). It
automatically adds the parameter -j to request JSON output
from exiftool and parses the output. The return value is
a list of dictionaries, mapping tag names to the corresponding
values. All keys are Unicode strings with the tag names,
including the ExifTool group name in the format <group>:<tag>.
The values can have multiple types. All strings occurring as
values will be Unicode strings.

The parameters to this function must be either raw strings
(type str in Python 2.x, type bytes in Python 3.x) or
Unicode strings (type unicode in Python 2.x, type str
in Python 3.x). Unicode strings will be encoded using
system’s filesystem encoding. This behaviour means you can
pass in filenames according to the convention of the
respective Python version – as raw strings in Python 2.x and
as Unicode strings in Python 3.x.

This method will issue a UserWarning if the subprocess is
already running. The process is started with the -G and
-n as common arguments, which are automatically included
in every command you run with execute().

Encode filename to the filesystem encoding with ‘surrogateescape’ error
handler, return bytes unchanged. On Windows, use ‘strict’ error handler if
the file system encoding is ‘mbcs’ (which is the default encoding).