PyObjC Social Framework
PyObjC is a bridge between Python and Objective-C, enabling Python developers to write full-featured Cocoa applications and interact with macOS system frameworks. The `pyobjc-framework-social` package provides Python wrappers for Apple's Social.framework, allowing programmatic access to social media services integrated into macOS, such as sharing content. The library is currently at version 12.1 and typically releases updates in alignment with major macOS SDK changes and Python version support.
Warnings
- breaking PyObjC has periodically dropped support for older Python versions. Version 12.0 dropped support for Python 3.9, and version 11.0 dropped support for Python 3.8. Ensure your Python environment meets the `requires_python` specification (>=3.10 for v12.1).
- breaking Version 11.1 introduced a change in how PyObjC models Automatic Reference Counting (ARC) for Objective-C initializer methods (`init` family). It now correctly reflects that these methods steal a reference to `self` and return a new one, which changed previous behavior where `alloc()` proxies were marked as 'partially initialized'. This may affect custom Objective-C subclasses or complex memory management patterns.
- gotcha When subclassing Objective-C classes in Python and providing a custom `__new__` method, using `__init__` had a regression in v10.3. While v10.3.1 restored this functionality for user-defined `__new__` implementations, classes relying on PyObjC's default `__new__` still cannot use `__init__` for initialization.
- breaking Framework bindings can be removed if the underlying macOS framework is deprecated and removed by Apple. For instance, PyObjC 10.0 removed bindings for the `IMServicePlugIn` framework, as it was deprecated in macOS 10.13 and fully removed in macOS 14.
- gotcha PyObjC version 12.1 automatically disables Key-Value Observing (KVO) usage for subclasses of `NSProxy` that are defined in Python. This change was implemented to prevent potential `SystemError` issues.
- gotcha Building PyObjC, including individual framework wrappers like `pyobjc-framework-social`, from source (e.g., with `--no-binary :all:` or from a Git checkout) requires Apple's Xcode or Command Line Tools to be installed. A compatible macOS SDK (ideally the latest or newer than your current OS version) is necessary; using an older SDK may lead to build errors.
Install
-
pip install pyobjc-framework-social
Imports
- SLComposeViewController
from Social import SLComposeViewController
- SLServiceTypeTwitter
from Social import SLServiceTypeTwitter
- objc
import objc
Quickstart
import objc
from Social import SLComposeViewController, SLServiceTypeTwitter, SLServiceTypeFacebook
def check_social_services():
"""
Checks if Twitter and Facebook social services are available on macOS.
Note: This example demonstrates basic availability checks without
requiring a full NSApplication event loop for UI presentation.
"""
# Explicitly load the Social framework if not already done by imports.
# This is often implicit but good for clarity in specific cases.
objc.loadBundle("Social", globals(), bundle_path=objc.pathForFramework("/System/Library/Frameworks/Social.framework"))
twitter_available = SLComposeViewController.isAvailableForServiceType_(SLServiceTypeTwitter)
facebook_available = SLComposeViewController.isAvailableForServiceType_(SLServiceTypeFacebook)
print(f"Twitter service available: {twitter_available}")
print(f"Facebook service available: {facebook_available}")
if __name__ == "__main__":
check_social_services()