Skip to main content

python-exiv2 is a low level interface (or binding) to the exiv2 C++ library. It is built using SWIG to automatically generate the interface code. The intention is to give direct access to all of the top-level classes in libexiv2, but with additional “Pythonic” helpers where necessary.

Introduction

There are several other ways to access libexiv2 from within Python. The first one I used was pyexiv2 (old). After its development ceased I moved on to using gexiv2 and PyGObject. This works well, providing a Metadata object with high level functions such as set_tag_string and set_tag_multiple to get and set metadata values.

A more recent development is pyexiv2 (new). This new project is potentially very useful, providing a simple interface with functions to read and modify metadata using Python dict parameters.

For more complicated metadata operations I think a lower level interface is required, which is where this project comes in.

This project is at an early stage of development. It is already usable, but please email jim@jim-easterbrook.me.uk if it doesn’t work for you. Here is an example of what it can do:

Python 3.6.12 (default, Dec 02 2020, 09:44:23) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import exiv2
>>> image = exiv2.ImageFactory.open('IMG_0211.JPG')
>>> image.readMetadata()
>>> data = image.exifData()
>>> data['Exif.Image.Artist']._print()
'Jim Easterbrook'
>>>

Documentation

The libexiv2 library is well documented for C++ users, in Doxygen format. Recent versions of SWIG can convert this documentation to pydoc format in the Python interface:

$ pydoc3 exiv2.Image.exifData

Help on method_descriptor in exiv2.Image:

exiv2.Image.exifData = exifData(...)
    Returns an ExifData instance containing currently buffered
        Exif data.

    The contained Exif data may have been read from the image by
    a previous call to readMetadata() or added directly. The Exif
    data in the returned instance will be written to the image when
    writeMetadata() is called.

    :rtype: :py:class:`ExifData`
    :return: modifiable ExifData instance containing Exif values

Assignment

libexiv2 stores metadata values in a generalised container whose type can be set by the type of a value assigned to it, for example:

exifData["Exif.Image.SamplesPerPixel"] = uint16_t(162);

This forces the Exif.Image.SamplesPerPixel value to be an unsigned short. Python doesn’t have such specific integer types, so if you want to set the type you need to create an exiv2 value of the appropriate type and assign that:

exifData["Exif.Image.SamplesPerPixel"] = exiv2.UShortValue(162)

This allows you to set the value to any type, just like in C++, but the Python interface warns you if you set a type that isn’t the default for that tag. Otherwise you can set the value to any Python object and let libexiv2 convert the string representation of that object to the appropriate type:

exifData["Exif.Image.SamplesPerPixel"] = 162

Iterators

Several libexiv2 classes use C++ iterators to expose private data, for example the ExifData class has a private member of std::list<Exifdatum> type. The classes have public begin and end methods that return std::list iterators. In C++ you can dereference one of these iterators to access the Exifdatum object, but Python doesn’t have a dereference operator.

This Python interface converts the std::list iterator to a Python object that has a curr method to return the list value. It is quite easy to use:

Python 3.6.12 (default, Dec 02 2020, 09:44:23) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import exiv2
>>> image = exiv2.ImageFactory.open('IMG_0211.JPG')
>>> image.readMetadata()
>>> data = image.exifData()
>>> b = data.begin()
>>> b.curr().key()
'Exif.Image.ProcessingSoftware'
>>>

The Python iterators also have a next method that increments the iterator as well as returning the list value. This can be used to iterate over the data in a very C++ like style:

>>> data = image.exifData()
>>> b = data.begin()
>>> e = data.end()
>>> while b != e:
...     b.next().key()
...
'Exif.Image.ProcessingSoftware'
'Exif.Image.ImageDescription'
[skip 227 lines]
'Exif.Thumbnail.JPEGInterchangeFormat'
'Exif.Thumbnail.JPEGInterchangeFormatLength'
>>>

You can also iterate in a more Pythonic style:

>>> data = image.exifData()
>>> for item in data:
...     item.key()
...
'Exif.Image.ProcessingSoftware'
'Exif.Image.ImageDescription'
[skip 227 lines]
'Exif.Thumbnail.JPEGInterchangeFormat'
'Exif.Thumbnail.JPEGInterchangeFormatLength'
>>>

I think this is much better.

Warning: segmentation faults

It is easy to crash python-exiv2 if you delete objects which contain data that another object is pointing to. For example, deleting an Image after extracting its metadata can cause a segfault when the metadata is accessed. Ideally the Python interface to libexiv2 would use Python objects’ reference counts to ensure this doesn’t happen, preventing the deletion of the Image object until all references to it have been deleted. Unfortunately I haven’t found a sensible way to do this in the Python interface, so some care is needed when using it.

Error handling

libexiv2 has a multilevel warning system a bit like Python’s standard logger. The Python interface redirects all Exiv2 messages to Python logging with an appropriate log level.

Installation

Python “wheels” are available for Windows (Python 3.5 to 3.9) and Linux (Python 3.6 to 3.10). These include the libexiv2 library and should not need any other software to be installed. They can be installed with Python’s pip package. For example, on Windows:

C:\Users\Jim>pip install python-exiv2

or on Linux:

$ sudo pip3 install python-exiv2

You can install for a single user with the --user option:

$ pip3 install --user python-exiv2

If the available wheels are not compatible with your operating system then pip will download the python-exiv2 source and attempt to compile it. For more information, and details of how to compile python-exiv2 and libexiv2, see INSTALL.rst.

Problems?

I think it’s a bit early in the project to be using the “issues” page. Please email jim@jim-easterbrook.me.uk if you find any problems (or solutions!).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-exiv2-0.4.0.zip (4.2 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

python_exiv2-0.4.0-cp39-cp39-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.9Windows x86-64

python_exiv2-0.4.0-cp38-cp38-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.8Windows x86-64

python_exiv2-0.4.0-cp37-cp37m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.7mWindows x86-64

python_exiv2-0.4.0-cp36-cp36m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.6mWindows x86-64

python_exiv2-0.4.0-cp35-cp35m-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.5mWindows x86-64

File details

Details for the file python-exiv2-0.4.0.zip.

File metadata

  • Download URL: python-exiv2-0.4.0.zip
  • Upload date:
  • Size: 4.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.26.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.12

File hashes

Hashes for python-exiv2-0.4.0.zip
Algorithm Hash digest
SHA256 a049b81e9123ba0b379070ac2b0eb3589fc0e54bfeb70bceb45b75e15e1a6a12
MD5 30f0fb873bee4b2aebd5b8c4f3357cab
BLAKE2b-256 c27461ecfc44f224367067ec620afc597308cfbc2c53621254ecb16fed613294

See more details on using hashes here.

File details

Details for the file python_exiv2-0.4.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: python_exiv2-0.4.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.26.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.12

File hashes

Hashes for python_exiv2-0.4.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8612b0266c59dc0adce2749b3a5e9f2fd603db466bebb11a6036d17d745768ca
MD5 53ac8bcdeeec022958b5d11c7a9915da
BLAKE2b-256 2701455105238b0f139f77f99f71df91656c4090b9b02ab606bd323e78b2651c

See more details on using hashes here.

File details

Details for the file python_exiv2-0.4.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: python_exiv2-0.4.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.26.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.12

File hashes

Hashes for python_exiv2-0.4.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 dafa9af8ed58b151f57fea8c650da4c6c9090a87142e17163313c41aef890baa
MD5 e2b8b2565d70d1ff4aa9a9ce65335858
BLAKE2b-256 764413f25fa1430384cc1feb90e145e920f2d88830ff0ca5e5c6d2a2cdc2d1f4

See more details on using hashes here.

File details

Details for the file python_exiv2-0.4.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: python_exiv2-0.4.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.26.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.12

File hashes

Hashes for python_exiv2-0.4.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 dc180a92bb9ad694833034216d9ad5473c029e1c6fd5a49edf251c031cb0beea
MD5 c5c6fab1281f8a9a9c72c79e7f4388d7
BLAKE2b-256 d4c96d577fdc5068e174b56b0521b11c7be7346b05ddd45dc7449d71e7fb8684

See more details on using hashes here.

File details

Details for the file python_exiv2-0.4.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: python_exiv2-0.4.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.26.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.12

File hashes

Hashes for python_exiv2-0.4.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 4e89975445b339c9739b0f3b6327f5de68280e55e56593f3b05a1b25b0e76b41
MD5 2c66b038de1f13442fcffff35d3b39f8
BLAKE2b-256 2e9729184cdcf041208821e2118e2b99c86eaebc5283c5e550fa2ce625b0d211

See more details on using hashes here.

File details

Details for the file python_exiv2-0.4.0-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: python_exiv2-0.4.0-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.26.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.12

File hashes

Hashes for python_exiv2-0.4.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 33beac794ef0ef4d2d3109332b125f611d49f48387b5bdca180519de041ca5b1
MD5 41ddc037e07eab04eb259cfde514d9ce
BLAKE2b-256 98eee6011697ffc3222b787a9ff17229f3e901f4d41a33212412920fdd84367a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page