PyObjC Collaboration Framework
PyObjC-framework-collaboration provides Python wrappers for Apple's Collaboration framework on macOS, enabling Python scripts to access identity and user selection features. It is part of the broader PyObjC project, a bridge between Python and Objective-C. The current version is 12.1, and it maintains an active release cadence, typically aligning with macOS SDK updates and Python version support.
Warnings
- breaking PyObjC frequently drops support for older Python versions. PyObjC 12.0 dropped support for Python 3.9, and PyObjC 11.0 dropped Python 3.8. Ensure your Python version is compatible with the PyObjC version you are installing.
- breaking PyObjC 10.3 introduced changes to `__new__` and `__init__` behavior, specifically disallowing direct use of `__init__` for classes relying on PyObjC's `__new__`. Version 10.3.1 partially reverted this to allow `__init__` when a user implements `__new__` or a superclass implements `__new__`. PyObjC 11.1 also aligned initializer methods with `clang`'s ARC documentation, affecting reference counting for `init` family methods.
- deprecated The `IMServicePlugIn` bindings were removed in PyObjC 10.0 as the entire framework was deprecated in macOS 10.13 and removed in macOS 14. Code relying on these bindings will fail.
- gotcha PyObjC is a macOS-specific library and will not install or run on other operating systems. The frameworks it wraps (like Collaboration) are Apple-proprietary.
- gotcha Unlike Objective-C, where sending a message to `nil` (equivalent to Python `None`) is a no-op, attempting to call a method on a Python `None` object (which PyObjC translates from `nil`) will raise an `AttributeError`.
- gotcha While PyObjC 11.0 introduced experimental support for free-threading (PEP 703) with Python 3.13, and later versions have improved it, note that Apple's underlying frameworks are not necessarily thread-safe. Concurrent access to Objective-C collections (like `NSMutableArray`) or `nonatomic` properties without explicit locking can lead to issues.
Install
-
pip install pyobjc-framework-collaboration
Imports
- CBIdentity
from Collaboration import CBIdentity
Quickstart
import objc
from Collaboration import CBIdentityAuthority
from AppKit import NSApplication, NSApp # Required for an active run loop in UI applications
def list_identity_authorities():
"""Lists available identity authorities on the system."""
authorities = CBIdentityAuthority.allAuthorities()
if authorities:
print("Available Collaboration Identity Authorities:")
for authority in authorities:
print(f"- {authority.displayName()} (Type: {authority.type()})")
if authority.isLocal():
print(" (Local Authority)")
print(f" Identifier: {authority.identifier()}")
else:
print("No Collaboration Identity Authorities found.")
if __name__ == "__main__":
# For non-UI interactions, a run loop is not strictly necessary but
# for many PyObjC applications, especially those involving UI,
# NSApplication.sharedApplication() or an active run loop is needed.
# Starting a minimal AppKit environment for consistency.
if not NSApp:
NSApplication.sharedApplication()
list_identity_authorities()