PyObjC Framework Symbols
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
- breaking PyObjC frequently drops support for older Python versions. Version 12.0 dropped support for Python 3.9, and version 11.0 dropped Python 3.8. Always check the release notes for Python compatibility.
- breaking In PyObjC 11.1, the core bridge's behavior for initializer methods changed to align with `clang`'s documentation for Automatic Reference Counting (ARC). Methods in the 'init' family now correctly steal a reference to `self` and return a new reference, which can affect custom object initialization logic.
- gotcha PyObjC framework bindings are tightly coupled to macOS SDK versions. Running code built with a newer SDK on an older macOS version, or attempting to use features not present in the runtime OS, can lead to runtime errors (e.g., missing symbols, unexpected behavior).
- gotcha PyObjC 10.3 introduced a change that prevented calling `__init__` when a user-implemented `__new__` was present, leading to breakage. This was partially reverted in 10.3.1 to reintroduce `__init__` support when `__new__` is user-defined, but code relying on PyObjC's default `__new__` still cannot use `__init__`.
- deprecated Specific framework bindings can be removed in major versions. For example, `IMServicePlugIn` bindings were entirely removed in PyObjC 10.0 because the framework itself was deprecated and removed in macOS.
Install
-
pip install pyobjc-framework-symbols
Imports
- SFSymbolsLibrary
from Symbols import SFSymbolsLibrary
- SFSymbolConfiguration
from Symbols import SFSymbolConfiguration
Quickstart
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.")