pyexiv2 – the best choice for photo metadata manipulation in python

Some days ago, the python community received an early easter gift: version 0.2.0 of the image metadata library pyexiv2 was released. First of all, I want to congratulate project maintainer Olivier Tilloy and all his contributors to this important milestone. Since Geotagging, Copyright Assignment, Timestamp fixing and other image metadata manipulation techniques are commonly used by photographers, it is important to have free software tools in this field.

While there are a lot of command line tools for metadata manipulation, only a few python libraries deal with this subject. A recent Article on EXIF Extraction in Python introduces some of them, but unfortunately doesn’t cover the newly-released pyeviv2. So I decided to spread the word about it.

What is pyexiv2?

pyexiv2 is a Python binding to exiv2, the C++ library for manipulation of EXIF, IPTC and XMP image metadata. As mentioned above, it allows you to perform many metadata manipulation tasks, such as correcting wrong photo timestamps, assigning GPS coordinates to your photos or simply dumping out the EXIF metadata generated by your camera.

Why should I use pyexiv2 instead of EXIF.py or similar libs?

  • pyexiv2 also supports Camera RAW (.NEF, .CRW, .ORF, etc) files and even gives you access to their embedded preview images, which allows you to perform very fast RAW-to-JPEG conversions.
  • It is able to decode many important Makernote Tags, such as LensTypes and ProgramModes
  • Being C++-based, pyexiv2 offers ultra-fast read and write support for metadata. In my tests, pyexiv2′s underlying library exiv2 was magnitudes faster than exiftool when it came to writing metadata
  • It provides a convenient Python API, no need to call external tools (as with various python-to-exiftool wrappers)
  • pyexiv2 automatically converts many tag values to approbriate Python datatypes (e.g. Exif.Image.Datetime returns a Datetime object), freeing you from the parsing date strings like '2004-07-13T21:23:44Z'. Of course, you can also access the raw value of a tag.
  • [UPDATE]: I almost forgot to mention the most important merit of pyexiv2: it has a very robust metadata parser that is tested against hundreds of sample photos from different camera models. While I appreciate the various pure-Python EXIF parsers for educational purposes, they never came close to pyexiv2′s stability.

What is new in version 0.2.0 ?

pyexiv2 0.2.0 handles XMP metadata and supports reading images from stream using the from_buffer method. This means that you can provide pyexiv2 with a variable holding the image data, in prior versions, only the filepath of the image was accepted. Furthermore, pyexiv2 is now compiled against libevix2 0.19, which brought huge performance improvements for reading metadata. Finally, it exposes all recent enhancements of the libexiv2 API, such as preview image access.
pyexiv2 is a complete, non-backwards-compatible rewrite and features an improved, better documented API. It was compiled and tested under Linux and Windows.

Installation & first steps

Windows folks can download the .exe-Installer (requires Python 2.6 or newer on your system), Linux folks have to get the source code and install the required dependencies before compiling pyexiv 0.2.0. There are also pre-built packages in debian experimental, but these are not suitable for production environments.

The excellent introductory tutorial on pyexiv2′s website will make you quickly proficient with the library.

About Franz Buchinger

Digital Photography/Python Aficionado from Vienna, Austria. Tamed his chaotic photo collection with some magic metadata spells. Decided to share his humble EXIF, IPTC and XMP knowledge in this blog.
This entry was posted in EXIF-Hacks. Bookmark the permalink.
  • chaos

    Just found you via google while searching for a python exif/iptc module. The tool looks great on paper, but (as a python newbie) I haven’t found a way to install it (or better install the dependencies first) on a MacOsX system or a no-admin-access linux system without spending more time compiling local libs than I would have spend editing the exif data by hand.

    If you know of any tutorial or prebuild binaries I would be very thankfull.

  • http://www.picurl.org Franz Buchinger

    sorry for the late reply… We ‘re drowning in comment spam.

    Robin Mills has an excellent tutorial on building pyexiv2 on Mac OS X: http://clanmills.com/articles/gpsexiftags/macos.shtml

    hth,

    Franz

  • reco

    franz
    yep we found that but still not work for us. did you manage to build it on mac osx 10.6?

  • fbuchinger

    As I don't own or use a mac, I have never tried to compile pyexiv2 on macos

    x.

    I recommend to contact Robin Mills directly regarding this issue. Maybe he

    can provide you with a build for mac osx 10.6 or update his building howto.

    Franz

    2010/11/4 Disqus <>

  • Pymind

    just try:
    brew install exiv2

    https://github.com/mxcl/homebr…

  • pymind

    Sorry for the misunderstanding:)

blog comments powered by Disqus