{"id":2226,"library":"pyobjc-core","title":"PyObjC Core","description":"PyObjC Core is the essential bridge between Python and Objective-C, enabling Python applications to interact with macOS Cocoa frameworks. Version 12.1 is current, and releases typically align with new macOS SDKs and Python versions, with major versions appearing roughly annually and patches more frequently.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","objective-c","interop","cocoa","gui","apple"],"install":[{"cmd":"pip install pyobjc-core","lang":"bash","label":"Install core bridge only"},{"cmd":"pip install pyobjc","lang":"bash","label":"Install core bridge and common frameworks (recommended for most users)"}],"dependencies":[],"imports":[{"note":"The 'objc' module contains the core bridging functionality, including functions to look up Objective-C classes and fundamental constants.","symbol":"objc","correct":"import objc"},{"note":"Core PyObjC functions and classes are exposed directly under the 'objc' module, not 'pyobjc_core'.","wrong":"from pyobjc_core import lookUpClass","symbol":"lookUpClass","correct":"from objc import lookUpClass"},{"note":"Decorator to mark a Python class as an Objective-C class.","symbol":"python_class","correct":"from objc import python_class"}],"quickstart":{"code":"import objc\nfrom Foundation import NSString, NSDate, NSObject\n\n# 1. Basic interoperability: Python string to Objective-C NSString\npython_string = \"Hello from PyObjC!\"\nobjc_string = NSString.stringWithString_(python_string)\nprint(f\"Python string: '{python_string}' (Type: {type(python_string)})\\n\")\nprint(f\"Objective-C NSString: '{objc_string}' (Type: {type(objc_string)})\\n\")\n\n# 2. Get current date as NSDate\ncurrent_nsdate = NSDate.date()\nprint(f\"Current NSDate: {current_nsdate} (Type: {type(current_nsdate)})\\n\")\n\n# 3. Define a Python class that inherits from an Objective-C class\n@objc.python_class\nclass MyPythonObject(NSObject):\n    def init(self):\n        self = objc.super(MyPythonObject, self).init()\n        if self is None: return None\n        self.message = \"I am a Python-backed Objective-C object!\"\n        return self\n\n    # Expose a method callable from Objective-C (and Python)\n    @objc.selector('myCustomMethod')\n    def myCustomMethod(self):\n        return self.message\n\n# Create an instance and call the method\n# Note: alloc().init() is the standard Objective-C way to create objects.\npython_objc_instance = MyPythonObject.alloc().init()\nprint(f\"Message from Python-backed ObjC instance: {python_objc_instance.myCustomMethod()}\\n\")","lang":"python","description":"This quickstart demonstrates fundamental PyObjC interoperability, including converting Python types to Objective-C types, interacting with core Cocoa framework classes (like NSString and NSDate from Foundation), and defining Objective-C classes in Python. For this example to run, `pip install pyobjc` (which includes `pyobjc-core` and common frameworks like Foundation) is recommended."},"warnings":[{"fix":"Develop on macOS for applications leveraging PyObjC.","message":"PyObjC is a macOS-specific bridge; it relies on macOS's Objective-C runtime and Cocoa frameworks. It will not work on Windows or Linux.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your Python environment meets the minimum version requirements for the PyObjC release you are using.","message":"PyObjC frequently drops support for older Python versions (e.g., Python 3.9 dropped in v12.0, Python 3.8 in v11.0) to align with macOS SDKs and Python's own end-of-life cycles. Always check the 'requires_python' metadata for compatibility.","severity":"breaking","affected_versions":"v11.0, v12.0, and future major versions"},{"fix":"Review code involving Objective-C initializer methods to ensure correct reference management in light of ARC semantics. Consult the PyObjC 11.1 release notes for details.","message":"PyObjC 11.1 introduced significant changes to how initializer methods (`init` family) handle reference counting to align with `clang`'s Automatic Reference Counting (ARC) documentation. This can change memory management behavior and potentially cause leaks or crashes in existing code that made assumptions about object lifecycle during initialization.","severity":"breaking","affected_versions":"v11.1 and later"},{"fix":"Avoid using free-threading with PyObjC in critical applications until it is officially declared stable. Test thoroughly if experimental features are enabled.","message":"While PyObjC 11 introduced experimental support for Python's PEP 703 (free-threading) feature in Python 3.13, it is still experimental. Use with caution, as it may not be stable or fully optimized for production environments.","severity":"gotcha","affected_versions":"v11.0 and later (when used with Python 3.13+)"},{"fix":"For full functionality, install `pyobjc` using `pip install pyobjc` rather than `pyobjc-core` alone.","message":"`pyobjc-core` provides the fundamental bridge, but for most practical application development, you will also need specific framework bindings (e.g., `pyobjc-framework-Foundation`, `pyobjc-framework-AppKit`). The `pyobjc` meta-package installs `pyobjc-core` and many common frameworks and is generally recommended for ease of use.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}