This package provides Python bindings for the MetricKit framework on macOS, allowing Python applications to access Apple's system for collecting power and performance metrics. It is part of the larger PyObjC project, which provides comprehensive Objective-C bridge functionality. The library is actively maintained, with new versions often aligning with macOS SDK updates and Python releases.
pip install pyobjc-framework-metrickitVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import and access the shared `MXMetricManager` instance, which is the entry point for MetricKit. MetricKit is primarily designed for macOS applications or extensions to submit performance and diagnostic metrics to Apple. While you can access its symbols in a script, active data collection and submission usually require an application context.
Upgrade your Python environment to 3.10 or later, or pin pyobjc-framework-metrickit to a version less than 12.0 (e.g., `pyobjc-framework-metrickit<12`).
Upgrade your Python environment to 3.9 or later, or pin pyobjc-framework-metrickit to a version less than 11.0 (e.g., `pyobjc-framework-metrickit<11`).
Review any custom `__init__` or `__new__` implementations, especially those interacting directly with Objective-C `alloc` or `init` patterns, and ensure ARC semantics are respected. In most cases, standard Python usage should be unaffected.
If encountering issues with `__init__` not being called correctly after `__new__`, consider if your `__new__` method is returning an Objective-C object directly or relying on PyObjC's `__new__` implementation. Review PyObjC 10.3/10.3.1 release notes for specific scenarios.
If developing a macOS app, integrate MetricKit into your application delegate or relevant lifecycle hooks. For testing purposes in scripts, understand that payloads might not be delivered, or the environment might not fully support MetricKit's intended operation. Use `PyObjCTools.AppHelper.runConsoleEventLoop()` to keep a console application alive for callbacks if needed.