Skip to main content

Python package for accessing the macOS Photos.app library via Apple's native PhotoKit framework.

Project description

Python PhotoKit

Python PhotoKit is a Python interface to the Apple PhotoKit framework for working with the Photos app on macOS.

This is currently a work in progress, and is not yet ready for use. I'm working on extracting the code from osxphotos and adding additional functionality.

It is based on work done for osxphotos which provides a command line interface to the Photos app on macOS as well as a python API for working with Photos.

Synopsis

>>> from photokit import PhotoLibrary
>>> PhotoLibrary.authorization_status()
(True, True)
>>> pl = PhotoLibrary()
>>> pl.add_photo("/Users/user/Desktop/IMG_0632.JPG")
'8D35D987-9ECC-490C-811A-1AA33C8A7983/L0/001'
>>> photo = pl.fetch_uuid("CA2E3ADB-53A4-4E85-8D7D-4A664F970810")
>>> photo.original_filename
'IMG_4703.HEIC'
>>> photo.export("/private/tmp")
['/private/tmp/IMG_4703.heic']
>>>
>>> from photokit import PhotoLibrary
>>> new_library = PhotoLibrary.create_library("test.photoslibrary")
>>> new_library.add_photo("/private/tmp/IMG_4703.HEIC")
'07922E5C-5F4D-46C4-8DF9-D609FCF6714D/L0/001'
>>> library2 = PhotoLibrary("/Users/user/Pictures/Test2.photoslibrary")

Installation

Still a work in progress and not yet ready for normal use. If you'd like to experiment with it, you can install it from GitHub:

git clone git@github.com:RhetTbull/photokit.git
cd photokit
python3 -m pip install flit
flit install

or via pip:

    pip3 install photokit

Documentation

Documentation is available at https://rhettbull.github.io/photokit/.

Supported Platforms

Python PhotoKit is being developed on macOS Ventura (13.5.x). Initial testing has been done on macOS Monterey (12.x) and macOS Sonoma (14.0 Developer Preview) and it appears to work though no guarantees are made. It will not work on macOS Catalina (10.15.x) or earlier as those versions of macOS do not support some of the API calls used by this library.

Implementation Notes

PhotoKit is a macOS framework for working with the Photos app. It is written in Objective-C and is not directly accessible from Python. This project uses pyobjc to provide a Python interface to the PhotoKit framework. It abstracts away the Objective-C implementation details and provides a Pythonic interface to the PhotoKit framework with Python classes to provide access to the user's Photo's library and assets in the library.

In addition the public PhotoKit API, this project uses private, undocumented APIs to allow access to arbitrary Photos libraries, creating new Photos libraries, accessing keywords, etc. The public PhotoKit API only allows access to the user's default Photos library (the so called "System Library") and limits the metadata available.

A number of methods allow retrieval of assets of via a local identifier or universally unique identifier. Photos uses a local identifier to identify assets, albums, etc. within a single Photos library. The local identifier is specific to a given instance of the Photos library. The same asset in a different instance of the Photos library will have a different local identifier. This library uses the term "UUID" interchangeably with local identifier. A UUID is a string of hexadecimal digits that takes the form: 61A4B877-5EAC-4710-AA77-6D387629D9A5. A local identifier returned by the native PhotoKit interface includes additional digits in the form 61A4B877-5EAC-4710-AA77-6D387629D9A5/L0/001. For any method in this library that accepts a UUID, you may pass either the full local identifier or just the UUID portion. The library will automatically strip off the additional digits.

See Also

  • osxphotos: Python app to export pictures and associated metadata from Apple Photos on macOS. Also includes a package to provide programmatic access to the Photos library, pictures, and metadata.
  • PhotoScript: Automate macOS Apple Photos app with python. Wraps AppleScript calls in Python to allow automation of Photos from Python code.

License

This project is licensed under the terms of the MIT license.

To Do

PhotoLibrary

Static Methods

  • enable_multi_library_mode()
  • multi_library_mode()
  • system_library_path()
  • authorization_status()
  • request_authorization() (partially implemented)
  • create_library()
  • default_library_path()

Methods

  • assets()
  • asset()
  • albums()
  • smart_albums() (or method for each smart album, e.g. "recents()", "hidden()", etc.)?
  • moments()
  • folders()
  • fetch_uuid_list() (rename to fetch_assets or use assets(uuid_list))
  • fetch_uuid() (rename to fetch_asset() or asset())
  • fetch_burst_uuid()
  • delete_assets()
  • add_photo()
  • add_video()
  • add_raw_pair()
  • add_live_photo()
  • create_album()
  • create_folder()
  • fetch_or_create_album() (renamed to album())
  • count(), len
  • is_default() # is default library
  • is_system() # is system library

PhotoAsset

  • keywords getter/setter
  • isphoto
  • ismovie
  • isaudio
  • original_filename
  • uuid
  • raw_filename
  • hasadjustments
  • media_type
  • media_subtypes
  • favorite (getter/setter)
  • panorama
  • hdr
  • screenshot
  • live
  • streamed
  • slow_mo
  • time_lapse
  • portrait
  • burst
  • source_type
  • pixel_width
  • pixel_height
  • date (created; setter/getter)
  • date_modified (setter/getter)
  • date_added (setter/getter)
  • timezone_offset (setter/getter)
  • timezone (setter/getter)
  • location (setter/getter)
  • duration
  • orientation
  • title (getter/setter)
  • description (getter/setter)
  • burst_photos
  • burst_uuid
  • export (implemented, not yet tested)

VideoAsset

LivePhotoAsset

Album

  • album properties
  • add_assets()
  • remove_assets()

Folder

PhotoDB

  • get_asset_uuids()
  • get_album_uuids

Tests

  • initial test suite

Documentation

  • initial documentation
  • publish to GitHub pages

Type Hints/Linting

  • mypy
  • ruff

Chores

  • add doit for build automation

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

photokit-0.2.1.tar.gz (49.7 MB view details)

Uploaded Source

Built Distribution

photokit-0.2.1-py3-none-any.whl (47.0 kB view details)

Uploaded Python 3

File details

Details for the file photokit-0.2.1.tar.gz.

File metadata

  • Download URL: photokit-0.2.1.tar.gz
  • Upload date:
  • Size: 49.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for photokit-0.2.1.tar.gz
Algorithm Hash digest
SHA256 bd0f054f7e5c9dc7351aa146cdcf557ca1c0b5bbceea90e9588c9fa15989444b
MD5 aea40e7978e94f7394bd3404fd0bedba
BLAKE2b-256 251c99cc484c1ccbc371249033239adf72271cc2f9033b10ea44962a013ab523

See more details on using hashes here.

File details

Details for the file photokit-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: photokit-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 47.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for photokit-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c8779e2cb5ceca0ac4794f9418b22682c6818483c1e329461ebbbe78643a2a6e
MD5 cdb749ad9653511bea4cc843e656ad53
BLAKE2b-256 84c96c72b6ece41df77eefc02aa162f037e2267e0154431f83e8b207dedcc199

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page