Python-to-Objective-C bridge providing seamless interoperability between Python and Objective-C programming languages on macOS systems.
npx @tessl/cli install tessl/pypi-pyobjc-core@10.3.0A comprehensive Python-to-Objective-C bridge that provides seamless interoperability between Python and Objective-C programming languages on macOS systems. PyObjC-Core enables developers to use Objective-C objects and classes as first-class Python citizens, subclass Objective-C classes from Python, and access the complete macOS development stack including Foundation and AppKit frameworks.
pip install pyobjc-coreimport objcCommon imports for specific functionality:
# For utilities and testing
from PyObjCTools import TestSupport, KeyValueCoding
# Core classes and decorators
from objc import objc_method, python_method, IBOutlet, IBActionimport objc
# Use Objective-C constants
result = objc.YES # True
empty = objc.nil # None
# Create autorelease pool context
with objc.autorelease_pool():
# Work with Objective-C objects here
pass
# Create an Objective-C method decorator
class MyClass:
@objc_method
def my_objc_method(self):
return "Hello from Objective-C"
@python_method
def my_python_method(self):
return "Hello from Python"
# Use Key-Value Coding
from PyObjCTools.KeyValueCoding import getKey, setKey
obj = MyClass()
value = getKey(obj, "someAttribute")
setKey(obj, "someAttribute", "new value")PyObjC-Core provides a comprehensive bridge through several key components:
This architecture enables full bidirectional interoperability, allowing Python code to seamlessly interact with the entire macOS ecosystem while maintaining Python's dynamic programming model.
Essential bridge components including constants, context management, and fundamental interoperability features that enable Python-Objective-C integration.
# Constants
nil = None
YES = True
NO = False
# Context management
class autorelease_pool:
def __enter__(self): ...
def __exit__(self, exc_type, value, tp): ...Decorators for controlling how Python methods are exposed to the Objective-C runtime, including method signatures and selector customization.
def objc_method(value=None, *, selector=None, signature=None, isclass=None): ...
def python_method(value=None): ...
def namedSelector(name, signature=None): ...
def typedSelector(signature): ...Decorators and descriptors for creating Interface Builder-compatible outlets, actions, and properties for macOS app development.
def IBOutlet(name=None): ...
def IBAction(func): ...
def IBInspectable(prop): ...
def IB_DESIGNABLE(cls): ...Comprehensive property descriptor system for creating Key-Value Coding compliant accessors and synthesized properties.
def accessor(func, typeSignature=b"@"): ...
def typedAccessor(typeSignature): ...
def synthesize(name, copy=False, readwrite=True, type=_C_ID, ivarName=None): ...Support for Objective-C formal and informal protocols, enabling proper protocol conformance and method requirements.
def protocolNamed(name): ...
def informal_protocol(name): ...
class ProtocolError(Exception): ...Functions for registering Python types with the bridge system and comprehensive SIMD type support for high-performance operations.
def registerListType(type_object): ...
def registerMappingType(type_object): ...
def registerSetType(type_object): ...
def registerDateType(type_object): ...
# SIMD types
simd_float2, simd_float3, simd_float4: type
matrix_float2x2, matrix_float3x3, matrix_float4x4: typeUtilities for loading Objective-C frameworks and libraries dynamically, including BridgeSupport file parsing and lazy module loading.
def dyld_framework(filename, framework_name, version=None): ...
def dyld_library(filename, libname): ...
def pathForFramework(path): ...
def initFrameworkWrapper(...): ...Functions for adding convenience methods to Objective-C classes and registering Abstract Base Classes for better Python integration.
def addConvenienceForClass(classname, methods): ...
def registerABCForClass(classname, *abc_class): ...
def addConvenienceForBasicMapping(name, readonly=False): ...
def addConvenienceForBasicSequence(name, readonly=False): ...Essential utilities for Key-Value Coding, signal handling, and testing support for PyObjC development.
# Key-Value Coding
def getKey(obj, key): ...
def setKey(obj, key, value): ...
def getKeyPath(obj, keypath): ...
def setKeyPath(obj, keypath, value): ...
# Signal handling
def dumpStackOnFatalSignal(): ...
def resetFatalSignals(): ...# Exception types
class ProtocolError(Exception):
"""Exception for protocol-related errors."""
# Context manager
class autorelease_pool:
"""Context manager for NSAutoreleasePool management."""
def __init__(self): ...
def __enter__(self): ...
def __exit__(self, exc_type, value, tp): ...
# Lazy loading support
class ObjCLazyModule:
"""Lazy module loading for frameworks."""