PyObjC Framework: DiskArbitration
This library provides Python wrappers for Apple's DiskArbitration framework on macOS, enabling programmatic interaction with disk management, mount/unmount events, and disk information. It is part of the larger PyObjC project, currently at version 12.1, with a release cadence often synchronized with macOS SDK updates 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. Users on these older Python versions must use an earlier PyObjC version.
- breaking PyObjC 11.1 introduced significant changes in how initializer methods (`init` family) are handled for Automatic Reference Counting (ARC), aligning with clang's documentation. This can alter reference counting behavior for custom Objective-C classes or Python subclasses.
- gotcha The interaction between Objective-C object initialization (`alloc`/`init`) and Python's `__new__`/`__init__` can be complex. PyObjC 10.3 temporarily broke the ability to call `__init__` after `__new__` for some cases, which was partially reverted in 10.3.1. Code relying on custom `__new__` might behave unexpectedly.
- gotcha While Python 3.13 introduces experimental free-threading (PEP 703), PyObjC 10.3 explicitly stated it did not support it. PyObjC 11.0 added *experimental* free-threading support. Using PyObjC in a free-threaded environment before full, stable support could lead to instability or incorrect behavior.
Install
-
pip install pyobjc-framework-diskarbitration -
pip install pyobjc
Imports
- DiskArbitration
import DiskArbitration
Quickstart
import DiskArbitration
import CoreFoundation
# Create a DiskArbitration session
session = DiskArbitration.DASessionCreate(CoreFoundation.kCFAllocatorDefault)
if session:
print("DiskArbitration session created successfully.")
# In a real application, you would register callbacks, e.g., using DASessionScheduleWithRunLoop
# For a quick demo, we just verify session creation and release it.
CoreFoundation.CFRelease(session)
else:
print("Failed to create DiskArbitration session.")