PyObjC is a bridge between Python and Objective-C that allows full featured Cocoa applications to be written in pure Python.
—
Fundamental bridge functionality that provides the foundation for all Python-Objective-C interoperability. These functions handle class lookup, runtime access, memory management, and bridge configuration.
Core functions for working with Objective-C classes and managing the bridge runtime environment.
def lookUpClass(name: str):
"""
Look up an Objective-C class by name.
Args:
name (str): The name of the Objective-C class to find
Returns:
The Objective-C class object, or None if not found
"""
def getClassList():
"""
Get a list of all available Objective-C classes.
Returns:
list: List of all registered Objective-C classes
"""
def currentBundle():
"""
Get the current NSBundle object.
Returns:
NSBundle: The bundle object for the current application
"""
def loadBundle(path: str, module_globals: dict, bundle_identifier: str = None, scan_classes: bool = True):
"""
Load a framework bundle and make its classes available.
Args:
path (str): Path to the bundle to load
module_globals (dict): Global namespace to inject classes into
bundle_identifier (str, optional): Bundle identifier
scan_classes (bool): Whether to scan for classes in the bundle
Returns:
The loaded bundle object
"""
def pyobjc_id(obj):
"""
Get the Objective-C object ID for a bridged object.
Args:
obj: The object to get the ID for
Returns:
int: The object's unique identifier
"""
def repythonify(obj, strict: bool = True):
"""
Convert an Objective-C object to its Python representation.
Args:
obj: The Objective-C object to convert
strict (bool): Whether to use strict conversion rules
Returns:
The Python representation of the object
"""
options: object
"""
Bridge configuration options object.
Example:
objc.options.verbose = True # Enable verbose output
objc.options.verbose = False # Disable verbose output
"""Functions for managing Objective-C memory and autorelease pools.
def recycleAutoreleasePool():
"""
Manually recycle the current autorelease pool.
This is typically handled automatically, but can be called
manually for fine-grained memory management control.
"""
def removeAutoreleasePool():
"""
Remove the current autorelease pool.
Lower-level pool management function. Use with caution.
"""
def setAssociatedObject(obj, key, value, policy):
"""
Associate an object with another object using a key.
Args:
obj: The object to associate with
key: The key for the association
value: The value to associate
policy: The association policy (retain, copy, etc.)
"""
def getAssociatedObject(obj, key):
"""
Get an associated object using a key.
Args:
obj: The object to query
key: The key for the association
Returns:
The associated value, or None if not found
"""
def _objc_sync_enter(obj):
"""
Enter a synchronized block on an object.
Args:
obj: The object to synchronize on
"""
def _objc_sync_exit(obj):
"""
Exit a synchronized block on an object.
Args:
obj: The object to synchronize on
"""
class autorelease_pool:
"""
Context manager for Objective-C autorelease pools.
Usage:
with objc.autorelease_pool():
# Objective-C operations that create autoreleased objects
pass
"""
def __enter__(self): ...
def __exit__(self, exc_type, exc_val, exc_tb): ...Access to the Objective-C runtime system and core bridge objects.
runtime: object
"""
Access to the Objective-C runtime system.
Provides low-level runtime introspection capabilities.
"""
class NSObject:
"""
Base class for Objective-C objects in Python.
All Objective-C classes accessible from Python inherit from this class.
Provides basic object lifecycle and introspection methods.
"""Classes that wrap Objective-C methods and C functions for bridge usage.
class selector:
"""
Represents Objective-C method selectors.
Selectors identify methods in the Objective-C runtime and are used
for method dispatch and introspection.
"""
class objc_method:
"""
Wraps Objective-C method implementations.
Provides access to method metadata, signatures, and implementation
details for bridged Objective-C methods.
"""
class function:
"""
Wraps C functions for bridge usage.
Enables calling C functions from Python with proper type conversion
and argument handling.
"""
class IMP:
"""
Method implementation pointer wrapper.
Represents the actual implementation function of an Objective-C method,
allowing direct method invocation bypass.
"""
class super:
"""
Override for Python's super() in Objective-C context.
Provides proper super method calling semantics when working with
Objective-C class hierarchies from Python.
"""# Objective-C equivalents for common Python values
nil = None # Objective-C nil
YES = True # Objective-C YES
NO = False # Objective-C NOclass error(Exception):
"""Base exception class for PyObjC errors."""
class nosuchclass_error(Exception):
"""Exception raised when an Objective-C class cannot be found."""
class internal_error(Exception):
"""Exception raised for internal bridge errors."""Install with Tessl CLI
npx tessl i tessl/pypi-pyobjc