or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

appkit.mdcore-foundation.mdenhanced-classes.mdfoundation.mdindex.mdpyobjctools.md
tile.json

tessl/pypi-pyobjc-framework-cocoa

Wrappers for the Cocoa frameworks on macOS

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

To install, run

npx @tessl/cli install tessl/pypi-pyobjc-framework-cocoa@10.3.0

index.mddocs/

PyObjC Framework Cocoa

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

Package Information

  • Package Name: pyobjc-framework-Cocoa
  • Language: Python
  • Installation: pip install pyobjc-framework-Cocoa
  • Dependencies: pyobjc-core>=10.3.2

Core Imports

Framework 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 bindings

Utility 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)

Basic Usage

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

Architecture

The package provides a hierarchical framework structure:

  • Framework Bindings: Direct Python access to Apple's Objective-C frameworks through dynamic attribute resolution
  • Enhanced Classes: Python-friendly convenience methods added to native Objective-C classes
  • Utility Tools: Higher-level helper functions for common application development tasks
  • Type System: Complete bridging between Python and Objective-C types with automatic conversion

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.

Capabilities

Core Foundation Framework

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

Core Foundation

Foundation Framework

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

Foundation Framework

AppKit Framework

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 characters

AppKit Framework

PyObjCTools Utilities

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

PyObjCTools Utilities

Enhanced Classes

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

Enhanced Classes

Framework Coverage

This package provides comprehensive access to:

  • CoreFoundation: 3,451+ lines of metadata covering fundamental C APIs
  • Foundation: 12,192+ lines of metadata covering Objective-C foundation classes
  • AppKit: 20,739+ lines of metadata covering user interface framework
  • OpenGL: Basic bindings for OpenGL framework through CGL
  • PyObjCTools: 25+ utility functions across 4 modules

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.