{"id":5024,"library":"pyobjc-framework-coretext","title":"PyObjC CoreText Framework Bindings","description":"This library provides Python wrappers for the CoreText framework on macOS, enabling Python applications to interact with macOS's advanced text layout and font rendering capabilities. It is part of the larger PyObjC project, which bridges Python and Objective-C/Cocoa. The current version is 12.1, and releases typically align with new macOS SDKs and Python versions.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","cocoa","bindings","coretext","fonts","text-rendering"],"install":[{"cmd":"pip install pyobjc-framework-coretext","lang":"bash","label":"Install CoreText bindings"}],"dependencies":[{"reason":"Provides the core bridge between Python and Objective-C, essential for all PyObjC framework bindings.","package":"pyobjc-core","optional":false}],"imports":[{"symbol":"CTFontCreateWithFontDescriptor","correct":"from CoreText import CTFontCreateWithFontDescriptor"},{"symbol":"CTFontDescriptorCreateWithNameAndSize","correct":"from CoreText import CTFontDescriptorCreateWithNameAndSize"}],"quickstart":{"code":"from CoreText import CTFontDescriptorCreateWithNameAndSize, CTFontCreateWithFontDescriptor, CTFontGetDisplayName\nfrom Foundation import NSBundle\n\n# Check if CoreText is available (generally true on macOS)\nif NSBundle.bundleWithPath_('/System/Library/Frameworks/CoreText.framework'):\n    print('CoreText framework is available.')\n\n    # Create a font descriptor for Helvetica at 16 points\n    font_descriptor = CTFontDescriptorCreateWithNameAndSize('Helvetica', 16.0)\n    if font_descriptor:\n        # Create a CTFontRef object from the descriptor\n        font = CTFontCreateWithFontDescriptor(font_descriptor, 0.0) # 0.0 for default font matrix\n        if font:\n            font_name = CTFontGetDisplayName(font)\n            print(f'Successfully created font: {font_name}')\n            print(f'Font object type: {type(font)}')\n        else:\n            print('Failed to create font from descriptor.')\n    else:\n        print('Failed to create font descriptor.')\nelse:\n    print('CoreText framework not found on this system.')\n","lang":"python","description":"This example demonstrates how to import and use basic CoreText functions to create and inspect a font object. It checks for the framework's availability and then uses `CTFontDescriptorCreateWithNameAndSize` and `CTFontCreateWithFontDescriptor` to instantiate a font, finally printing its display name."},"warnings":[{"fix":"Upgrade to a supported Python version (e.g., Python 3.10 or newer for PyObjC 12.x) or use an older PyObjC version that supports your Python runtime.","message":"PyObjC has periodically dropped support for older Python versions. Version 12.0 dropped support for Python 3.9, and version 11.0 dropped support for Python 3.8. Ensure your Python version meets the minimum requirement (currently Python 3.10+ for v12.x).","severity":"breaking","affected_versions":">=11.0"},{"fix":"Review custom class implementations inheriting from Objective-C objects, especially those overriding `__new__` and `__init__`. Prefer to perform initialization logic within `__new__` or Objective-C designated initializers when possible, or ensure `__init__` is correctly called in cases where it is supported.","message":"The behavior of `__init__` methods in Python subclasses of Objective-C classes, particularly when a custom `__new__` method is present, changed in v10.3 and was partially reverted in v10.3.1. In v10.3, `__init__` could not be used when PyObjC provided the `__new__`. In v10.3.1, this was relaxed for user-defined `__new__` methods, but `__init__` still cannot be used with PyObjC's default `__new__`.","severity":"breaking","affected_versions":"10.3 - 10.3.1"},{"fix":"If you are working with Objective-C objects directly, especially custom initializers, carefully review reference counting and object lifecycle. You might need to adjust manual retain/release calls or object ownership in more complex scenarios, although Python's garbage collection usually handles this.","message":"PyObjC v11.1 changed its Automatic Reference Counting (ARC) behavior for methods in the 'init' family to align with `clang`'s documentation. This means that such methods now correctly 'steal' a reference to `self` and return a new reference, which might alter object lifecycle if your code relied on the previous PyObjC behavior.","severity":"breaking","affected_versions":">=11.1"},{"fix":"Avoid using PyObjC with Python 3.13's free-threading mode in production environments until this feature is declared stable and fully supported by PyObjC. Stick to the default GIL-enabled mode for now.","message":"PyObjC's support for free-threading (PEP 703) introduced in Python 3.13 is experimental as of v11.0. While efforts have been made to support it, it may not be fully stable or correct for all use cases. It was explicitly stated as 'not supported' in earlier 3.13-compatible PyObjC releases (v10.3).","severity":"gotcha","affected_versions":">=10.3"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}