{"id":6141,"library":"pyobjc-framework-metrickit","title":"PyObjC MetricKit Framework","description":"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.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","framework","metrics","pyobjc","apple"],"install":[{"cmd":"pip install pyobjc-framework-metrickit","lang":"bash","label":"Install PyObjC MetricKit"}],"dependencies":[{"reason":"Provides the core bridge between Python and Objective-C, required for all PyObjC framework bindings.","package":"pyobjc-core"},{"reason":"MetricKit depends on core Foundation classes like NSObject and NSLog.","package":"pyobjc-framework-Foundation"},{"reason":"Required for dispatch-related functionality.","package":"pyobjc-framework-libdispatch"}],"imports":[{"symbol":"MXMetricManager","correct":"from MetricKit import MXMetricManager"},{"symbol":"MXDiagnosticPayload","correct":"from MetricKit import MXDiagnosticPayload"},{"symbol":"MXMetricPayload","correct":"from MetricKit import MXMetricPayload"}],"quickstart":{"code":"import objc\nfrom MetricKit import MXMetricManager\nfrom Foundation import NSLog # Used for Objective-C style logging\n\ndef get_metrickit_manager():\n    \"\"\"\n    Retrieves the shared MetricKit manager instance.\n    MetricKit is used for collecting power and performance metrics from an app.\n    Note: This is primarily designed for macOS apps/extensions to submit data to Apple, \n    not typically for standalone console scripts to actively collect and process.\n    \"\"\"\n    manager = MXMetricManager.sharedManager()\n    NSLog(f\"MetricKit Shared Manager: {manager}\")\n    # In a full application, you would typically add a subscriber (an NSObject subclass)\n    # manager.addSubscriber_(my_subscriber_instance)\n    return manager\n\nif __name__ == \"__main__\":\n    print(\"Attempting to get MetricKit manager...\")\n    manager = get_metrickit_manager()\n    if manager:\n        print(f\"Successfully retrieved MetricKit manager: {manager}\")\n    else:\n        print(\"Failed to retrieve MetricKit manager.\")\n","lang":"python","description":"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."},"warnings":[{"fix":"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`).","message":"PyObjC 12.0 dropped support for Python 3.9. Projects targeting older Python versions must use an older PyObjC release (e.g., PyObjC 11.x for Python 3.9).","severity":"breaking","affected_versions":">=12.0"},{"fix":"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`).","message":"PyObjC 11.0 dropped support for Python 3.8. Users on Python 3.8 need to use PyObjC 10.x or earlier.","severity":"breaking","affected_versions":">=11.0"},{"fix":"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.","message":"PyObjC 11.1 introduced significant changes to how initializer methods are handled, aligning the core bridge with clang's Automatic Reference Counting (ARC) documentation. Methods in the 'init' family now correctly steal a reference to self and return a new reference, which can affect custom memory management or interactions with `alloc`.","severity":"breaking","affected_versions":">=11.1"},{"fix":"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.","message":"In PyObjC 10.3, calling `__init__` was initially restricted for classes implementing `__new__`, causing breaks in some projects. While partially re-introduced in 10.3.1, users defining custom `__new__` methods should be cautious, as the behavior around `__init__` might still differ from older PyObjC versions or standard Python class initialization.","severity":"gotcha","affected_versions":">=10.3, <10.3.2"},{"fix":"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.","message":"MetricKit is designed for deep integration into macOS applications or extensions to report metrics to Apple. While its APIs are exposed, successfully collecting and submitting metrics usually requires running within an appropriate application context with an `NSApplication` runloop, rather than a simple command-line Python script. Payloads are delivered asynchronously.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z","problems":[]}