Python wrapper for exiftool to extract and manipulate metadata from image, video, and other media files
npx @tessl/cli install tessl/pypi-pyexiftool@0.5.0A Python library that provides a wrapper interface to communicate with Phil Harvey's ExifTool command-line application for extracting and manipulating metadata from image, video, and other media files. PyExifTool runs ExifTool in batch mode for efficient processing of multiple files and supports reading and writing EXIF, IPTC, XMP, and other metadata formats.
pip install PyExifToolimport exiftoolCommon pattern for helper class:
from exiftool import ExifToolHelperLow-level access:
from exiftool import ExifToolException handling:
from exiftool import exceptionsimport exiftool
# Recommended approach using ExifToolHelper
files = ["image1.jpg", "image2.png", "video.mp4"]
with exiftool.ExifToolHelper() as et:
# Get all metadata
metadata = et.get_metadata(files)
for data in metadata:
print(f"File: {data['SourceFile']}")
print(f"Date: {data.get('EXIF:DateTimeOriginal', 'N/A')}")
# Get specific tags
tags = et.get_tags(files, ['EXIF:Make', 'EXIF:Model'])
# Set tags
et.set_tags('image.jpg', {'EXIF:Artist': 'John Doe'})
# Low-level approach for advanced usage
with exiftool.ExifTool() as et:
# Execute direct exiftool commands
result = et.execute_json('-j', 'image.jpg')
# Execute raw commands
output = et.execute('-n', '-g', 'image.jpg')PyExifTool provides three main classes for different use cases:
The library runs ExifTool in batch mode using subprocess communication, keeping a single ExifTool process running for multiple operations to maximize performance. All classes support context manager patterns for automatic resource management.
Low-level interface to the exiftool subprocess with direct command execution, JSON parsing, and subprocess lifecycle management. Provides maximum control and flexibility for advanced users.
class ExifTool:
def __init__(self, executable=None, common_args=None, win_shell=False, config_file=None, encoding=None, logger=None): ...
def run(self): ...
def terminate(self, timeout=30, _del=False): ...
def execute(self, *params, raw_bytes=False): ...
def execute_json(self, *params): ...User-friendly wrapper with convenience methods for common metadata operations, automatic error checking, and simplified file handling. Recommended for most users.
class ExifToolHelper(ExifTool):
def __init__(self, auto_start=True, check_execute=True, check_tag_names=True, **kwargs): ...
def get_metadata(self, files, params=None): ...
def get_tags(self, files, tags, params=None): ...
def set_tags(self, files, tags, params=None): ...Experimental functionality for specialized use cases including batch operations, keyword management, and file-to-file tag copying.
class ExifToolAlpha(ExifToolHelper):
def get_tag(self, filename, tag): ...
def copy_tags(self, from_filename, to_filename): ...
def set_keywords(self, filename, mode, keywords): ...Comprehensive exception hierarchy for different error conditions with detailed error information including exit codes and command output.
class ExifToolException(Exception): ...
class ExifToolProcessStateError(ExifToolException): ...
class ExifToolExecuteException(ExifToolException): ...
class ExifToolRunning(ExifToolProcessStateError): ...
class ExifToolNotRunning(ExifToolProcessStateError): ...
class ExifToolExecuteError(ExifToolExecuteException): ...
class ExifToolOutputEmptyError(ExifToolExecuteException): ...
class ExifToolJSONInvalidError(ExifToolExecuteException): ...
class ExifToolVersionError(ExifToolException): ...
class ExifToolTagNameError(ExifToolException): ...Package version and platform-specific constants for advanced configuration.
__version__ = "0.5.6"
# Platform detection
PLATFORM_WINDOWS: bool
PLATFORM_LINUX: bool
# Executable and configuration defaults
DEFAULT_EXECUTABLE = "exiftool"
DEFAULT_BLOCK_SIZE = 4096
EXIFTOOL_MINIMUM_VERSION = "12.15"
# Platform-specific constants
SW_FORCEMINIMIZE = 11 # Windows show window constant
PR_SET_PDEATHSIG = 1 # Linux process death signal constant# Type aliases for documentation
FilePath = Union[str, Path]
FileList = Union[FilePath, List[FilePath]]
TagDict = Dict[str, Any]
MetadataList = List[TagDict]
ParamsList = Optional[Union[str, List[str]]]