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

Windows

Python “wheels” are available for Windows Python versions from 3.5 to 3.9. These include the libexiv2 library and should not need any other software to be installed. They can be installed with pip, for example:

C:\Users\Jim>"c:\Program Files\Python38\python.exe" -m pip install python-exiv2

Linux

Python “wheels” are available for Linux Python versions from 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 pip, for example:

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. This requires the “development headers” of Python3 and an appropriate compiler & linker to be installed.

If the development headers of libexiv2 are installed then pip will try to build python-exiv2 to use the installed version. Otherwise it will use the copy included in the download, which may not be compatible with your operating system.

Building python-exiv2

If you want customise your installation of python-exiv2 you can build it yourself. Download and unpack a source archive from PyPI or GitHub, then switch to the python-exiv2 directory. The setup.py script used to install python-exiv2 will use the libexiv2 installed by your operating system if it can find it. This usually requires the “development headers” package to be installed. In this case you just need to build python-exiv2 and install it as follows:

pip wheel -v .
sudo pip3 install python_exiv2-0.2.3-cp36-cp36m-linux_x86_64.whl

(The name of the wheel file will depend on the python-exiv2 version, your Python version, and the system architecture.)

If you want to use your own downloaded copy of libexiv2 then a few more steps are required. First you need to copy some files using the copy_libexiv2.py script. This has two parameters: the exiv2 directory and the exiv2 version. For example:

python3 utils/copy_libexiv2.py ../exiv2-0.27.4-Linux64 0.27.4

This copies the exiv2 header files and runtime library to the directory libexiv2_0.27.4/linux/. Now you can run pip as before. Note that pip will still use the system installed version of libexiv2 if it can find it. Uninstalling the “development headers” package will prevent this.

When you try to import exiv2 into Python it’s possible you might get an error like OSError: /lib64/libm.so.6: version `GLIBC_2.29' not found (required by /usr/lib64/python3.6/site-packages/exiv2/libexiv2.so.0.27.4). This happens if the downloaded copy of libexiv2 was built for a newer version of the GNU C library than is installed on your computer. In this case the only option is to build libexiv2 from source.

Download the exiv2 source archive, then follow the build instructions in README.md, but make sure you install to a local directory rather than /usr/local:

$ mkdir build && cd build
$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../local_install
$ cmake --build .
$ make install

Then, back in your python-exiv2 directory, copy sources from the newly created local directory:

python3 utils/copy_libexiv2.py ../exiv2-0.27.4-Source/local_install 0.27.4

Then run pip as before.

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.3.0.zip (6.4 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.3.0-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (6.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.12+ x86-64

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

Uploaded CPython 3.9Windows x86-64

python_exiv2-0.3.0-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (6.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.12+ x86-64

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

Uploaded CPython 3.8Windows x86-64

python_exiv2-0.3.0-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (5.9 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64

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

Uploaded CPython 3.7mWindows x86-64

python_exiv2-0.3.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (5.9 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64

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

Uploaded CPython 3.6mWindows x86-64

python_exiv2-0.3.0-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (5.9 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.12+ x86-64

python_exiv2-0.3.0-cp35-cp35m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.5mWindows x86-64

File details

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

File metadata

  • Download URL: python-exiv2-0.3.0.zip
  • Upload date:
  • Size: 6.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.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.3.0.zip
Algorithm Hash digest
SHA256 d97db3601b379f43335b0471e787190820fd32afb6bd5390cf02932bb544f463
MD5 fb4aaa3c08fe9da4dbca75e91a5f6f07
BLAKE2b-256 e45cbca4954fab32106808ca74dec88f73402f2eaa0d9bde2afc39015cf71cf6

See more details on using hashes here.

File details

Details for the file python_exiv2-0.3.0-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for python_exiv2-0.3.0-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 29b6ea30039eba3798b6569d45fd53c4211f7b6a27f334f911a3db6309c88aec
MD5 5a55d5c8d935490d740fb665a1c766a8
BLAKE2b-256 7d738deb3a296f532743dc8617aacfc9029529063b84c48c553ed0b8292f97a8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_exiv2-0.3.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.24.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.3.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 0d70b8772802178016f08620be91c8510efe89138a8cefc3f3a2a6a4345b6345
MD5 aeaa8ea1f9621c4b51b14d941c4837d5
BLAKE2b-256 e5c2c9384545c773a97af600d983fcc7d513336c1acdc2d0406f3ecabe4b6c02

See more details on using hashes here.

File details

Details for the file python_exiv2-0.3.0-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for python_exiv2-0.3.0-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 a69c2fb246fa32a1ee67f77aa5ca8b010f93f17a227b88fbd7e323654bf279fd
MD5 6d80739ca53ccb58e6a063fa243a8ba5
BLAKE2b-256 62331628b16f4f5ea9b580e18eb19d183ed9cf4cfbd38c3cb6608cf89de28e0a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_exiv2-0.3.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.24.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.3.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 1ad570316f53da056a4cf215ea6480c35fd85f32bafbcce8604e375d56926926
MD5 1897f58e648f72fc3b8f1b862755cad5
BLAKE2b-256 3a0afe6088a409387764cebdee1c602fd3ff17cef80e29e273e5cfc89b7b9969

See more details on using hashes here.

File details

Details for the file python_exiv2-0.3.0-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for python_exiv2-0.3.0-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 d0cc09ba769262f059191c3870a23f76b31067d6fcfbda084afca2f45381811e
MD5 11088e72aab576b83f38a461a1561169
BLAKE2b-256 fd3ec0e5422a46fabf831ae5443974530a81826da2f25e5bfecce4e62339eff5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_exiv2-0.3.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.24.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.3.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ba1556af0c9242275207cbd7adb94db8108c975a537f3bbb6332f56035a5a569
MD5 ec87d9dc248f4a27ca1d3579b8a06b56
BLAKE2b-256 4a68bb145e79984bc496bfa30692b70efdca5e1f575b576fcaf01903254d728a

See more details on using hashes here.

File details

Details for the file python_exiv2-0.3.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for python_exiv2-0.3.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 3903d6bb570dce7fff7230201fe911274b1388ca4d8a848219009f7e652a1126
MD5 384e9b816a8db79a8065c3f4658a7ec0
BLAKE2b-256 0c85c37a8623b0581c12ff712a90767f5639e4c08ca42e3274182de534df4db5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_exiv2-0.3.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.24.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.3.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 ce6be934a9157a186897616c1b8d340d29785dcedf7ab413d3e701dedde9a7fa
MD5 90eb110f0633503f759e889bcd3ede3c
BLAKE2b-256 e74cd6e11a2f112bd62feaae1500afd80fc3dc90c6297aaa89dca97625cb1190

See more details on using hashes here.

File details

Details for the file python_exiv2-0.3.0-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for python_exiv2-0.3.0-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 485e9cd4cc8dd75eb93b317b533d8eaf3f900acb469fdbcad690e17c1e7797e8
MD5 57f8ba30080ff028acbb4c6e161bc059
BLAKE2b-256 8c0c5ba1e247aa4dcb2876d5b8c9eb8a853c43466abd9e4eb19562ae6fed1495

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_exiv2-0.3.0-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 1.7 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.24.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.3.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 8fe2e16624c85ee9c4c5e41468d32a6931fe22605f2259f1b6e8ddd72c9ca6c2
MD5 1a3297684dd50c6619441d753c59e408
BLAKE2b-256 e93ffecde51b43e9540d9dd4724f4882331d8cea378b0f6e22d53b86d6df5666

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