PyObjC Carbon Framework

12.1 · active · verified Tue Apr 14

PyObjC-framework-carbon provides Python bindings for the Carbon framework on macOS. Carbon is an older API set largely deprecated by Apple in favor of Cocoa. This library is part of the larger PyObjC project, which offers comprehensive Objective-C-Python bridging and wrappers for numerous macOS frameworks. The current version is 12.1, and PyObjC typically releases new versions in sync with major macOS SDK updates and Python version support changes.

Warnings

Install

Imports

Quickstart

This quickstart attempts to retrieve a reference to the current Carbon Event Loop using a direct Carbon C API call wrapped by PyObjC. It includes error handling to acknowledge that Carbon APIs are deprecated on modern macOS and might not always succeed.

import objc
from Carbon.Events import GetCurrentEventLoop

def main():
    # Attempt to get the current Carbon event loop.
    # Note: Carbon APIs are largely deprecated on macOS and might not behave as expected
    # or even be available in newer OS versions/SDKs.
    try:
        event_loop = GetCurrentEventLoop()
        print(f"Successfully retrieved Carbon Event Loop reference: {event_loop}")
        print(f"Type: {type(event_loop)}")
    except objc.error as e:
        print(f"Could not retrieve Carbon Event Loop. Error: {e}")
        print("This is expected behavior on modern macOS as Carbon APIs are deprecated.")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

if __name__ == "__main__":
    main()

view raw JSON →