{"library":"pyobjc-framework-corehaptics","title":"PyObjC CoreHaptics Framework","description":"This library provides Python bindings for Apple's CoreHaptics framework on macOS, allowing developers to integrate sophisticated haptic feedback into their applications. As part of the larger PyObjC bridge, it enables direct interaction with Objective-C APIs from Python. The current version is 12.1, and releases generally follow macOS SDK updates and Python version support changes.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install pyobjc-framework-corehaptics"],"cli":null},"imports":["from CoreHaptics import CHHapticEngine","from CoreHaptics import CHHapticEvent","from CoreHaptics import CHHapticPattern","from CoreHaptics import CHHapticEventParameterID","from Foundation import NSArray","from Foundation import NSThread","import objc"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import objc\nfrom CoreHaptics import (\n    CHHapticEngine, CHHapticPattern, CHHapticEvent,\n    CHHapticEventParameter, CHHapticEventParameterID, CHHapticEventType\n)\nfrom Foundation import NSArray, NSThread\n\ndef play_haptic_feedback():\n    \"\"\"\n    Initializes a CHHapticEngine and plays a simple haptic impact.\n    Requires macOS and haptic feedback enabled.\n    \"\"\"\n    print(\"Attempting to play haptic feedback...\")\n\n    # Create an error holder (PyObjC will populate if an error occurs)\n    error = objc.nil\n\n    # 1. Initialize the haptic engine\n    engine = CHHapticEngine.alloc().initAndReturnError_(objc.ptr(error))\n    if engine is None:\n        print(f\"Error initializing CHHapticEngine: {error[0] if error else 'Unknown error'}\")\n        return\n\n    # 2. Set an error handler for the engine\n    engine.setErrorHandler_(lambda err: print(f\"CHHapticEngine encountered an error: {err}\"))\n\n    # 3. Start the engine\n    success, error = engine.startAndReturnError_(objc.ptr(error))\n    if not success:\n        print(f\"Error starting CHHapticEngine: {error[0] if error else 'Unknown error'}\")\n        return\n    print(\"CHHapticEngine started.\")\n\n    # 4. Create haptic event parameters\n    intensity_param = CHHapticEventParameter.alloc().initWithParameterID_value_(\n        CHHapticEventParameterID.CHHapticEventParameterIDHapticIntensity, 0.8\n    )\n    sharpness_param = CHHapticEventParameter.alloc().initWithParameterID_value_(\n        CHHapticEventParameterID.CHHapticEventParameterIDHapticSharpness, 0.6\n    )\n\n    # 5. Create a haptic event (a transient impact)\n    event = CHHapticEvent.alloc().initWithEventType_parameters_relativeTime_duration_(\n        CHHapticEventType.CHHapticEventTypeHapticTransient,\n        NSArray.arrayWithArray_([intensity_param, sharpness_param]),\n        0.0,\n        0.1\n    )\n\n    # 6. Create a haptic pattern from the event\n    pattern = CHHapticPattern.alloc().initWithEvents_parameters_error_(\n        NSArray.arrayWithArray_([event]),\n        objc.nil,\n        objc.ptr(error)\n    )\n    if pattern is None:\n        print(f\"Error creating CHHapticPattern: {error[0] if error else 'Unknown error'}\")\n        engine.stopWithCompletionHandler_(objc.nil)\n        return\n\n    # 7. Create a player for the pattern\n    player, error = engine.createPlayerWithPattern_error_(pattern, objc.ptr(error))\n    if player is None:\n        print(f\"Error creating CHHapticPatternPlayer: {error[0] if error else 'Unknown error'}\")\n        engine.stopWithCompletionHandler_(objc.nil)\n        return\n\n    # 8. Start the player\n    success, error = player.startAtTime_error_(0, objc.ptr(error))\n    if not success:\n        print(f\"Error starting CHHapticPatternPlayer: {error[0] if error else 'Unknown error'}\")\n        engine.stopWithCompletionHandler_(objc.nil)\n        return\n    print(\"Haptic pattern started playing.\")\n\n    # 9. Keep the script alive long enough for the haptic to play\n    NSThread.sleepForTimeInterval_(1.5)\n\n    # 10. Stop the engine gracefully\n    success, error = engine.stopAndReturnError_(objc.ptr(error))\n    if not success:\n        print(f\"Error stopping CHHapticEngine: {error[0] if error else 'Unknown error'}\")\n    print(\"CHHapticEngine stopped.\")\n\nif __name__ == \"__main__\":\n    play_haptic_feedback()\n","lang":"python","description":"This quickstart demonstrates how to initialize the `CHHapticEngine`, define a simple haptic impact using `CHHapticEvent` and `CHHapticEventParameter`, create a `CHHapticPattern`, and play it. This code will only run on macOS systems with haptic feedback capabilities. Ensure your system's haptic settings are enabled.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":null,"pypi_latest":"12.1","is_stale":null,"summary":{"python_range":"3.10–3.9","success_rate":0,"avg_install_s":null,"avg_import_s":null,"wheel_type":null},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pyobjc-framework-corehaptics","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pyobjc-framework-corehaptics","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":3.3,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pyobjc-framework-corehaptics","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pyobjc-framework-corehaptics","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":3.1,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pyobjc-framework-corehaptics","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pyobjc-framework-corehaptics","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":3,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pyobjc-framework-corehaptics","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pyobjc-framework-corehaptics","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":2.6,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pyobjc-framework-corehaptics","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pyobjc-framework-corehaptics","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":3.6,"import_time_s":null,"mem_mb":null,"disk_size":null}]}}