Skip to main content

PyExifTool fork with server/client support

Project description

PyPI Version Supported Python Versions

PyExifTool is a Python library to communicate with an instance of Phil Harvey’s ExifTool command-line application.

The library provides the class exiftool.ExifTool that runs the command-line tool in batch mode and features methods to send commands to that program, including methods to extract meta-information from one or more image files. Since exiftool is run in batch mode, only a single instance needs to be launched and can be reused for many queries. This is much more efficient than launching a separate process for every single query.

Example Usage

Simple example:

import exiftool

files = ["a.jpg", "b.png", "c.tif"]
with exiftool.ExifToolHelper() as et:
    metadata = et.get_metadata(files)
    for d in metadata:
        print("{:20.20} {:20.20}".format(d["SourceFile"],
                                         d["EXIF:DateTimeOriginal"]))

Refer to documentation for more Examples and Quick Start Guide

Getting PyExifTool

PyPI

Easiest: Install a version from mbanucu-pyexiftool on PyPI

python -m pip install -U mbanucu-pyexiftool

From Source

  1. Check out the source code from the github repository

    • git clone https://github.com/MBanucu/pyexiftool.git

    • Alternatively, you can download a tarball.

  2. Run setup.py to install the module from source

    • python setup.py install [--user|--prefix=<installation-prefix>]

PyExifTool Dependencies

Python

PyExifTool runs on Python 3.10+. PyExifTool has been tested on Windows and Linux, and probably also runs on other Unix-like platforms.

Phil Harvey’s exiftool

For PyExifTool to function, exiftool command-line tool must exist on the system. If exiftool is not on the PATH, you can specify the full pathname to it by using ExifTool(executable=<full path>).

PyExifTool requires a minimum version of 12.15 (which was the first production version of exiftool featuring the options to allow exit status checks used in conjuction with -echo3 and -echo4 parameters).

To check your exiftool version:

exiftool -ver

Windows/Mac

Windows/Mac users can download the latest version of exiftool:

https://exiftool.org

Linux

Most current Linux distributions have a package which will install exiftool. Unfortunately, some do not have the minimum required version, in which case you will have to build from source.

  • Ubuntu

    sudo apt install libimage-exiftool-perl
  • CentOS/RHEL

    yum install perl-Image-ExifTool

Documentation

The current documentation is available at sylikc.github.io or MBanucu on GitHub.

http://sylikc.github.io/pyexiftool/

Package Structure

PyExifTool was designed with flexibility and extensibility in mind. The library consists of a few classes, each with increasingly more features.

The base ExifTool class contains the core functionality exposed in the most rudimentary way, and each successive class inherits and adds functionality.

  • exiftool.ExifTool is the base class with core logic to interface with PH’s ExifTool process. It contains only the core features with no extra fluff. The main methods provided are execute() and execute_json() which allows direct interaction with the underlying exiftool process.

    • The API is considered stable and should not change much with future releases.

  • exiftool.ExifToolHelper exposes some of the most commonly used functionality. It overloads some inherited functions to turn common errors into warnings and adds logic to make exiftool.ExifTool easier to use. For example, ExifToolHelper provides wrapper functions to get metadata, and auto-starts the exiftool instance if it’s not running (instead of raising an Exception). ExifToolHelper demonstrates how to extend ExifTool to your liking if your project demands customizations not directly provided by ExifTool.

    • More methods may be added and/or slight API tweaks may occur with future releases.

  • exiftool.ExifToolAlpha further extends the ExifToolHelper and includes some community-contributed not-very-well-tested methods. These methods were formerly added ad-hoc by various community contributors, but no longer stand up to the rigor of the current design. ExifToolAlpha is not up to the rigorous testing standard of both ExifTool or ExifToolHelper. There may be old, buggy, or defunct code.

    • This is the least polished of the classes and functionality/API may be changed/added/removed on any release.

    • NOTE: The methods exposed may be changed/removed at any time.

    • If you are using any of these methods in your project, please Submit an Issue to start a discussion on making those functions more robust, and making their way into ExifToolHelper. (Think of ExifToolAlpha as ideas on how to extend ExifTool, where new functionality which may one day make it into the ExifToolHelper class.)

Server / Client Mode

PyExifTool provides a TCP server mode that allows multiple processes or threads to share a single exiftool subprocess. This avoids the overhead of starting a new subprocess per client and is essential when multiple processes must not concurrently write to the same filesystem.

The server listens on a TCP socket and accepts JSON-RPC-like requests. The client provides the same API as exiftool.ExifToolHelper, making it a drop-in replacement.

  • exiftool.ExifToolServer wraps an ExifToolHelper instance and exposes it over TCP. It auto-shuts down after an idle timeout.

  • exiftool.ExifToolClient connects to a running server and proxies all calls to it.

Example:

import exiftool

# Start a server
server = exiftool.ExifToolServer()
port = server.start()

# Connect a client from another process (or the same one)
with exiftool.ExifToolClient(port=port) as client:
    metadata = client.get_metadata("file.jpg")

# Servers auto-shutdown after 60s idle; stop explicitly:
server.stop()

Auto-discovery via a well-known port file (pyexiftool-server.json in the temp directory) is also supported:

# Process A: start server (uses default port file)
server = exiftool.ExifToolServer()
server.start()

# Process B: auto-discover
client = exiftool.ExifToolClient()
print(client.execute("-ver"))

# Or spawn a server as a background subprocess:
port = exiftool.spawn_server()
print(f"Server on port {port}")

Discovered server port from a running server:

port = exiftool.find_server()
if port:
    print(f"Found server on port {port}")

Brief History

PyExifTool was originally developed by Sven Marnach in 2012 to answer a stackoverflow question Call exiftool from a python script?. Over time, Sven refined the code, added tests, documentation, and a slew of improvements. While PyExifTool gained popularity, Sven never intended to maintain it as an active project. The original repository was last updated in 2014.

Over the years, numerous issues were filed and several PRs were opened on the stagnant repository. In early 2019, Martin Čarnogurský created a PyPI release from the 2014 code with some minor updates. Coincidentally in mid 2019, Kevin M (sylikc) forked the original repository and started merging the PR and issues which were reported on Sven’s issues/PR page.

In late 2019 and early 2020 there was a discussion started to Provide visibility for an active fork. There was a conversation to transfer ownership of the original repository, have a coordinated plan to communicate to PyExifTool users, amongst other things, but it never materialized.

Kevin M (sylikc) made the first release to the PyPI repository in early 2021. At the same time, discussions were started, revolving around Deprecating Python 2.x compatibility and refactoring the code and classes.

The latest version is the result of all of those discussions, designs, and development. Special thanks to the community contributions, especially Jan Philip Göpfert, Seth P, and Kolen Cheung.

Licence

PyExifTool is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the licence, or (at your option) any later version, or the BSD licence.

PyExifTool is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See LICENSE for more details.

Project details


Download files

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

Source Distribution

mbanucu_pyexiftool-0.6.4.tar.gz (78.4 kB view details)

Uploaded Source

Built Distribution

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

mbanucu_pyexiftool-0.6.4-py3-none-any.whl (62.7 kB view details)

Uploaded Python 3

File details

Details for the file mbanucu_pyexiftool-0.6.4.tar.gz.

File metadata

  • Download URL: mbanucu_pyexiftool-0.6.4.tar.gz
  • Upload date:
  • Size: 78.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mbanucu_pyexiftool-0.6.4.tar.gz
Algorithm Hash digest
SHA256 7c3db3caca813d7d67d65d2b3f7dcabad0283f2b1a1c73d6d330fbded8650664
MD5 2bb55ced44e61f3e817ecf35eacaf415
BLAKE2b-256 0068e34bc9e6d553f0c6534dcc74d1d4fca27a7224612a4a0315d471cd5fbf5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for mbanucu_pyexiftool-0.6.4.tar.gz:

Publisher: publish.yml on MBanucu/pyexiftool

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mbanucu_pyexiftool-0.6.4-py3-none-any.whl.

File metadata

File hashes

Hashes for mbanucu_pyexiftool-0.6.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7f2beb8d8a51cfb1556e66a3c3d38359502e2bf2151204ba6df49903c91bc4d5
MD5 7476632a44b755b9ce73461ae3a74e32
BLAKE2b-256 89039d1c78fa7a6518c13fd3da6937a2dd2a6a7e9e282c40577564f4091ae6c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mbanucu_pyexiftool-0.6.4-py3-none-any.whl:

Publisher: publish.yml on MBanucu/pyexiftool

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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