PyObjC MediaToolbox Framework
PyObjC provides Python bindings for Objective-C frameworks on macOS, enabling Python developers to interact with Apple's system APIs. `pyobjc-framework-mediatoolbox` offers wrappers for the MediaToolbox framework, which supports media format readers and audio processing. The library is currently at version 12.1 and maintains an active release cadence, typically aligning with macOS and Python version updates.
Warnings
- breaking PyObjC frequently drops support for older Python versions. PyObjC 12.0 dropped Python 3.9, and PyObjC 11.0 dropped Python 3.8.
- breaking PyObjC 11.1 aligned its core bridge with `clang`'s Automatic Reference Counting (ARC) documentation for initializer methods. Methods in the 'init' family now correctly steal a reference to `self` and return a new reference. This can alter memory management behavior for Python subclasses overriding Objective-C initializers.
- gotcha PyObjC 10.3 initially broke `__init__` usage for Python subclasses of Objective-C classes, particularly when a user implemented `__new__` or when relying on PyObjC's `__new__` behavior. This was partially reverted in 10.3.1 to reintroduce `__init__` support when a user implements `__new__`.
- breaking In PyObjC 10.0, the `IMServicePlugIn` bindings were removed as the entire framework was deprecated in macOS 10.13 and removed in macOS 14.
- gotcha PyObjC 11.0 introduced experimental support for free-threading (PEP 703) with Python 3.13+. While PyObjC protects its own implementation, Apple's frameworks are not necessarily thread-safe (e.g., `NSMutableArray` for concurrent updates, non-atomic properties, GUI classes on non-main threads).
Install
-
pip install pyobjc-framework-mediatoolbox
Imports
- MediaToolbox
import MediaToolbox
Quickstart
import MediaToolbox
import Foundation
# Simply importing the framework demonstrates it's loadable.
# Accessing a generic Objective-C class (e.g., NSObject from Foundation)
# via any PyObjC framework binding confirms the bridge is working.
# In a real application, you would access MediaToolbox-specific classes or functions
# e.g., MediaToolbox.MTAudioProcessingTapCreate
# or constants like kCMFormatDescriptionBridgeError_InvalidParameter if exposed via MediaToolbox or an imported dependency.
print(f"MediaToolbox module loaded from: {MediaToolbox.__file__}")
# Verify that basic PyObjC functionality is available by accessing NSObject
# which is part of Foundation, implicitly loaded or linked by most PyObjC frameworks.
if hasattr(Foundation, 'NSObject'):
print(f"Foundation.NSObject available, indicating PyObjC bridge is active.")
else:
print("Foundation.NSObject not found, PyObjC bridge might not be fully active.")