Python interface to libexiv2
Project description
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.
This project has taken over the PyPI exiv2 package created by Michael Vanslembrouck. If you need to use Michael’s project, it is available at https://bitbucket.org/zmic/exiv2-python/src/master/ and can be installed with pip:
pip install exiv2==0.3.1
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'
>>>
Please see USAGE.rst for more help with using the Python interface to libexiv2.
Deprecation warnings
As python-exiv2 is being developed better ways are being found to do some things. Some parts of the interface are deprecated and will eventually be removed. Please use Python’s -Wd flag when testing your software to ensure it isn’t using deprecated features. (Do let me know if I’ve deprecated a feature you need and can’t replace with an alternative.)
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.readMetadata Help on method_descriptor in exiv2.Image: exiv2.Image.readMetadata = readMetadata(...) Read all metadata supported by a specific image format from the image. Before this method is called, the image metadata will be cleared. This method returns success even if no metadata is found in the image. Callers must therefore check the size of individual metadata types before accessing the data. :raises: Error if opening or reading of the file fails or the image data is not valid (does not look like data of the specific image type).
Unfortunately some documentation gets lost in the manipulations needed to make a useful interface. The C++ documentation is still needed in these cases.
Support for bmff files (e.g. CR3, HEIF, HEIC, AVIF, JPEG XL)
Python-exiv2 from version 0.8.3 onwards is built with support for BMFF files. In order to use BMFF files in your Python program you need to call the enableBMFF function. Please read the Exiv2 statement on BMFF patents before doing so.
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 need to set the type you can 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. Alternatively you can use any Python object and let libexiv2 convert the string representation of that object to the appropriate type:
# Python
exifData["Exif.Image.SamplesPerPixel"] = 162
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 “binary wheels” are available for Windows, Linux, and MacOS. 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 exiv2
or on Linux or MacOS:
$ pip3 install --user exiv2
If the available wheels are not compatible with your operating system or Python version 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!).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for exiv2-0.14.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30f400ff2ca6d55de640bf27f68af50abc9cdcd03da89f07527e4c63751f498d |
|
MD5 | 09841c4741e8fc0b464509e9925a298a |
|
BLAKE2b-256 | 21e4db5b4f2706e61afb04c6fd43ae03cef88cf4953145ac483f61603b39e3b4 |
Hashes for exiv2-0.14.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a0ecc75dde923bdff82494ca587f3587ba66714a369cb2ab955d39e1c25081f |
|
MD5 | 9146f89367be5fac04a9ee362c21baaf |
|
BLAKE2b-256 | 6c7e9f188377d48187f37b64758c5442cb64c61e566d67a6cf307462997ef66e |
Hashes for exiv2-0.14.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b70f3f48094e72b6e80655f4928db70051aead305e6ed65c7b3400479554319 |
|
MD5 | 719cb69f973cc57e9060ce8e94a3ad3c |
|
BLAKE2b-256 | a509c9e98cab50bdc49ed2950cf4c035af606d4b8871f3fdfa3733a364bf2427 |
Hashes for exiv2-0.14.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7824663f10dcb9ca2c647080db35d897d6491b1b50d6514f1f8a0c56bfd4d405 |
|
MD5 | 50330e32f7d6d63051efe509dcb62a54 |
|
BLAKE2b-256 | f5d3285fa475bc731982c0e241bd349f33cbc1b52a326731dfb8196705961534 |
Hashes for exiv2-0.14.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b18110660f99554900be87e1fddf4b6c9864305808fd3953215314cf91e0ae55 |
|
MD5 | d19e509606748917634087a7a82ac398 |
|
BLAKE2b-256 | bcb58a7fb844b961b30b4be8f12f759da3d48f113ece0bff9ae4b8d1361c211a |
Hashes for exiv2-0.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ec3618030a30410742b5679b61f77b6556d7ac3afeb79349bd7e263b2eec8e4 |
|
MD5 | 975f5e7ed96b3fddddbfc8a3c9267602 |
|
BLAKE2b-256 | 468d05e462658e82ed3fe3e3c19c324804a29a07ea626456b3fb11c7c1d5a28e |
Hashes for exiv2-0.14.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 357614ab5cff48fd335b01f840a55e7f021af902bcfefb66443778c9b5095871 |
|
MD5 | fe919a8f64f1f55726c65fd905ea40ca |
|
BLAKE2b-256 | 810cb802a25873c28ef6f0407b3b5423368e24b2f4f330dcfa4915df2a76562c |
Hashes for exiv2-0.14.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fa71eff2c51421125a1ed1b5b07d2eca7615957102e0cfb09fa09bc1cc442b2 |
|
MD5 | 49ef96fcf488da1be397579f49c65260 |
|
BLAKE2b-256 | eafe1618734ff15a7487ceeaa44a4431e5002091c78336ae09cdbfe0e0c96616 |
Hashes for exiv2-0.14.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 281ac42acec398397f036e15fa7e0eac69f61f0dbcb1bf45e5f816ac2f869ba8 |
|
MD5 | 5e6a7e281fc3d600ab7b9912cfebc715 |
|
BLAKE2b-256 | 6ca70fa4c432c9ffc63775af3908307b09e83a14cd89840489d9f6b66aec791c |
Hashes for exiv2-0.14.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12a4fecc2d0d98974f9c52acda2d2e42cb35f5f2bfb10057aa0470c8c5d4a4f2 |
|
MD5 | 3e6441c53589c218950c48769de5b6b7 |
|
BLAKE2b-256 | d46f5b5880ce771ec0fdab56b330be43303070afcd3a77bcc453f1b69ffa1f14 |
Hashes for exiv2-0.14.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 272d8ef6d64037348c8c83a86e784283891534b17313d2d131b73aaacb7d53d3 |
|
MD5 | 11ba88804ab4b8e545dea0b68787c130 |
|
BLAKE2b-256 | 7f89cdf00b11f11279fe67c9e71ee0a2d0d28e7a58f9367e17f83afebc1d7c79 |
Hashes for exiv2-0.14.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48e54eea2704838c5f53f3c085d425d44cb02ce9d96179f90dc74e7d8a69b939 |
|
MD5 | 6ed9c7cf44b1f6e964eb616c6111a68e |
|
BLAKE2b-256 | 8c6c35f5febe08cfd940ef3f4a66b1a0d408df33a966dd2b52768856d730290c |
Hashes for exiv2-0.14.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f243888728d09af616c00ad673f9d3e8b90a804a81eda2cda9339609f2929285 |
|
MD5 | 3b23993b53b007bdc1564a0884205061 |
|
BLAKE2b-256 | 2f069722468950ff4ecdcc7853e8809b4c94de4f062ddd4ed127aa05e13edd23 |
Hashes for exiv2-0.14.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a0ab942f2a9c94e9fc1f28368908de9fc199d0e49e5c7cb625c736637780907 |
|
MD5 | 506affc08358420551b22d4da60ceccd |
|
BLAKE2b-256 | 7bbd6e1ff69dffa241f8a16e3cfcaa351b5e579e891c849bf3041f818ee945bb |
Hashes for exiv2-0.14.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b93075701a80ae36742211ab3082e6bab349352f1a8764d4f2b1d3f57414d5f |
|
MD5 | 962f8ab7037611f9af3a6ddb589b14ac |
|
BLAKE2b-256 | 5d86c8911733ccbc3d69a737f4fbe91becc11c2a28a5d7fa9e503ae858437582 |
Hashes for exiv2-0.14.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84bce60112fc8337ce140830e4eb03ebc9d8cdaad24e3dba965510749ce9bf7f |
|
MD5 | 8f0881ec22084fb16470a61b7caa6f10 |
|
BLAKE2b-256 | 6095c2f73286807be86f58eeb561061ea8438897d70c4ede5f0ee0b775c6ec1d |
Hashes for exiv2-0.14.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ae907a8a207a9171865eb798abf317fd8106000e67668087e5282ea76b9a457 |
|
MD5 | eee4046e4167af108983c536f7eb56b4 |
|
BLAKE2b-256 | f8d96fdc3bf61e3bf13d5ea822ea9c9786c0bf304cc1f5b6b436f0271273c528 |
Hashes for exiv2-0.14.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d273b461230daf714ddddbdd2164ba29f46bd2c5a284963a584dbac8b351013 |
|
MD5 | 9099890a5bcce4c0aa689ec680656a72 |
|
BLAKE2b-256 | c5af9d248a3e2d0191d7e28a844a2fc739b40af911414a7beda4544f8255fd6d |
Hashes for exiv2-0.14.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc062d35328948ebaaa7bce102a0cf66c31622f9115b9321a3951c385ddf851b |
|
MD5 | c4b4176ad50bc748212b9a8bf56ea76b |
|
BLAKE2b-256 | db721cf5ed462ee1d1f8b4cd4fc16a409bf38bb5dff2a93b42c12829adc43a79 |
Hashes for exiv2-0.14.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42f6f5ed37b2dad1085f438e4d97e055f1e2204ab37943285b9e067e0659d22f |
|
MD5 | 88f84b730b28c655418311f29f629a23 |
|
BLAKE2b-256 | 175ddcde9385be86e5b7d01213ff777c86bbc26961259279ee5d15f91ee11bd4 |
Hashes for exiv2-0.14.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01fe29a492019fa2df1bb36881a3b951d2e337a53a40cf0a116baa5235d4bd08 |
|
MD5 | 000219dc0b82e08300392aef86e0da51 |
|
BLAKE2b-256 | 7663ec32a38ce6c52175906d3e52e2f38ba5f3676e1bf83333605c9bdc5adf5e |
Hashes for exiv2-0.14.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 375c27e0ab66b503b3b17ec66b7a4f3a225f4eff7689d521c0cea3a06277073d |
|
MD5 | 40e995b157f4771fe9311c64817e01e4 |
|
BLAKE2b-256 | 3d02166d3cfc31a73dc6f079f00323b454c823dc35a81de89f1c38f5e1c36b19 |