Skip to main content

PhotoScript

Code style: black License: MIT

All Contributors

What is PhotoScript

PhotoScript provides a python wrapper around Apple Photos applescript interface. With PhotoScript you can interact with Photos using python. Runs only on MacOS. Tested on MacOS Catalina.

PhotosScript is limited by Photos' very limited AppleScript dictionary.

Compatibility

Designed for MacOS Catalina/Photos 5. Preliminary testing on Big Sur/Photos 6 beta shows this should work on Big Sur as well. Photos' AppleScript interface has changed very little since Photos 2 (the earliest version I have access to). This package should work with most versions of Photos but some methods may not function correctly on versions earlier than Photos 5. If you find compatibility issues, open an issue or send a PR.

Installation

You can install via pip:

python3 -m pip install photoscript

To install via the source code:

  • Install uv if not already installed
  • Clone the repo: git clone git@github.com:RhetTbull/PhotoScript.git
  • Change to the directory: cd PhotoScript
  • Run uv pip install -r pyproject.toml.

If you want to develop code for PhotoScript, see README_DEV.md.

Example

""" Simple example showing use of photoscript """

import photoscript

photoslib = photoscript.PhotosLibrary()

photoslib.activate()
print(f"Running Photos version: {photoslib.version}")

album = photoslib.album("Album1")
photos = album.photos()

for photo in photos:
    photo.keywords = ["travel", "vacation"]
    print(f"{photo.title}, {photo.description}, {photo.keywords}")

new_album = photoslib.create_album("New Album")
photoslib.import_photos(["/Users/rhet/Downloads/test.jpeg"], album=new_album)

photoslib.quit()

Documentation

Full documentation here.

Additional documentation about Photos and AppleScript available on the wiki.

Testing

Tested on MacOS Catalina, Photos 5 with 100% coverage.

Limitations

Photos' AppleScript interface is very limited. For example, it cannot access information on faces in photos nor can it delete a photo. PhotoScript is thus limited. PhotoScript works by executing AppleScript through an Objective-C bridge from python. Every method call has to do a python->Objective C->AppleScript round trip; this makes the interface much slower than native python code. This is particularly noticeable when dealing with Folders which requires significant work arounds.

Where possible, PhotoScript attempts to provide work-arounds to Photos' limitations. For example, Photos does not provide a way to remove a photo from an album. PhotoScript does provide a Album.remove() method but in order to do this, it creates a new album with the same name as the original, copies all but the removed photos to the new album then deletes the original album. This simulates removing photos and produces the desired effect but is not the same thing as removing a photo from an album.

  • osxphotos: Python package that provides read-only access to the Photos library including all associated metadata.
  • PhotoKit: Experimental Python package for accessing the macOS Photos.app library via Apple's native PhotoKit framework.

Dependencies

Contributors ✨

Thanks goes to these wonderful people (emoji key):

David Haberthür
David Haberthür

📖
André Anjos
André Anjos

🤔 🐛
oPromessa
oPromessa

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

See Also

For a more comprehensive python interface for Mac automation, see PyXA which provides a python interface to Photos and many other Mac applications.

Metadata

Release files for photoscript 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for photoscript 0.6.1
File Size Uploaded
photoscript-0.6.1.tar.gz 29.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for photoscript 0.6.1
File Interpreter ABI Platform
photoscript-0.6.1-py3-none-any.whl Python 3 none any Details

Total release size: 57.9 kB

Release files / photoscript-0.6.1.tar.gz

Download URL photoscript-0.6.1.tar.gz
Size 29.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1471b294d014eac3e8e1dbdff3b3e293c5ec5833d36bb3d84ebaed14c2869aaf
BLAKE2b-256 checksum
How to use checksums
0c1774f51f2f4ce0759dd86c199f9603738a6b20792e3778249a455a2b634b52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.2

Release files / photoscript-0.6.1-py3-none-any.whl

Download URL photoscript-0.6.1-py3-none-any.whl
Size 28.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f7352d77e3419c05ee71f299adbdbc3be6c642ce8edfc39eb47b4481c32fe10
BLAKE2b-256 checksum
How to use checksums
cdad66634b1bef1d0dcc7e92a4170d9ea3099f466ca1c86f2a709fbd8f3a6d02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.2

Release history Release notifications | RSS feed

This release

0.6.1 This release

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.27

2 release files

0.0.26

2 release files

0.0.25

2 release files

0.0.23

2 release files

0.0.22

2 release files

0.0.21

2 release files

0.0.20

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page