PyObjC MetricKit Framework

12.1 · active · verified Tue Apr 14

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.

Warnings

Install

Imports

Quickstart

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.

import objc
from MetricKit import MXMetricManager
from Foundation import NSLog # Used for Objective-C style logging

def get_metrickit_manager():
    """
    Retrieves the shared MetricKit manager instance.
    MetricKit is used for collecting power and performance metrics from an app.
    Note: This is primarily designed for macOS apps/extensions to submit data to Apple, 
    not typically for standalone console scripts to actively collect and process.
    """
    manager = MXMetricManager.sharedManager()
    NSLog(f"MetricKit Shared Manager: {manager}")
    # In a full application, you would typically add a subscriber (an NSObject subclass)
    # manager.addSubscriber_(my_subscriber_instance)
    return manager

if __name__ == "__main__":
    print("Attempting to get MetricKit manager...")
    manager = get_metrickit_manager()
    if manager:
        print(f"Successfully retrieved MetricKit manager: {manager}")
    else:
        print("Failed to retrieve MetricKit manager.")

view raw JSON →