PyObjC Carbon Framework
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
- breaking The Carbon framework, which pyobjc-framework-carbon wraps, is largely deprecated and removed by Apple from macOS. Many APIs may not function as expected or be available on modern macOS versions/SDKs. Relying on Carbon APIs for new development is strongly discouraged.
- breaking PyObjC 12.0 (and by extension, pyobjc-framework-carbon 12.0 and newer) dropped support for Python 3.9. Projects must use Python 3.10 or later.
- gotcha PyObjC 11.1 aligned its Automatic Reference Counting (ARC) behavior for initializer methods with `clang`'s documentation. Methods in the 'init' family now correctly 'steal' a reference to `self` and return a new reference. This might subtly change memory management behavior for custom Objective-C subclasses implemented in Python.
- gotcha Behavior related to `__init__` and `__new__` methods in custom `objc` classes changed in PyObjC 10.3 and was partially reverted in 10.3.1. Specifically, 10.3 prevented calling `__init__` when PyObjC's `__new__` was used, which broke some projects. While 10.3.1 reintroduced `__init__` support when `__new__` is user-implemented, complex interactions can still arise.
Install
-
pip install pyobjc-framework-carbon
Imports
- GetCurrentEventLoop
from Carbon.Events import GetCurrentEventLoop
Quickstart
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()