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. Not everything in libexiv2 is available in the Python interface. If you need something that’s not there, please let me know.

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. Here is an example of its 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()
>>> 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:

// C or C++
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:

# Python
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:

# Python
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 access to all the Exifdatum object’s methods. For example:

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.key()
'Exif.Image.ProcessingSoftware'
>>>

The Python objects 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.key()
...     next(b)
...
'Exif.Image.ProcessingSoftware'
<Swig Object of type 'ExifDataIterator *' at 0x7f2cbf6c2fb8>
'Exif.Image.ImageDescription'
<Swig Object of type 'ExifDataIterator *' at 0x7f2cbf6c2fb8>
[skip 227 line pairs]
'Exif.Thumbnail.JPEGInterchangeFormat'
<Swig Object of type 'ExifDataIterator *' at 0x7f2cbf6c2fb8>
'Exif.Thumbnail.JPEGInterchangeFormatLength'
<Swig Object of type 'ExifDataIterator *' at 0x7f2cbf6c2fb8>
>>>

The <Swig Object of type 'ExifDataIterator *' at 0x7f2cbf6c2fb8> lines are the Python interpreter showing the return value of next(b). You can also iterate in a more Pythonic style:

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

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. The exiv2.LogMsg.setLevel function can be used to control what severity of messages are logged.

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?

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.5.1.zip (4.1 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.5.1-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (6.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.12+ x86-64

python_exiv2-0.5.1-cp310-cp310-macosx_10_9_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

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

Uploaded CPython 3.9Windows x86-64

python_exiv2-0.5.1-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (6.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.12+ x86-64

python_exiv2-0.5.1-cp39-cp39-macosx_10_9_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

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

Uploaded CPython 3.8Windows x86-64

python_exiv2-0.5.1-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (6.2 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64

python_exiv2-0.5.1-cp38-cp38-macosx_10_9_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

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

Uploaded CPython 3.7mWindows x86-64

python_exiv2-0.5.1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64

python_exiv2-0.5.1-cp37-cp37m-macosx_10_9_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

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

Uploaded CPython 3.6mWindows x86-64

python_exiv2-0.5.1-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.12+ x86-64

python_exiv2-0.5.1-cp36-cp36m-macosx_10_9_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.6mmacOS 10.9+ x86-64

python_exiv2-0.5.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.5.1.zip.

File metadata

  • Download URL: python-exiv2-0.5.1.zip
  • Upload date:
  • Size: 4.1 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.5.1.zip
Algorithm Hash digest
SHA256 b2bf0984140d8d100822594a467f9f1333eadaf15166da84735e85280ebf889d
MD5 391f813911601ac8a684b1aa485be7ff
BLAKE2b-256 c478e58b940c4a60f8fddf36b2ce30928f3bc8b388842c8d3064edc57451d26b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_exiv2-0.5.1-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 8918d8f8b8a115a391781188a0758155c13fef7f8deaa30c2ef5527848b6956a
MD5 cd5d8297421d807f26df0c35c9adf71c
BLAKE2b-256 382b69b2027e94f4709010bf61794faa3c4524e326169211e54a4c574a3670fc

See more details on using hashes here.

File details

Details for the file python_exiv2-0.5.1-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: python_exiv2-0.5.1-cp310-cp310-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.10, macOS 10.9+ 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.5.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7549e82ef604fbbffc735fd3a778284b47acbd37675f21c1c1f12dbd88ef0fce
MD5 af16ffcb38eca33c83cf14a563b753ae
BLAKE2b-256 c5df895b63490528671f3beb582d084a7c2e735c3590e400d4e10ca4d5af2180

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_exiv2-0.5.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.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.5.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3cfb29a88558d34a96b89cde47d951939169268083c2ef3651b479b9259d3db5
MD5 62c0b579efb8242363c63af80e2e4a04
BLAKE2b-256 dae18f5ebeb2ced915b49f773dbcab3d315017cab2dfcf7374a7830ac4246aed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_exiv2-0.5.1-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 fa3871cbd0e74bc9c2aead03f42d1f508d477cdedaf71a23eafc71e5e090efb3
MD5 c58a9399f4e19bb8924886578b082c87
BLAKE2b-256 b5cd96c2f6ae4b3d9732cb3aaf5321e97b58c152e0ae5ee3c9e1d6224f7765fe

See more details on using hashes here.

File details

Details for the file python_exiv2-0.5.1-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: python_exiv2-0.5.1-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.9, macOS 10.9+ 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.5.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1f3bdbdd96a8764a76de80a6ffc3fe4e26b41815f8d673bc4c494ac4be367fa7
MD5 0ed953e02b45e0e29051ab34d8b48b12
BLAKE2b-256 942c90d4e7d7c26f74910fac2d4af596233ab1f672480cb744fe66fb9f58010c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_exiv2-0.5.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.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.5.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 422072b65e5e49989862ed7858ade60c409de3dc163709cbf260931540c56f56
MD5 b3f7a84e83e299a5ce90862ff1dd3ce6
BLAKE2b-256 8561933adcdefca7025fccbe45a45f4bd4127ef1510d75914cd5a2fb2a59ae74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_exiv2-0.5.1-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 dab5564316be0ee359aef65a08d77ce8559a971e96d87a65a1a43fe20c0c0d63
MD5 1274c75bc5eacab6cb46ef7e329ab072
BLAKE2b-256 a1582057066a34da80df8982f2d2e77778328f604fa20202ed3fcf3d4bec69ae

See more details on using hashes here.

File details

Details for the file python_exiv2-0.5.1-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: python_exiv2-0.5.1-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.8, macOS 10.9+ 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.5.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9026e7eb94bea04d8165110b30a4673f885eda31f693f90b212ec59722fd90bd
MD5 ed445edfce57c1d9b5b3a5530aea5b47
BLAKE2b-256 faa27929c13a22435240a312d40f43b81c5865e379b87210c323034691117cf4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_exiv2-0.5.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.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.5.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 cd079c4daaf3674ac052ce979184d8bd1b6ca2e3eb1d21f47e3f2b20342079a1
MD5 ae0029639e81493e831602ce2c99ad81
BLAKE2b-256 ab76df4212abe99fc735632a49d49638e826e436ae74e89cc8a0ebc8319891bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_exiv2-0.5.1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 32c15dc00ccc8f163a7535c777afc9ea7d36aa66bc6bbf6501ac3cbd35e15cb0
MD5 117008960f95dac506f006c11a2d498d
BLAKE2b-256 462f74e197e5c7f5774136c7429c4605620361f011209a61cd7b3dbb0926b1b9

See more details on using hashes here.

File details

Details for the file python_exiv2-0.5.1-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: python_exiv2-0.5.1-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.7m, macOS 10.9+ 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.5.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 696153a0dea51de4fb525b61a5b9d848f151e608c02c80a62f4a1c53837d8bcc
MD5 09c14af4c53d31d2e65be890bd00942e
BLAKE2b-256 8ab05684dfd91e1e8c90d6819a0267251f11b968b31a75f797aef1dbf00570f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_exiv2-0.5.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.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.5.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 2ddd78c25913a9b4f5e3f522842bc15b917a825bdac885f5ba4aed5c613aec16
MD5 7abf3f9308186255dda559d6928832ef
BLAKE2b-256 037b0122c05de552c9782770d5b9066df60699d6657025683c734a5629d9ff72

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_exiv2-0.5.1-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 2d48134ad44ab2c53028114db5898302996bbb5477319b5e8b4206fd2cf94e67
MD5 82cd941024831afb7d17c147c6a54940
BLAKE2b-256 679cd19189699a26256859dd6e283d35357bc644b8441d2afe458a42591894b8

See more details on using hashes here.

File details

Details for the file python_exiv2-0.5.1-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: python_exiv2-0.5.1-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.6m, macOS 10.9+ 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.5.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 460cddd0fd4352aa1ff614c2f5ff49a6abb60394c1c68b09fbb515286e83a8cf
MD5 ddb8e582413700582cb17934d53a7b7d
BLAKE2b-256 6630209d235df11a57fc3d9cbcef0c29397a56086ade4e5397708a904bae6121

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_exiv2-0.5.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.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.5.1-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 5ead9073a0a4415441b7a740dc97cfd8a910e9a6685b977da4adec2f56b0e26d
MD5 ab9277f51e5cae1343a6ca650256e1c1
BLAKE2b-256 2201442f0d2d64765a00900cb3913a25c42bf1e2207834d887ff823c4e2c84dc

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 Sentry Error logging StatusPage Status page