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.
pip install pyobjc-framework-healthkitVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade Python to a supported version (e.g., 3.10+ for PyObjC 12.x).
Review custom `init` method implementations and their Python wrappers, especially regarding reference counting, to ensure compatibility with ARC semantics.
Configure your macOS application's Xcode project to include the HealthKit capability and add the necessary privacy usage descriptions to its `Info.plist` file.
Avoid using Python's experimental free-threading (`python -X 'gil=0'`) when developing applications that rely on PyObjC frameworks. Use standard Python threading if needed.
Wrap all HealthKit-dependent code paths with a check for `HealthKit.HKHealthStore.isHealthDataAvailable()` to gracefully handle environments where HealthKit is not present.