PyObjC provides Python wrappers for Apple's ContactsUI framework on macOS, enabling Python applications to integrate with the system's contact selection interface. This library is part of the larger PyObjC bridge, which facilitates full-featured Cocoa application development in Python. Currently at version 12.1, PyObjC projects are actively maintained with releases often synchronized with major macOS SDK updates.
pip install pyobjc-framework-contactsuiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to display a `CNContactPickerViewController` to allow the user to select contacts. It initializes an `NSApplication`, sets up a `CNContactPickerDelegate` to handle selection or cancellation, and then presents the picker as a sheet. The selected contact's name and phone numbers are logged. Note that running PyObjC UI code typically requires an active `NSApplication` event loop.
Ensure your Python environment meets the minimum version requirement for the PyObjC version you are installing or upgrading to. Use `pyenv` or `conda` to manage Python versions.
Always install the PyObjC version that is compatible with your macOS SDK. Use `pip install pyobjc` (or a specific framework like `pyobjc-framework-contactsui`) on the target machine to ensure the correct wheels are installed for your OS and Python version.
When calling Objective-C methods from Python via PyObjC, convert all colons in the Objective-C selector to underscores in the Python method name. Ensure the number of arguments passed matches the number of underscores/colons.
Review code that manually manages object lifetimes or relies on specific `alloc().init()` reference counting behavior, especially when subclassing Objective-C classes. In most cases, PyObjC handles this automatically, but custom memory management code might need adjustments.
If experiencing issues with `__init__` not being called after `__new__`, ensure you are on `pyobjc` 10.3.1 or later. If relying on PyObjC's default `__new__`, avoid implementing `__init__` in a way that bypasses Objective-C's two-phase initialization (alloc/init).
Periodically review Apple's developer documentation for framework deprecations and plan to update your application's dependencies and code to newer frameworks as needed when upgrading PyObjC or macOS.