UniformTypeIdentifiers Framework (PyObjC)

12.1 · active · verified Mon Apr 13

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.

Warnings

Install

Imports

Quickstart

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`.

import UniformTypeIdentifiers
from Foundation import NSURL # Foundation is often implicitly needed or useful

# Get a system-declared UTI for an image
image_type = UniformTypeIdentifiers.UTType.image
print(f"Image UTI Identifier: {image_type.identifier}")
print(f"Image UTI Preferred filename extension: {image_type.preferredFilenameExtension}")

# Check conformance
text_type = UniformTypeIdentifiers.UTType.text
is_text_conforming_to_data = text_type.conformsToType_(UniformTypeIdentifiers.UTType.data)
print(f"Does text UTI conform to data UTI? {is_text_conforming_to_data}")

# Get a UTI from a filename extension
pdf_type = UniformTypeIdentifiers.UTType.typeWithFilenameExtension_("pdf")
if pdf_type:
    print(f"PDF UTI Identifier: {pdf_type.identifier}")

view raw JSON →