Reading¶
This guide demonstrates how to read EXIF metadata from image files using tagkit.
Command Line Interface¶
Tags can be read with the CLI using the view command:
tagkit [global-options] view [options] FILE_OR_PATTERN
FILE_OR_PATTERN can be a single file name, a glob, or a regex pattern.
The CLI will infer which to use based on the pattern, but you can be explicit with the --regex or --glob options.
Glob patterns must be enclosed in quotes, for example: tagkit view "*.jpg".
The default output is a table. Use the --json option for JSON output, which is useful for downstream processing.
Use --tags to filter for specific tags.
Examples¶
# View EXIF data for a single file
tagkit view photo.jpg
# View specific tags from multiple files using a glob pattern
tagkit view "*.jpg" --tags Make,Model,DateTimeOriginal
# View EXIF data as JSON
tagkit view --json photo.jpg
# View EXIF data from thumbnails
tagkit view --thumbnail photo.jpg
# Use a regex pattern to match files
tagkit view ".*\d{4}-\d{2}-\d{2}.*\.jpg"
API¶
Error Handling¶
Tagkit defines several custom exceptions. An example of handling errors when writing tags:
from tagkit.image.exif import ExifImage
from tagkit.core.exceptions import TagkitError
try:
exif = ExifImage("image.jpg")
except FileNotFoundError:
print("Error: Image file not found")
except TagkitError as e:
print(f"Error reading EXIF data: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
Next Steps¶
Now that you’ve learned how to read EXIF data, check out:
Basic Writing Example to learn how to write EXIF data
Batch Processing Example for handling multiple files efficiently