PyObjC MediaExtension Framework
pyobjc-framework-mediaextension provides Python wrappers for the macOS MediaExtension framework, enabling developers to create extensions for media playback and editing on macOS. It is part of the larger PyObjC project, which bridges Python and the Objective-C runtime. The library is actively maintained with a regular release cadence, often tied to macOS SDK updates, with version 12.1 being the current stable release.
Warnings
- breaking PyObjC 12.0 (and thus pyobjc-framework-mediaextension 12.0) dropped support for Python 3.9. Projects using Python 3.9 must remain on PyObjC 11.x or older.
- breaking PyObjC 11.1 introduced a significant change in how PyObjC models Automatic Reference Counting (ARC) behavior for Objective-C initializer ('init') methods, aligning with `clang` documentation. Previously, certain `init` methods might not have correctly stolen or returned references, leading to potential memory management issues (leaks or premature deallocation) in code that heavily interacts with Objective-C object initialization.
- gotcha PyObjC 10.3 briefly removed support for using `__init__` in Python subclasses when `__new__` was not explicitly implemented by the user, causing breaks in some projects. Version 10.3.1 reinstated the ability to use `__init__` when a class or its superclass implements a user-defined `__new__`. However, if relying on PyObjC's provided `__new__`, `__init__` still cannot be used.
- gotcha PyObjC 11.0 introduced experimental support for Python 3.13's PEP 703 (free-threading). While not fully stable or enabled by default, this required significant internal changes to PyObjC's core bridge to handle Python's C API and reference counting in a thread-safe manner. Users planning to leverage free-threading with Python 3.13 and PyObjC should be aware of its experimental status and potential for unforeseen issues.
Install
-
pip install pyobjc-framework-mediaextension -
pip install pyobjc # installs all frameworks
Imports
- MediaExtension
import MediaExtension
- MEMediaExtension
from MediaExtension import MEMediaExtension
Quickstart
import MediaExtension
import objc
# The MediaExtension framework primarily deals with creating extensions
# for media playback and editing on macOS. Due to its nature, a simple
# script can only verify its presence and accessibility, not its full functionality
# which typically requires a host application context.
print('Attempting to import MediaExtension framework...')
try:
# Accessing a fundamental class from the framework verifies the import.
# MEMediaExtension is a key class. If the framework is correctly loaded,
# this class should be accessible.
media_extension_class = MediaExtension.MEMediaExtension
print(f"Successfully imported MediaExtension and accessed its class: {media_extension_class}")
# Further verification: Check for a common method (illustrative)
if hasattr(media_extension_class, 'beginMediaExtensionProcessWithConfiguration:completionHandler:'):
print("Found a common MediaExtension method, indicating bindings are functional.")
else:
print("Could not find a common MediaExtension method, though class is accessible.")
except objc.nosuchmodule_error:
print("Error: MediaExtension framework not found. This typically means you are not on macOS,")
print(" or the framework is not available for your macOS version.")
except AttributeError as e:
print(f"Error accessing MediaExtension classes: {e}. Framework might be present but classes not exposed or wrong name.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
print('Quickstart complete: Demonstrated successful import and class access for MediaExtension.')