I'm looking for good exif (Exchangeable image file format) manipulation library for python. I prefer flexibility (e.g., ability to retrieve providers' proprietary tags) than processing speed. What would you suggest?
-
1Perhaps the question should read: "What options are available to edit Exif (Exchangeable image file format) using python that emphasize feature set (e.g. ability to retrieve providers' proprietary tags and compatiblity with a wide variety of image formats) over speed?" – dlm Aug 06 '13 at 20:08
-
2@Wooble et al: "If this question can be reworded to fit the rules in the help center, please edit the question or leave a comment." I did the latter, but the Q closed without further comment. What gives? (Just trying to understand, and don't want to waste time commenting/editing questions if its a foregone conclusion) – dlm Aug 12 '13 at 02:04
-
I wanted other developers opinions when asking this question! PackageOpinionOverflow? – Derek Litz Aug 20 '13 at 21:50
-
1Keep in mind that pretty much all non-exiv2 solutions here will not be able to access `MakerNote`. In this EXIF tag, camera manufacturers add their own tags that hold valuable information. So you would only get the basic tags with most libraries from the below answers. – user136036 Feb 13 '20 at 14:32
12 Answers
You might want to check out exif-py:
Python library to extract EXIF data from tiff and jpeg files. Very easy to use - $ ./EXIF.py image.jpg
or the Python Imaging Library (PIL):
The Python Imaging Library (PIL) adds image processing capabilities to your Python interpreter. This library supports many file formats, and provides powerful image processing and graphics capabilities.
There's also the aptly named pyexif: http://pyexif.sourceforge.net/
The pyexif python library and tools aims at extracting EXIF information from Jpeg and Tiff files which include it. This information is typically included in images created using digital imaging devices such as digital cameras, digital film scanners, etc.
However, it looks like pyexif hasn't been updated in quite while. They recommend if theirs isn't doing the trick to check out EXIF-py, so you should probably try that one first, as their sourceforge page seems to have some activity there lately, though not much. Finally, using PIL you could do this:
from PIL import Image
from PIL.ExifTags import TAGS
def get_exif(fn):
ret = {}
i = Image.open(fn)
info = i._getexif()
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
ret[decoded] = value
return ret
Disclaimer:
I actually have no idea which is best, this is just what I was able to piece together with Google. :)

- 94,605
- 21
- 231
- 225

- 480,997
- 81
- 517
- 436
-
23None of these "solutions" can write EXIF tags back, so they are not a solution to the question. – odinho - Velmont Jan 03 '11 at 21:41
-
Nice overview. Just a note: exif-py is currently not compatible with Python 3.x it seems (tested with Python 3.3.3, see also https://github.com/ianare/exif-py/issues/12). – cel Jan 11 '14 at 19:39
I've been using pyexiv2 myself recently, and it seems to fit my needs quite nicely. Perhaps it might suit yours as well.
Note: pyexiv2 is only for python2, for python3 use py3exiv2

- 75,001
- 122
- 434
- 781
-
10For the record: pyexiv2 seems to be the best-maintained of them all, and the most complete (including writing EXIF tags back to the file). – rbp Oct 25 '10 at 22:15
-
1
-
2Maintenance seems to be slowed down, and installation on Mac is a hell. :/ – Vortexfive Sep 11 '12 at 18:06
-
7For those who care: Unfortunately, pyexiv2 is only available for Python 2. – texnic Sep 18 '12 at 18:58
-
1This will work equally well with either Python 2 or 3, which makes GExiv2 an excellent replacement for pyexiv2, which only supports Python 2. – jno May 13 '13 at 12:55
-
Can you test this on this Question, download the images, and try to get the ImageDescription. http://stackoverflow.com/questions/22173902/how-to-get-image-title-in-python-django – A.J. Mar 06 '14 at 07:45
-
1
Exiv2 Based solutions
Exiv2 (exiv2: http://exiv2.org/) is a mature, open-source C++ library that supports reading and writing metadata to many image types (JPEG, PNG, TIFF and many raw formats), understands standard (Xmp, IPTC and Exif) and non-standard metadata ("Makernotes"), and runs on multiple platforms (Windows, Linux, and, with some work, Mac).
Python bindings to exiv2 are:
- gexiv2 (a multi-language binding, but works with python 2.6/2.7/3.X): https://wiki.gnome.org/gexiv2
- pyexiv2 (no longer supported, but works with python 2.6/2.7): http://tilloy.net/dev/pyexiv2/
One advantage of pyexiv2 is that there is a windows build available for python 2.7. A windows build request for gexiv2 is here: https://bugzilla.gnome.org/show_bug.cgi?id=712441
exiv2 and the bindings are all open source (GPL).

- 13,076
- 9
- 63
- 101

- 4,054
- 2
- 23
- 19
This article describes a Python module for writing EXIF metadata (and not just reading them) using pure Python. Apparently, none of PIL, pyexif, nor EXIF-py support writing EXIF. pyexiv2 appears to be bleeding-edge and platform-specific.

- 41,115
- 10
- 83
- 93
Use PIL :)
import os,sys
from PIL import Image
from PIL.ExifTags import TAGS
if __name__ == '__main__':
for (k,v) in Image.open(sys.argv[1])._getexif().iteritems():
print '%s = %s' % (TAGS.get(k), v)
os.system('pause')

- 65
- 1
- 1
-
2Pure PIL / Pillow does not allow modifying EXIF tags. But there a small library helping with that: https://github.com/hMatoba/Pyxif – Simon Steinberger Jan 27 '15 at 08:21
The page at http://redmine.yorba.org/projects/gexiv2/wiki (became https://wiki.gnome.org/Projects/gexiv2) reads now:
This will work equally well with either Python 2 or 3, which makes GExiv2 an excellent replacement for pyexiv2, which only supports Python 2.
So, both Python2 and Python3 are now supported by GExiv2.
Good news.

- 997
- 1
- 10
- 18
-
2the link does not work. this works https://wiki.gnome.org/Projects/gexiv2 – user881300 Sep 22 '16 at 11:21
-
I have been using my own wrappers around http://www.sno.phy.queensu.ca/~phil/exiftool/ -- the reason is that it is very complete, the dev is very active. And not being able to support almost all image formats is a absolute showstopper for the project it is needed for
The drawback of course is that it isn't python, so you would need to use subprocess calls, as I do.

- 39
- 1
-
There's a python wrapper for exiftool https://github.com/smarnach/pyexiftool. One vote for exiftool for the fact that it is very complete. – Long Vu Jun 26 '12 at 14:28
-
You might also look at Gheorghe Milas' jpeg.py library at http://www.emilas.com/jpeg/, which is "A python library to parse, read and write JPEG EXIF, IPTC and COM metadata."
A drawback is that he appears to be hosting his domain on a dynamic IP via DynDNS, so it's not always available.
I started to write my own small library which is based on the code in PIL. check it here.

- 15,573
- 16
- 56
- 75

- 65,406
- 61
- 242
- 386
somehow i get an attributeError for _getexif with Paolo's code above.. I am using Python 2.6.6 and PIL 1.1.7. Is _getexif obsolete now??
Here's a small modification that worked for me.
from PIL import Image
from PIL.ExifTags import TAGS
def get_exif(fn):
ret = {}
i = Image.open(fn)
# info = i._getexif()
info = i.tag.tags
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
ret[decoded] = value
return ret

- 2,660
- 2
- 29
- 48
In Python 2.6 the place of module is different. Use this:
import Image
from ExifTags import TAGS

- 448
- 6
- 8