PyObjC Framework SafetyKit
PyObjC Framework SafetyKit provides Python wrappers for the macOS SafetyKit framework, allowing Python applications to interact with Apple's APIs related to parental controls and screen time. It is part of the larger PyObjC project, which bridges Python and Objective-C. The current version is 12.1, and releases typically align with macOS SDK updates and PyObjC core library releases.
Warnings
- breaking PyObjC has dropped support for older Python versions in recent major releases. 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 `pyobjc-framework-safetykit` requirements (currently >=3.10).
- breaking The core PyObjC bridge changed its modeling of Automatic Reference Counting (ARC) for initializer methods in v11.1. Methods in the 'init' family now correctly steal a reference to self and return a new one, aligning with clang's documentation. Code relying on previous, potentially incorrect, reference counting behavior for initializers may break.
- breaking Behavior around `__init__` and `__new__` when subclassing Objective-C classes in Python was altered in PyObjC 10.3 and partially reverted in 10.3.1. While `__init__` usage was reintroduced for user-defined `__new__`, code relying on PyObjC's default `__new__` cannot use `__init__`. This can affect Python subclasses of Objective-C types.
- gotcha PyObjC framework wrappers, including `pyobjc-framework-safetykit`, do not include their own detailed documentation for the Objective-C APIs. Users must consult Apple's official developer documentation for the 'SafetyKit' framework to understand class structures, methods, and usage patterns.
Install
-
pip install pyobjc-framework-safetykit
Imports
- SafetyKit
import SafetyKit
Quickstart
import SafetyKit
import objc
# SafetyKit provides APIs for parental controls and screen time.
# Actual usage typically involves interacting with system services
# and requires specific macOS versions and user permissions.
# This quickstart demonstrates importing the framework and accessing a known class.
try:
# SNSafetyChecker is a primary class within the SafetyKit framework.
_ = SafetyKit.SNSafetyChecker
print("Successfully imported SafetyKit and accessed SNSafetyChecker class.")
print("Refer to Apple's official SafetyKit documentation for detailed API usage.")
# Example: To interact with a class, you would follow Apple's Objective-C API patterns.
# For instance, if SNSafetyChecker had a static method 'isSupported':
# if hasattr(SafetyKit.SNSafetyChecker, 'isSupported'):
# print(f"SNSafetyChecker.isSupported(): {SafetyKit.SNSafetyChecker.isSupported()}")
except AttributeError:
print("Could not find SNSafetyChecker in SafetyKit. "
"This might indicate an unsupported macOS version or an incorrect class name.")
except Exception as e:
print(f"An unexpected error occurred during SafetyKit access: {e}")