exif
raw JSON → 1.6.1 verified Fri May 01 auth: no python
A Python library to read and modify image EXIF metadata with a simple, intuitive API. Current version 1.6.1 requires Python >=3.7. Releases are infrequent, but the library is stable and widely used.
pip install exif Common errors
error AttributeError: 'Image' object has no attribute 'make' ↓
cause The tag 'make' is not present in the EXIF data. The library raises AttributeError for missing tags since v1.0.0.
fix
Use getattr(img, 'make', 'Unknown') or the .get() method: img.get('make').
error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte ↓
cause The image was opened in text mode instead of binary mode.
fix
Open the file with open('image.jpg', 'rb') (binary read mode).
error OSError: [Errno 9] Bad file descriptor ↓
cause Trying to write EXIF data to a file opened in read-only mode ('rb') or after the file has been closed.
fix
Open with 'rb+' (read and write binary) and ensure the file is not closed before calling img.write().
Warnings
breaking Version 1.0.0 changed from returning None to raising AttributeError when a tag does not exist. Accessing a tag not present in the image will raise an AttributeError, not return None. ↓
fix Use hasattr() or the tag's 'get' method (e.g., img.get('make', 'Unknown')).
gotcha You must open the image file in binary read mode ('rb'), not text mode. Opening in text mode will cause UnicodeDecodeError or corrupt EXIF parsing. ↓
fix Always use open('image.jpg', 'rb') when reading images with exif.
gotcha Writing EXIF data requires the file to be opened in 'rb+' mode and the image to be seekable. Many users forget to open with write permission or close the file before writing. ↓
fix Open with 'rb+', modify tags, then call img.write() before closing.
Imports
- Image wrong
import exif.Imagecorrectfrom exif import Image
Quickstart
from exif import Image
with open('image.jpg', 'rb') as f:
img = Image(f)
if img.has_exif:
print(f"Make: {img.make}")
print(f"Model: {img.model}")
print(f"Date/Time Original: {img.datetime_original}")
else:
print("No EXIF data found.")