PyObjC SharedWithYou Framework
pyobjc-framework-sharedwithyou provides Python wrappers for Apple's SharedWithYou framework on macOS. It is part of the PyObjC project, a bidirectional bridge enabling Python scripts to interact with Objective-C libraries, including macOS Cocoa frameworks. 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 11.1 changed how initializer methods (`init` family) are modeled, now correctly reflecting that they 'steal' a reference to `self` and return a new one, as per clang's ARC documentation. This affects object lifecycle and reference counting.
- breaking In PyObjC 10.3, the ability to call `__init__` when a class or its superclasses contain a user implementation of `__new__` was temporarily dropped, then reintroduced in 10.3.1 due to breaking popular projects. Code relying on PyObjC's provided `__new__` still cannot use `__init__` in this scenario.
- breaking The `IMServicePlugIn` framework bindings were removed in PyObjC 10.0 because the framework was deprecated in macOS 10.13 and removed entirely in macOS 14.
- gotcha PyObjC 11.0 introduced experimental support for free-threading (PEP 703) in Python 3.13. While a significant advancement, it's an experimental feature and may have stability considerations.
- gotcha As of PyObjC 12.0, classes `NSString` and `NSMutableString` are marked as 'final', meaning they can no longer be subclassed from Python. Attempting to subclass them will result in crashes due to special handling within PyObjC.
Install
-
pip install pyobjc-framework-sharedwithyou
Imports
- SharedWithYou
import SharedWithYou
Quickstart
import Foundation
import SharedWithYou # Assuming SharedWithYou classes are directly exposed
# This example demonstrates basic PyObjC interaction by creating a Foundation object.
# Interactions with SharedWithYou classes would follow a similar pattern.
# Create an instance of a Foundation object
hello_string = Foundation.NSString.stringWith_('Hello from PyObjC SharedWithYou!')
print(f"Created Objective-C string: {hello_string}")
# You would typically interact with SharedWithYou classes here.
# For example, if there was a 'SWYCollaboration' class:
# try:
# collaboration = SharedWithYou.SWYCollaboration.alloc().init()
# print(f"Created SharedWithYou Collaboration object: {collaboration}")
# except AttributeError:
# print("SWYCollaboration class not found or initialized in this simple example.")
print("PyObjC bridge is active and ready to interact with macOS frameworks.")