PyObjC Framework ColorSync
pyobjc-framework-colorsync provides Python wrappers for Apple's ColorSync framework on macOS. It allows Python applications to interact with macOS's color management system, including accessing color profiles and performing color conversions. As part of the larger PyObjC project, it closely follows macOS SDK updates and typically releases alongside new macOS versions and major Python releases, maintaining compatibility with the latest macOS features.
Warnings
- breaking PyObjC frequently drops support for older Python versions. Version 12.0 dropped Python 3.9, and version 11.0 dropped Python 3.8. Always check the `requires_python` metadata for compatibility.
- breaking The behavior of Objective-C initializer methods (methods in the 'init' family) was changed in PyObjC v11.1 to align with `clang`'s automatic reference counting (ARC) documentation. These methods now correctly 'steal' a reference to `self` and return a new one.
- gotcha When implementing `__new__` in Python subclasses of Objective-C classes, the ability to call `__init__` on the created object was temporarily broken in v10.3 and partially restored in v10.3.1. However, code relying on the PyObjC-provided `__new__` still cannot use `__init__` for custom initialization.
- breaking Specific macOS frameworks or APIs may be deprecated or entirely removed in newer macOS versions. PyObjC bindings will also cease to be available or function for these removed frameworks. For example, 'IMServicePlugIn' bindings were removed in PyObjC 10.0 due to the framework's removal in macOS 14.
- gotcha PyObjC 11 introduced experimental support for PEP 703 (free-threading) in Python 3.13, which required significant internal changes. While the library aims for compatibility, complex multi-threaded Objective-C interactions might behave unexpectedly.
Install
-
pip install pyobjc-framework-colorsync
Imports
- ColorSync
import ColorSync
Quickstart
import ColorSync
import objc # Recommended for general PyObjC interaction as it sets up the bridge
# ColorSync interactions often involve C functions or Core Foundation types.
# Get the default profile ID for the primary display.
# The domain argument expects a byte string (e.g., b"display", b"output").
# The function returns a CFStringRef, which PyObjC automatically bridges to a Python string.
try:
display_profile_id = ColorSync.ColorSyncGetDefaultProfileID(b"display")
print(f"Successfully retrieved default display profile ID: {display_profile_id}")
except AttributeError:
print("Error: ColorSyncGetDefaultProfileID not found. Ensure the ColorSync framework is available and PyObjC is correctly installed on macOS.")
except Exception as e:
print(f"An unexpected error occurred while accessing ColorSync: {e}")
# This quickstart demonstrates importing the framework and calling a basic C-level function,
# which is a common pattern for interacting with some parts of PyObjC-wrapped frameworks.