PyObjC CoreMotion Framework

12.1 · active · verified Tue Apr 14

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.

Warnings

Install

Imports

Quickstart

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.

import CoreMotion
from Foundation import NSObject # Foundation is part of pyobjc-framework-Cocoa, which is usually installed with pyobjc

# A simple check to ensure the CoreMotion framework is available and a class is accessible.
# Actual use of CMMotionManager to get data would require an active NSApplication/NSRunLoop
# and appropriate user permissions on macOS.

print(f"CoreMotion module: {CoreMotion.__name__}")

if hasattr(CoreMotion, 'CMMotionManager'):
    print(f"CMMotionManager class found: {CoreMotion.CMMotionManager}")
    # Example: Attempting to instantiate CMMotionManager (requires an app context on macOS)
    # manager = CoreMotion.CMMotionManager.alloc().init()
    # print(f"CMMotionManager instance created: {manager}")
else:
    print("CMMotionManager class not found. Ensure correct macOS version and PyObjC installation.")

view raw JSON →