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.3.1.zip (8.0 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.1-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.1-cp39-cp39-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.9Windows x86-64

python_exiv2-0.3.1-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.1-cp38-cp38-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.8Windows x86-64

python_exiv2-0.3.1-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.1-cp37-cp37m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.7mWindows x86-64

python_exiv2-0.3.1-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.1-cp36-cp36m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.6mWindows x86-64

python_exiv2-0.3.1-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.1-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.3.1.zip.

File metadata

  • Download URL: python-exiv2-0.3.1.zip
  • Upload date:
  • Size: 8.0 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.1.zip
Algorithm Hash digest
SHA256 dbee259028a6de7e0680d3625d63ed7b4121501e0eb5dd6aa9d65266e2087850
MD5 63f15b394aa117eda2069b5e958ef8a6
BLAKE2b-256 9aee2c97279093ff1bc7310c23c604dd4ecb584dcb01cde7eb812a83e1d4c467

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_exiv2-0.3.1-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 75ab24ffc68fd1aa0b6d009ef5a3c8bebf517b16234d201989c89b9dc3873542
MD5 9788bc00f4609cc90f078bbe5907be66
BLAKE2b-256 d9e4974b63b6ccb86b0f2d9ae05787e9c4d80faf96d9fa8ad1e805cdbcf22de6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_exiv2-0.3.1-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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4eba4e56b6daa8e27b9769bfb0f403f7231fa6843f4bbc1d5c99cf85facee136
MD5 63d83ced4ed303d9e01770f9125f54f9
BLAKE2b-256 ed0ff7c8f8f92081045c70bd47c731d846c7f3c81703dfd0d2e5ccfcc28e7da8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_exiv2-0.3.1-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 501f4955bb1bef737e1ae4be1a2d1feb997ac63894973a1f246fda768fb4d0c0
MD5 bca5ef9e296483c454cc2c2c42ee349f
BLAKE2b-256 c3da9e5d24aa3510ee436e9e5ce74819b232fe8e11ad641c992042cf0bc0b0da

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_exiv2-0.3.1-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.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 679a058718c6269ce179dd120b6e88e06d694e28687e9e7a7ebc743c98d2ec89
MD5 3407bf709e24314e828e6a621bef858a
BLAKE2b-256 d0a0652adab1b41c2109586f4394a766a2836c78d3bd4b9efb18889a2a22ed8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_exiv2-0.3.1-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 3164da92d4ff73a10b31dfad956608ad22f8c46407729616c4cb5155887b35d6
MD5 bfa2416f4eaa1bd54ed5dd712f620ee9
BLAKE2b-256 b387a76f8abf698be912f40712d0b8c19657a99b5a69f0a9a9006440bc58d591

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_exiv2-0.3.1-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.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 078e19be8c0658090ed6fe03ef69e7ac81a841969651ed1f8d46ad666cd0918f
MD5 0f5340cf450402ad5192603c08464dc7
BLAKE2b-256 c5410b8c3c76a05aee523673ce9ff7c087a3cbcdc8895c9b3c434f034dc4e316

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_exiv2-0.3.1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 3924fa44c3fb2d504f124069c652a82bc68860c220ea7d623c1d04021c901846
MD5 f12f0f3175deae4ea3682532f07fdeed
BLAKE2b-256 868696e8905227c71b1b578eff1434915f36903dc80803223bcaa4acc463cd50

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_exiv2-0.3.1-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.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 099d186250414543d7f3b163b53a65107226bb79ddf6df9ec9fea61810d1ab70
MD5 8fa6d42ba6d1a55d9d2c3c34b34f1bd5
BLAKE2b-256 40c38ccf6ecbe75e645ded1f5dfd126b32aec86c489d032e8a1552d8089f47f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_exiv2-0.3.1-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 3727c65f030e977ea822f83e1113aaddd0d80e4aca01a7072950d2f25c4f1e4f
MD5 6255fe0b95d39e6da1ac446df0ddb01d
BLAKE2b-256 3a0ca87528c95d2334d4b47cf03e8baa757de06c69eabcae49b90e234c58c755

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_exiv2-0.3.1-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.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.1-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 00e27ce89f1eda20ea82da31c696ae2902472575960fd661d08bb49a2f60ab09
MD5 bfa236d9ae8b01b4f2ab49db86f589bc
BLAKE2b-256 a82cb95609427b186851b7286bbb836a4ec15b8803bccca5f4c27d1f8e187b51

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