Wrappers for the Cocoa frameworks on macOS
npx @tessl/cli install tessl/pypi-pyobjc-framework-cocoa@10.3.0A comprehensive Python package providing Objective-C bindings for Apple's core Cocoa frameworks on macOS. This package enables Python developers to access native macOS APIs through CoreFoundation, Foundation, and AppKit frameworks, plus utility tools for application development.
pip install pyobjc-framework-Cocoapyobjc-core>=10.3.2Framework packages can be imported individually or together:
import Cocoa # Top-level access to AppKit functionality
import Foundation # Foundation framework classes and functions
import CoreFoundation # Core Foundation framework
import AppKit # AppKit GUI framework
import CGL # OpenGL framework bindingsUtility tools are imported separately:
from PyObjCTools import AppHelper # Application lifecycle utilities
from PyObjCTools import Conversion # Python/ObjC conversion utilities
from PyObjCTools import AppCategories # AppKit class enhancements (auto-applied)
from PyObjCTools import FndCategories # Foundation class enhancements (auto-applied)import Foundation
import AppKit
from PyObjCTools import AppHelper
# Create Foundation objects
string = Foundation.NSString.stringWithString_("Hello, macOS!")
array = Foundation.NSMutableArray.array()
array.addObject_(string)
# Work with AppKit for GUI applications
app = AppKit.NSApplication.sharedApplication()
window = AppKit.NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
Foundation.NSMakeRect(100, 100, 400, 300),
AppKit.NSWindowStyleMaskTitled | AppKit.NSWindowStyleMaskClosable,
AppKit.NSBackingStoreBuffered,
False
)
window.setTitle_("PyObjC Window")
window.makeKeyAndOrderFront_(None)
# Use PyObjCTools for event loop management
AppHelper.runEventLoop()The package provides a hierarchical framework structure:
The framework bindings use PyObjC's metadata-driven approach to provide access to thousands of Objective-C classes, methods, and constants without requiring explicit wrapper code for each API element.
Low-level C API framework providing fundamental data types, memory management, and system services that form the foundation of macOS development.
# Object creation functions
def CFArrayCreate(values): ...
def CFDictionaryCreate(keys, values): ...
def CFSetCreate(values): ...
def CFSTR(string): ...
# Localization functions
def CFCopyLocalizedString(key, comment): ...
def CFCopyLocalizedStringFromTable(key, table, comment): ...High-level Objective-C framework providing object-oriented wrappers around Core Foundation, including collections, strings, dates, and system services.
# Special constants and types
NSDecimal: type
YES: bool
NO: bool
NSNotFound: int
# Localization functions
def NSLocalizedString(key, comment): ...
def NSLocalizedStringFromTable(key, table, comment): ...
# Utility functions
def MIN(a, b): ...
def MAX(a, b): ...
def ABS(x): ...The Cocoa user interface framework providing windows, views, controls, and event handling for building native macOS applications.
# Utility functions
def NSDictionaryOfVariableBindings(*names): ...
# Global application instance
NSApp: object
# Character constants
NSEnterCharacter: str
NSBackspaceCharacter: str
NSTabCharacter: str
# ... and many more special charactersHigh-level utility functions and classes that simplify common PyObjC development tasks including application lifecycle management and data conversion.
# Application lifecycle (PyObjCTools.AppHelper)
def runEventLoop(): ...
def stopEventLoop(): ...
def callAfter(func, *args, **kwargs): ...
def callLater(delay, func, *args, **kwargs): ...
# Data conversion (PyObjCTools.Conversion)
def pythonCollectionFromPropertyList(collection): ...
def propertyListFromPythonCollection(collection): ...
def toPythonDecimal(decimal): ...
def fromPythonDecimal(decimal): ...Python-friendly enhancements to native Objective-C classes providing dictionary-like access, iteration support, and context managers.
# Foundation enhancements
NSCache.__getitem__(key): ...
NSCache.__setitem__(key, value): ...
NSIndexSet.__len__(): ...
NSIndexSet.__iter__(): ...
# AppKit enhancements
NSFontDescriptor.__getitem__(key): ...
NSFontDescriptor.get(key, default): ...
# Context managers
NSDisabledAutomaticTermination: type
NSDisabledSuddenTermination: typeThis package provides comprehensive access to:
The metadata-driven bindings provide access to thousands of Objective-C classes, methods, and constants, enabling development of native macOS applications and system integration tools in Python.