{"id":6139,"library":"pyobjc-framework-metalperformanceshaders","title":"PyObjC: MetalPerformanceShaders Framework","description":"PyObjC is a bridge between Python and Objective-C that allows Python applications to use Objective-C frameworks and objects. `pyobjc-framework-metalperformanceshaders` provides Python bindings for Apple's MetalPerformanceShaders framework on macOS, offering highly optimized GPU-accelerated functions for tasks like image processing, machine learning, and physics simulations. The library is actively maintained, with version 12.1 being the latest as of November 2025, and receives frequent updates tied to new macOS SDK releases.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","framework","metal","gpu","machine-learning","image-processing","pyobjc"],"install":[{"cmd":"pip install pyobjc-framework-metalperformanceshaders","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"This package provides the core bridging functionality between Python and Objective-C, essential for all PyObjC framework bindings.","package":"pyobjc-core"}],"imports":[{"note":"All classes and functions from the MetalPerformanceShaders framework are exposed under the `MetalPerformanceShaders` module.","symbol":"MetalPerformanceShaders","correct":"import MetalPerformanceShaders"}],"quickstart":{"code":"import objc\nfrom Foundation import NSObject # Often implicitly imported or used by other frameworks\nimport MetalPerformanceShaders\n\n# Accessing a basic class from the framework\n# MPSKernel is a base class for many Metal Performance Shaders operations.\ntry:\n    # Simply accessing the class confirms the import and binding are working.\n    _ = MetalPerformanceShaders.MPSKernel\n    print(\"Successfully imported MetalPerformanceShaders and accessed MPSKernel.\")\n\n    # Note: Full usage of MetalPerformanceShaders (e.g., creating a blur filter, \n    # running a neural network, or performing ray tracing) is complex. \n    # It requires setting up a Metal device, command queue, and textures.\n    # For example:\n    # from Metal import MTLCreateSystemDefaultDevice\n    # device = MTLCreateSystemDefaultDevice()\n    # commandQueue = device.newCommandQueue()\n    # # ... then create MPSImageGaussianBlur, encode to command buffer, etc.\n    print(\"Note: Actual usage of MetalPerformanceShaders requires a Metal context (device, command queue, textures). Refer to Apple's Metal Performance Shaders documentation for details.\")\n\nexcept objc.nosuchmethod_error as e:\n    print(f\"Error accessing MetalPerformanceShaders.MPSKernel: {e}\")\n    print(\"This might indicate an issue with the framework bindings or an incompatible macOS version.\")\nexcept ImportError as e:\n    print(f\"Error importing MetalPerformanceShaders: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to import the `MetalPerformanceShaders` framework through PyObjC and access a basic class like `MPSKernel`. Real-world usage of this framework is highly dependent on Apple's Metal API, requiring a Metal device, command queue, and texture management for actual GPU-accelerated operations."},"warnings":[{"fix":"Upgrade to Python 3.10 or later for PyObjC 12.x, or Python 3.9 or later for PyObjC 11.x.","message":"`pyobjc-framework-metalperformanceshaders` version 12.0 dropped support for Python 3.9. Version 11.0 dropped support for Python 3.8. Ensure your Python version meets the `pyobjc` requirements (currently Python >=3.10).","severity":"breaking","affected_versions":"11.0, 12.0"},{"fix":"Review custom Python subclasses of Objective-C classes and adapt initialization logic to use `SomeClass.alloc().init()` or `SomeClass(...)`. If providing a custom `__new__`, ensure `__init__` is correctly called if desired.","message":"PyObjC 10.3 introduced changes to how `__init__` and `__new__` methods are handled when subclassing Objective-C classes in Python. While a partial revert in 10.3.1 allowed `__init__` when a user-defined `__new__` exists, it can still break code relying on the old behavior where `__init__` was called regardless. The recommended pattern is to use `SomeClass.alloc().init()` or the more Pythonic `SomeClass(...)` (introduced in PyObjC 10.3) for object initialization.","severity":"breaking","affected_versions":"10.3, 10.3.1"},{"fix":"Consult Apple's Metal Performance Shaders documentation for API specifics and usage examples.","message":"PyObjC framework bindings, including `pyobjc-framework-metalperformanceshaders`, do not include their own documentation. Users must refer to Apple's official Objective-C and Swift documentation for the MetalPerformanceShaders framework to understand the available APIs and their usage.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure Xcode and its Command Line Tools are installed and updated (`xcode-select --install`). For binary wheels, this is usually not an issue.","message":"Installing PyObjC from source (e.g., using `pip install --no-binary :all: pyobjc`) requires a full Xcode installation or the Xcode Command Line Tools to be present, along with a sufficiently new macOS SDK. Building with an older SDK can lead to compilation errors due to missing protocol declarations or other API changes.","severity":"gotcha","affected_versions":"All versions (when installing from source)"},{"fix":"Avoid direct reliance on the `isAlloc` attribute of `objc.selector`. Consult PyObjC documentation for alternative approaches if needed.","message":"The `isAlloc` attribute of `objc.selector` is deprecated and will be removed in PyObjC 12. While this change is primarily internal to the bridge, users with highly specialized code that directly inspects `objc.selector` attributes should be aware.","severity":"deprecated","affected_versions":"11.x and earlier"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}