PyObjC KernelManagement Framework
pyobjc-framework-kernelmanagement provides Python wrappers for the macOS KernelManagement framework. It enables Python applications to interact with kernel extensions and manage kernel-level operations on macOS. The library is part of the larger PyObjC project, currently at version 12.1, and typically releases updates aligned with macOS SDK changes and Python version support.
Warnings
- breaking PyObjC 12.0 dropped support for Python 3.9, and PyObjC 11.0 dropped support for Python 3.8. Ensure your Python version is 3.10 or newer.
- gotcha PyObjC is a binding for macOS's Objective-C frameworks and is therefore exclusively available and functional on macOS. It cannot be used on Windows or Linux.
- gotcha PyObjC 11.1 introduced changes to align the core bridge with `clang`'s Automatic Reference Counting (ARC) documentation for initializer methods. Methods in the 'init' family now correctly model stealing a reference to `self` and returning a new reference. This can affect manual memory management (though less common in modern ARC code).
- gotcha PyObjC 10.3 changed the interaction between `__init__` and `__new__` for Python classes bridged to Objective-C. While v10.3.1 partially re-enabled `__init__` when `__new__` is user-implemented, using `__init__` with PyObjC-provided `__new__` is still not supported.
Install
-
pip install pyobjc-framework-kernelmanagement
Imports
- KMUserClient
from KernelManagement import KMUserClient
- NSObject
from Foundation import NSObject
Quickstart
import objc
from KernelManagement import KMUserClient
from Foundation import NSObject # Core PyObjC framework
print(f"PyObjC version: {objc.__version__}")
# Verify that the KernelManagement framework's classes are accessible
# This only works on macOS systems.
if objc.platform == 'mac':
if hasattr(KMUserClient, 'alloc'):
print(f"KMUserClient class found from KernelManagement framework: {KMUserClient}")
print(f"Is KMUserClient an Objective-C class? {isinstance(KMUserClient, objc.objc_class)}")
else:
print("KMUserClient class is available but lacks expected methods (ensure framework is loaded).")
# A basic PyObjC interaction demonstrating the bridge with a common class
ns_object_instance = NSObject.alloc().init()
print(f"Created a basic NSObject instance: {ns_object_instance}")
else:
print("PyObjC and its framework bindings are macOS-specific and cannot run on this platform.")