{"id":6140,"library":"pyobjc-framework-metalperformanceshadersgraph","title":"PyObjC: MetalPerformanceShadersGraph","description":"PyObjC-framework-MetalPerformanceShadersGraph provides Python wrappers for Apple's MetalPerformanceShadersGraph framework on macOS. This framework enables high-performance, energy-efficient computation on Apple platforms by leveraging various hardware compute blocks, allowing users to generate symbolic compute graphs of operations for GPU execution. The library is actively maintained with frequent releases, often synchronized with new macOS SDK updates. Its current version is 12.1.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","apple","metal","gpu","graphics","framework","pyobjc","neural-networks","machine-learning","high-performance-computing"],"install":[{"cmd":"pip install pyobjc-framework-metalperformanceshadersgraph","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"All pyobjc-framework-* packages depend on pyobjc-core for the Python-Objective-C bridge functionality.","package":"pyobjc-core","optional":false}],"imports":[{"note":"PyObjC typically maps macOS frameworks directly to top-level Python packages.","symbol":"MPSGraph","correct":"from MetalPerformanceShadersGraph import MPSGraph"},{"note":"Many Cocoa classes, including `NSObject`, are found in the `Foundation` framework, which is wrapped by `pyobjc-framework-Foundation`.","symbol":"NSObject","correct":"from Foundation import NSObject"}],"quickstart":{"code":"from MetalPerformanceShadersGraph import MPSGraph\nfrom Foundation import NSObject # For general PyObjC interaction\n\n# Instantiate a Metal Performance Shaders Graph\n# Note: This is a minimal example. Actual graph creation involves defining\n# tensors, operations, and compiling for a Metal device.\n# Refer to Apple's MetalPerformanceShadersGraph documentation for usage.\n\ntry:\n    graph = MPSGraph.alloc().init()\n    # Alternatively, for PyObjC 10.4+ a more Pythonic way often works:\n    # graph = MPSGraph()\n    print(f\"Successfully instantiated MPSGraph: {graph}\")\n    print(f\"MPSGraph options: {graph.options()}\")\nexcept Exception as e:\n    print(f\"Failed to instantiate MPSGraph or access options: {e}\")\n    print(\"Ensure you are running on macOS with Metal support.\")\n\n# Example of a basic NSObject to confirm PyObjC is working generally\nobj = NSObject.alloc().init()\nprint(f\"Successfully instantiated NSObject: {obj}\")","lang":"python","description":"This quickstart demonstrates the basic import and instantiation of an `MPSGraph` object using PyObjC. A full MetalPerformanceShadersGraph workflow involves complex setup with tensors, operations, and compilation for a specific Metal device, which is beyond the scope of a minimal quickstart. Users should consult Apple's official documentation for detailed MPSGraph usage."},"warnings":[{"fix":"Upgrade your Python environment to Python 3.10 or newer to use PyObjC 12.x.","message":"PyObjC has dropped support for older Python versions. PyObjC 12.0 dropped support for Python 3.9, and PyObjC 11.0 dropped support for Python 3.8.","severity":"breaking","affected_versions":">=11.0"},{"fix":"Review custom Python subclasses of Objective-C classes, especially `__init__` and `__new__` implementations. Prefer the Pythonic `SomeClass(...)` instantiation or explicitly use `SomeClass.alloc().init...()` for clarity.","message":"The behavior of `__init__` and object instantiation was significantly changed in PyObjC 10.3 and 11.1. PyObjC 10.3 initially broke `__init__` for classes not defining their own `__new__`, though 10.3.1 partially reverted this. PyObjC 11.1 aligned reference counting for 'init' methods with `clang`'s ARC documentation. Direct calls to methods on partially initialized objects (`SomeClass.alloc()`) may lead to unexpected behavior or crashes in recent versions, as such patterns used to 'accidentally work' but hid reference counting bugs.","severity":"breaking","affected_versions":">=10.3"},{"fix":"Avoid using PyObjC in Python environments configured for experimental free-threading. Use a standard CPython build.","message":"PyObjC does not support the experimental free-threading feature (PEP 703) introduced in Python 3.13. Using PyObjC in a free-threaded Python environment may lead to undefined behavior or crashes.","severity":"gotcha","affected_versions":">=10.3 (with Python 3.13+)"},{"fix":"If you relied on KVO for Python-defined `NSProxy` subclasses, be aware that this behavior has changed. Consider upgrading to v12.1 or re-evaluate your KVO approach for such classes.","message":"Key-Value Observing (KVO) usage for subclasses of `NSProxy` defined in Python was automatically disabled in PyObjC 12.1 due to prior issues.","severity":"gotcha","affected_versions":"<12.1"},{"fix":"If your application relied on `IMServicePlugIn`, it will no longer function on macOS 14+ or with PyObjC 10.0+. You must migrate to alternative macOS APIs.","message":"The `IMServicePlugIn` framework bindings were removed in PyObjC 10.0 because the entire framework was deprecated in macOS 10.13 and removed in macOS 14.","severity":"breaking","affected_versions":">=10.0"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z","problems":[]}