{"id":6122,"library":"pyobjc-framework-iosurface","title":"PyObjC: IOSurface Framework","description":"PyObjC is a bridge between Python and Objective-C, enabling Python scripts to interact with and extend macOS's Cocoa libraries and other Objective-C frameworks. The `pyobjc-framework-iosurface` package provides Python wrappers specifically for Apple's IOSurface framework, which allows applications to share graphics buffers efficiently across processes. It is actively maintained, with version 12.1 being the latest, and sees regular updates to support new macOS SDKs and Python versions.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","frameworks","objective-c","iosurface","graphics","pyobjc"],"install":[{"cmd":"pip install pyobjc-framework-iosurface","lang":"bash","label":"Install `pyobjc-framework-iosurface`"},{"cmd":"pip install pyobjc # Installs all framework bindings","lang":"bash","label":"Install all PyObjC framework bindings"}],"dependencies":[{"reason":"Provides the core Python-Objective-C bridge functionality, essential for all PyObjC framework bindings.","package":"pyobjc-core"}],"imports":[{"note":"Accesses the IOSurface framework bindings directly.","symbol":"IOSurface","correct":"import IOSurface"}],"quickstart":{"code":"import IOSurface\n\n# Define properties for the IOSurface\n# PyObjC automatically bridges Python dictionaries to CFDictionary\n# and Python integers/booleans to CFNumber/CFBoolean.\nproperties = {\n    IOSurface.kIOSurfaceWidth: 640,\n    IOSurface.kIOSurfaceHeight: 480,\n    IOSurface.kIOSurfaceBytesPerElement: 4, # e.g., 4 bytes per pixel for 32-bit color\n    IOSurface.kIOSurfacePixelFormat: 0x42524741, # Example: 'ARGB' (Big-endian equivalent)\n    # IOSurface.kIOSurfaceBytesPerRow: 640 * 4, # Can be derived or explicitly set\n}\n\n# Create the IOSurface\nsurface = IOSurface.IOSurfaceCreate(properties)\n\nif surface:\n    print(f\"Successfully created IOSurface: {surface}\")\n    print(f\"IOSurface ID: {IOSurface.IOSurfaceGetID(surface)}\")\n    print(f\"IOSurface Width: {IOSurface.IOSurfaceGetWidth(surface)}\")\n    print(f\"IOSurface Height: {IOSurface.IOSurfaceGetHeight(surface)}\")\n    # The 'surface' object's memory is managed by Objective-C's ARC,\n    # but the Python wrapper will be garbage collected.\nelse:\n    print(\"Failed to create IOSurface.\")\n","lang":"python","description":"This quickstart demonstrates how to create a basic IOSurface object with specified dimensions and pixel format. It highlights how Python dictionaries and primitive types are automatically bridged to their CoreFoundation equivalents for IOSurface creation. The resulting IOSurface object provides access to its properties, such as ID, width, and height."},"warnings":[{"fix":"Upgrade Python to version 3.10 or later, or use an older PyObjC version compatible with your Python environment.","message":"PyObjC 12.0 dropped support for Python 3.9, and PyObjC 11.0 dropped support for Python 3.8. Users must ensure their Python version meets the `requires_python` specification (currently >=3.10) to use recent PyObjC versions.","severity":"breaking","affected_versions":">=11.0"},{"fix":"Review custom Python subclasses of Objective-C objects, especially those overriding `init` methods, to ensure correct reference handling if manual memory management was previously assumed. PyObjC generally handles ARC transparently, but this change ensures stricter compliance.","message":"PyObjC 11.1 introduced a significant change in how initializer methods (those in the 'init' family) handle object references, aligning with `clang`'s Automatic Reference Counting (ARC) documentation. This means `init` methods are now correctly modeled to steal a reference to `self` and return a new one.","severity":"breaking","affected_versions":">=11.1"},{"fix":"When calling Objective-C methods from Python via PyObjC, convert the Objective-C selector by replacing each colon with an underscore. The number of underscores corresponds to the number of arguments expected by the method.","message":"PyObjC translates Objective-C selectors (method names) with embedded colons (e.g., `doSomething:withSomethingElse:`) into Python method names where colons are replaced by underscores (e.g., `doSomething_withSomethingElse_`). Each underscore indicates an argument.","severity":"gotcha","affected_versions":"all"},{"fix":"If subclassing Objective-C classes in Python and implementing `__new__`, be aware of `__init__`'s behavior. For classes where PyObjC provides `__new__`, avoid implementing `__init__`. For user-implemented `__new__`, `__init__` can be used as of 10.3.1.","message":"In PyObjC 10.3, behavior around `__init__` when a user implements `__new__` was modified, potentially breaking some popular projects. Version 10.3.1 partially reverted this, reintroducing the ability to use `__init__` if `__new__` is user-implemented. However, code relying on PyObjC's provided `__new__` still cannot use `__init__` for reasons explained in the 10.3 release notes.","severity":"gotcha","affected_versions":"10.3 - 10.3.1"},{"fix":"Before relying on specific framework bindings, check their deprecation status in Apple's documentation. If a framework is deprecated or removed in macOS, its PyObjC bindings will likely be removed in a future release.","message":"PyObjC 10.0 removed bindings for the `IMServicePlugIn` framework as the framework itself was deprecated in macOS 10.13 and removed in macOS 14. This indicates a general trend where bindings for deprecated macOS frameworks may be removed in future PyObjC releases.","severity":"deprecated","affected_versions":">=10.0"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}