{"id":5411,"library":"pyobjc-framework-uniformtypeidentifiers","title":"UniformTypeIdentifiers Framework (PyObjC)","description":"PyObjC is a comprehensive bridge that enables Python developers to interact with Objective-C frameworks on macOS. The `pyobjc-framework-uniformtypeidentifiers` package provides Python wrappers for Apple's UniformTypeIdentifiers framework, which allows applications to work with system-declared and custom Uniform Type Identifiers (UTIs) to describe file types, data formats, and other resources. The library is currently at version 12.1 and maintains an active release cadence, often aligning with macOS and Python version updates.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","objective-c","cocoa","apple","framework","uti"],"install":[{"cmd":"pip install pyobjc-framework-uniformtypeidentifiers","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"This package is a wrapper for a specific macOS framework and requires the core PyObjC bridge for Objective-C interoperability.","package":"pyobjc-core","optional":false}],"imports":[{"note":"The `UniformTypeIdentifiers` framework is imported as a module. Classes like `UTType` are attributes of this module, e.g., `UniformTypeIdentifiers.UTType`.","wrong":"from UniformTypeIdentifiers import UTType","symbol":"UniformTypeIdentifiers","correct":"import UniformTypeIdentifiers"}],"quickstart":{"code":"import UniformTypeIdentifiers\nfrom Foundation import NSURL # Foundation is often implicitly needed or useful\n\n# Get a system-declared UTI for an image\nimage_type = UniformTypeIdentifiers.UTType.image\nprint(f\"Image UTI Identifier: {image_type.identifier}\")\nprint(f\"Image UTI Preferred filename extension: {image_type.preferredFilenameExtension}\")\n\n# Check conformance\ntext_type = UniformTypeIdentifiers.UTType.text\nis_text_conforming_to_data = text_type.conformsToType_(UniformTypeIdentifiers.UTType.data)\nprint(f\"Does text UTI conform to data UTI? {is_text_conforming_to_data}\")\n\n# Get a UTI from a filename extension\npdf_type = UniformTypeIdentifiers.UTType.typeWithFilenameExtension_(\"pdf\")\nif pdf_type:\n    print(f\"PDF UTI Identifier: {pdf_type.identifier}\")","lang":"python","description":"This example demonstrates how to import the `UniformTypeIdentifiers` framework, access system-declared UTIs, check type conformance, and create a UTI from a filename extension. Note that `Foundation` is often imported alongside PyObjC frameworks for basic Cocoa types like `NSURL`."},"warnings":[{"fix":"Ensure your Python environment meets the `requires_python` specification (>=3.10 for PyObjC 12.1) before upgrading PyObjC. Always check the PyObjC release notes or PyPI metadata for the target version.","message":"PyObjC frequently drops support for older Python versions. PyObjC 12.0 dropped Python 3.9 support, and PyObjC 11.0 dropped Python 3.8 support. Version 12.1 corrected packaging metadata that incorrectly showed support for Python 3.9, which could lead to installation failures on that version.","severity":"breaking","affected_versions":">=11.0"},{"fix":"Review custom `init` implementations in Python subclasses of Objective-C objects. PyObjC 10.3 introduced a Pythonic `Class(...)` instantiation pattern that is generally safer.","message":"PyObjC 11.1 aligned its core bridge with `clang`'s Automatic Reference Counting (ARC) documentation for initializer methods. Methods in the 'init' family now correctly steal a reference to `self` and return a new reference. This changed behavior for `[NSObject alloc]` proxies and can affect custom `init` implementations, potentially leading to crashes if old patterns are used.","severity":"breaking","affected_versions":">=11.1"},{"fix":"When subclassing Objective-C classes, implement Objective-C style `init` methods (e.g., `initWithFoo_:`). If overriding `__new__` in a Python subclass, ensure `__init__` is handled correctly, potentially using the pattern where `__init__` is only called if `__new__` returns an instance of the class itself. Update to 10.3.1 or later to mitigate this specific issue.","message":"Version 10.3 initially broke `__init__` usage for Python subclasses of Objective-C classes, particularly when a user implemented `__new__` or when relying on PyObjC's `__new__` behavior. This was partially reverted in 10.3.1 to reintroduce `__init__` support when a user implements `__new__`.","severity":"gotcha","affected_versions":"10.3.0"},{"fix":"Do not subclass `NSString` or `NSMutableString` in Python. If custom string behavior is needed, wrap an existing `NSString` or use Python's built-in string types.","message":"`NSString` and `NSMutableString` are marked as 'final' in PyObjC versions 11.1 and later. Attempting to subclass these in Python will result in crashes due to special handling within PyObjC.","severity":"gotcha","affected_versions":">=11.1"},{"fix":"Ensure Xcode or the Command Line Tools are installed via `xcode-select --install` before attempting installation, particularly if encountering compilation errors. Using an older SDK than the target macOS version can lead to build errors.","message":"Installing PyObjC (especially from source or if binary wheels aren't suitable) requires Xcode or the Command Line Tools to be installed on macOS, including a compatible SDK for the target macOS version.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Only use PyObjC and its framework wrappers in macOS environments. For cross-platform development, consider alternative libraries or platform-specific conditional logic.","message":"PyObjC is a macOS-specific library and does not function on other platforms like iOS, Linux, or Windows.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}