PyObjC Framework Symbols

12.1 · active · verified Tue Apr 14

The `pyobjc-framework-symbols` package provides Python bindings for Apple's `Symbols` framework on macOS, enabling interaction with SF Symbols. It is part of the larger PyObjC project, currently at version 12.1, with a release cadence tied to macOS SDK updates and Python version support cycles.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to access the `SFSymbolsLibrary` and create an `SFSymbolConfiguration` object using the `pyobjc-framework-symbols` bindings. This functionality is generally available on macOS 11.0 and newer.

import objc
from Symbols import SFSymbolsLibrary, SFSymbolConfiguration

# Ensure PyObjC runtime is initialized (often implicit with framework imports)
# if not objc.isInitialized():
#    objc.initFrameworkWrapper("Foundation")

try:
    # Get the shared library of SF Symbols
    shared_library = SFSymbolsLibrary.sharedLibrary()

    if shared_library:
        print("Successfully accessed SFSymbolsLibrary.")
        
        # List a few symbol names
        all_symbol_names = shared_library.allSymbolNames()
        if all_symbol_names:
            print(f"Found {len(all_symbol_names)} SF Symbols.")
            print(f"First 5 symbols: {list(all_symbol_names)[:5]}")

            # Example: Create a symbol configuration (requires macOS 11.0+ typically)
            config = SFSymbolConfiguration.configurationWithPointSize_weight_scale_(
                24,  # Point size
                3,   # SFSymbolWeightSemibold (use integer for simplicity in quickstart)
                2    # SFSymbolScaleMedium (use integer for simplicity in quickstart)
            )
            print(f"Created SFSymbolConfiguration: {config}")
        else:
            print("No symbol names found in library.")
    else:
        print("SFSymbolsLibrary.sharedLibrary() returned None.")
except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure you are running on macOS 11.0+ and PyObjC is correctly installed.")

view raw JSON →