PyObjC¶
PyObjC provides bindings to most Objective-C frameworks on macOS, build upon a generic bidirectional bridge between Python and Objective-C.
PyObjC aims to get as close as possible to having Python and a first class language for developing applications and scripts on macOS using Apple’s high level system APIs.
Cocoa class definition in Python¶
from Foundation import NSObject
from objc import super
class MyCocoaObject(NSObject):
def initWithX_y_(self, x, y):
self = super().init()
if self is None:
return None
self.x = x
self.y = y
return self
Cocoa class definition in Objective-C¶
#import <Foundation/Foundation.h>
@interfae MyCocoaObject : NSObject {
int x, y;
}
-(instancetype)initWithX:(int)x y:(int)y;
@end
@implementation MyCocoaObject
-(instancetype)initWithX:(int)xValue y:(int)yValue
{
self = [super init];
if (!self) return nil;
x = xValue;
y = yValue;
return self;
}
Release Info
PyObjC 11.0 was released on 2025-01-14. See the changelog for more information.
Supported Platforms
macOS 10.9 and later
Python 3.9 and later
x86_64 and arm64
Installing PyObjC
$ python3 -mpip \
install -U pyobjc