PyObjC Framework InstallerPlugins
PyObjC is a bridge between Python and Objective-C, enabling Python scripts to interact with macOS frameworks and Cocoa libraries. The `pyobjc-framework-installerplugins` package provides Python wrappers specifically for the InstallerPlugins framework, which allows developers to extend the macOS installation process with custom steps and UI. The current version is 12.1, and PyObjC generally follows a release cadence tied to macOS SDK updates and Python version support, with major versions often introducing significant changes or dropping older Python support.
Warnings
- breaking PyObjC v12.0 dropped support for Python 3.9. Projects must upgrade to Python 3.10 or newer.
- breaking In PyObjC v11.1, the behavior for Objective-C initializer methods ('init' family) was aligned with `clang`'s Automatic Reference Counting (ARC) documentation. PyObjC now correctly models that these methods steal a reference to `self` and return a new reference, which might change memory management expectations for custom initializers.
- gotcha PyObjC 10.3 did not support Python 3.13's experimental free-threading (PEP 703). While PyObjC 11.0 introduced *experimental* support, developers should be cautious and test thoroughly when using PyObjC with free-threading Python interpreters, as the bridge's internal C API usage may still have edge cases.
- gotcha There was a temporary change in PyObjC v10.3 where `__init__` could not be used when a class or its superclasses had a user-implemented `__new__`. This was largely reverted in v10.3.1 to support popular projects, but understanding the interaction between `__new__` and Objective-C's two-phase instantiation (`alloc`/`init`) is crucial.
- breaking PyObjC v10.0 removed the `IMServicePlugIn` bindings entirely, as the framework was deprecated in macOS 10.13 and removed in macOS 14. While this specific package is `InstallerPlugins`, it demonstrates a pattern where bindings for deprecated macOS frameworks are removed in major PyObjC versions without backward compatibility.
Install
-
pip install pyobjc-framework-installerplugins
Imports
- InstallerPlugins
import InstallerPlugins
- NSObject
from Foundation import NSObject
- objc
import objc
Quickstart
from Foundation import NSObject
import objc
import InstallerPlugins
class MyCustomInstallerSection(NSObject):
# The 'alloc().init()' pattern is standard for Objective-C object creation.
# Python methods often use trailing underscores for Objective-C selector arguments.
# Example: Defining a method that an Installer Plugin might call.
# In a real plugin, you would override specific methods like 'initWithSection_'.
@objc.python_method
def myPluginMethod_(self, installerSection):
print(f"My custom installer plugin method called by: {installerSection}")
# You'd typically interact with installerSection here
return True
# This simple script demonstrates importing the framework and defining a class.
# A real Installer Plugin requires specific project structure and bundling
# (e.g., using py2app) to be loaded by the macOS Installer.app.
if __name__ == '__main__':
print("InstallerPlugins framework imported successfully.")
# Instantiate the class (though it won't be 'used' without Installer.app)
plugin_instance = MyCustomInstallerSection.alloc().init()
print(f"Instance created: {plugin_instance}")
# Demonstrate calling a custom method (for illustrative purposes)
# In practice, the macOS Installer would call specific methods on your plugin.
# Replace 'None' with a mock InstallerSection object if testing interaction.
plugin_instance.myPluginMethod_(None)