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.