{"id":6090,"library":"pyobjc-framework-coremotion","title":"PyObjC CoreMotion Framework","description":"PyObjC is a bridge between Python and Objective-C, enabling Python developers to write macOS applications and scripts using Apple's high-level system APIs. The `pyobjc-framework-coremotion` package provides Python wrappers for the CoreMotion framework on macOS, allowing access to device motion and environment-related data. The library is currently at version 12.1 and typically releases new major versions aligned with macOS SDK updates, usually around October/November, with minor bugfix releases as needed.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","objc","coremotion","pyobjc","apple-frameworks","sensor-data"],"install":[{"cmd":"pip install pyobjc-framework-coremotion","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"This package provides the fundamental bridge between Python and Objective-C, upon which all PyObjC framework wrappers are built.","package":"pyobjc-core"}],"imports":[{"note":"The CoreMotion framework bindings are accessed directly through the 'CoreMotion' package name.","symbol":"CoreMotion","correct":"import CoreMotion"},{"note":"Classes within the CoreMotion framework are attributes of the imported `CoreMotion` module, not submodules.","wrong":"from CoreMotion.CMMotionManager import CMMotionManager","symbol":"CMMotionManager","correct":"from CoreMotion import CMMotionManager"}],"quickstart":{"code":"import CoreMotion\nfrom Foundation import NSObject # Foundation is part of pyobjc-framework-Cocoa, which is usually installed with pyobjc\n\n# A simple check to ensure the CoreMotion framework is available and a class is accessible.\n# Actual use of CMMotionManager to get data would require an active NSApplication/NSRunLoop\n# and appropriate user permissions on macOS.\n\nprint(f\"CoreMotion module: {CoreMotion.__name__}\")\n\nif hasattr(CoreMotion, 'CMMotionManager'):\n    print(f\"CMMotionManager class found: {CoreMotion.CMMotionManager}\")\n    # Example: Attempting to instantiate CMMotionManager (requires an app context on macOS)\n    # manager = CoreMotion.CMMotionManager.alloc().init()\n    # print(f\"CMMotionManager instance created: {manager}\")\nelse:\n    print(\"CMMotionManager class not found. Ensure correct macOS version and PyObjC installation.\")\n","lang":"python","description":"This quickstart demonstrates how to import the `CoreMotion` framework and access a common class like `CMMotionManager`. While actual motion data retrieval requires a running macOS application context and user permissions, this code verifies that the framework is correctly imported and its classes are accessible in Python."},"warnings":[{"fix":"Upgrade Python to 3.10 or newer, or pin PyObjC to a compatible earlier version, e.g., `pip install pyobjc-framework-coremotion==11.1` for Python 3.9.","message":"PyObjC 12.0 dropped support for Python 3.9, and PyObjC 11.0 dropped support for Python 3.8. Users on these Python versions must pin to older PyObjC releases (e.g., PyObjC 11.1 for Python 3.9, PyObjC 10.3 for Python 3.8).","severity":"breaking","affected_versions":">=11.0, >=12.0"},{"fix":"Review custom Python subclasses of Objective-C objects, especially those overriding 'init' methods, to ensure compatibility with standard ARC behavior. Existing code might need adjustments if it relied on the prior 'partially initialized' state.","message":"PyObjC 11.1 changed how it handles Automatic Reference Counting (ARC) for Objective-C initializer methods. Methods in the 'init' family now correctly steal a reference to `self` and return a new one, diverging from previous 'partially initialized' object handling.","severity":"breaking","affected_versions":">=11.1"},{"fix":"For Python classes subclassing Objective-C objects, prefer Objective-C style `init*` methods. If overriding `__new__`, ensure it correctly calls `super().__new__` and returns an Objective-C object. If implementing `__init__`, ensure it doesn't conflict with PyObjC's object instantiation lifecycle, especially if not providing a custom `__new__`.","message":"The behavior around Python's `__init__` and Objective-C's `__new__` for PyObjC classes can be subtle. While PyObjC 10.3 initially broke `__init__` for classes relying on PyObjC's `__new__`, version 10.3.1 restored `__init__` functionality if the class or its superclasses implement their own `__new__` method. Classes relying on the PyObjC-provided `__new__` still cannot use `__init__`.","severity":"gotcha","affected_versions":">=10.3"},{"fix":"Monitor PyObjC release notes for updates on free-threading stability. If encountering issues related to concurrency with Python 3.13+, consider running without free-threading (if possible) or providing feedback to the PyObjC project.","message":"PyObjC 11.0 introduced experimental support for free-threading (PEP 703) with Python 3.13. While supported, users should be aware that this is an experimental feature and may have stability implications.","severity":"gotcha","affected_versions":">=11.0"},{"fix":"Ensure Xcode Command Line Tools are installed (`xcode-select --install`). For most users, using binary wheels (`pip install ...`) is the preferred and simpler installation method that avoids compiler requirements.","message":"Installing PyObjC from source (e.g., if binary wheels are unavailable or a specific SDK is needed) requires the Xcode Command Line Tools to be installed. Using an older macOS SDK than the one PyObjC was built against can lead to build errors.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}