or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

bridge-registration.mdclass-enhancement.mdcore-bridge.mdframework-loading.mdindex.mdinterface-builder.mdmethod-decorators.mdproperties-accessors.mdprotocol-support.mdpyobjctools.md
tile.json

tessl/pypi-pyobjc-core

Python-to-Objective-C bridge providing seamless interoperability between Python and Objective-C programming languages on macOS systems.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pyobjc-core@10.3.x

To install, run

npx @tessl/cli install tessl/pypi-pyobjc-core@10.3.0

index.mddocs/

PyObjC-Core

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

Package Information

  • Package Name: pyobjc-core
  • Language: Python
  • Installation: pip install pyobjc-core
  • Requires: Python 3.8+, macOS

Core Imports

import objc

Common 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, IBAction

Basic Usage

import 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")

Architecture

PyObjC-Core provides a comprehensive bridge through several key components:

  • Core Bridge: C extension module providing runtime integration
  • Method System: Decorators and descriptors for method binding and Interface Builder integration
  • Type System: Support for Objective-C types, SIMD vectors, and struct types
  • Framework Loading: Dynamic loading and bridge support for Objective-C frameworks
  • Convenience Layer: Enhanced functionality for common Objective-C classes like NSArray, NSDictionary

This architecture enables full bidirectional interoperability, allowing Python code to seamlessly interact with the entire macOS ecosystem while maintaining Python's dynamic programming model.

Capabilities

Core Bridge Functionality

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): ...

Core Bridge

Method and Class Decorators

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): ...

Method Decorators

Interface Builder Integration

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): ...

Interface Builder

Property and Accessor System

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): ...

Properties and Accessors

Protocol Support

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): ...

Protocol Support

Bridge Registration and Type System

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: type

Bridge Registration

Framework and Dynamic Loading

Utilities 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(...): ...

Framework Loading

Convenience Functions and Class Enhancement

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): ...

Class Enhancement

PyObjCTools Utilities

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(): ...

PyObjCTools

Types

# 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."""