{"library":"pyobjc-framework-healthkit","title":"PyObjC HealthKit Framework","description":"PyObjC-framework-HealthKit provides Python bindings for Apple's HealthKit framework on macOS. It allows Python applications to interact with health and fitness data, offering a bridge to Objective-C APIs. The library is actively maintained with frequent releases, often synchronized with macOS SDK updates and changes in Python version support.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install pyobjc-framework-healthkit"],"cli":null},"imports":["import HealthKit","from HealthKit import HKHealthStore","from HealthKit import HKObjectType"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import HealthKit\nfrom PyObjCTools import AppHelper\n\ndef request_health_authorization():\n    if not HealthKit.HKHealthStore.isHealthDataAvailable():\n        print(\"HealthKit is not available on this device.\")\n        return\n\n    health_store = HealthKit.HKHealthStore.alloc().init()\n\n    # Define types to read and write\n    # Example: Body Mass and Height\n    try:\n        body_mass_type = HealthKit.HKObjectType.quantityTypeForIdentifier_(\n            HealthKit.HKQuantityTypeIdentifierBodyMass\n        )\n        height_type = HealthKit.HKObjectType.quantityTypeForIdentifier_(\n            HealthKit.HKQuantityTypeIdentifierHeight\n        )\n    except Exception as e:\n        print(f\"Error getting HealthKit object types: {e}\")\n        return\n\n    types_to_read = {body_mass_type, height_type}\n    types_to_share = set() # No data to write in this example\n\n    # Request authorization\n    # Note: This will trigger a system prompt to the user\n    def completion_handler(success, error):\n        if success:\n            print(\"HealthKit authorization granted.\")\n            # You can now proceed with HealthKit operations\n        else:\n            print(f\"HealthKit authorization denied or error: {error}\")\n        AppHelper.stopEventLoop()\n\n    health_store.requestAuthorizationToShareTypes_readTypes_completion_(\n        types_to_share,\n        types_to_read,\n        completion_handler\n    )\n\n\nif __name__ == '__main__':\n    # Run this from a macOS app context or a script with UI entitlements\n    # For a simple script, ensure PyObjCTools.AppHelper.runEventLoop() is used\n    # to handle asynchronous callbacks.\n    print(\"Requesting HealthKit authorization...\")\n    request_health_authorization()\n    # For simple scripts where a UI application loop isn't explicitly started,\n    # AppHelper.runEventLoop() ensures callbacks are processed.\n    # In a full Cocoa app, the app's runloop would handle this.\n    AppHelper.runEventLoop()\n","lang":"python","description":"This quickstart demonstrates how to check for HealthKit availability and request authorization to read specific data types (Body Mass and Height). Running this code will trigger a system prompt asking the user for permission. HealthKit operations require an active run loop to handle asynchronous callbacks. For a standalone script, `PyObjCTools.AppHelper.runEventLoop()` is essential to process these callbacks and wait for the authorization request to complete. Note that HealthKit features require an application with the proper entitlements set in Xcode.","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-healthkit","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-healthkit","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":2.9,"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-healthkit","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-healthkit","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.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pyobjc-framework-healthkit","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-healthkit","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":2.9,"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-healthkit","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-healthkit","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":2.5,"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-healthkit","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-healthkit","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":3.4,"import_time_s":null,"mem_mb":null,"disk_size":null}]}}