{"id":5412,"library":"pyobjc-framework-webkit","title":"PyObjC WebKit Framework Bindings","description":"PyObjC-framework-WebKit provides Python wrappers for Apple's WebKit and JavaScriptCore frameworks on macOS, enabling Python applications to embed web content and execute JavaScript. It is part of the larger PyObjC project, which acts as a bridge between Python and Objective-C. The library is actively maintained with regular updates to support new macOS SDKs and Python versions, typically following a release cadence aligned with major macOS and Python releases.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macOS","WebKit","JavaScriptCore","Objective-C","Cocoa","UI","browser","desktop"],"install":[{"cmd":"pip install pyobjc-framework-webkit","lang":"bash","label":"Install PyObjC WebKit bindings"}],"dependencies":[{"reason":"This package provides the core bridge between Python and Objective-C, essential for all PyObjC framework bindings. It is implicitly installed as a dependency.","package":"pyobjc-core"},{"reason":"While not a direct PyPI dependency, WebKit applications typically rely on AppKit (part of Cocoa) for UI elements like windows and application loops.","package":"pyobjc-framework-Cocoa","optional":true}],"imports":[{"note":"The WebKit framework bindings are accessed directly through the 'WebKit' package.","symbol":"WebKit","correct":"import WebKit"},{"note":"Most practical uses of WebKit will require AppKit for windowing and application management.","symbol":"AppKit","correct":"import AppKit"},{"note":"Foundation framework provides core data types and utilities, often used with WebKit for URLs and requests.","symbol":"Foundation","correct":"import Foundation"}],"quickstart":{"code":"import AppKit\nimport Foundation\nimport WebKit\n\nclass AppDelegate(AppKit.NSObject):\n    def applicationDidFinishLaunching_(self, notification):\n        rect = Foundation.NSMakeRect(0, 0, 800, 600)\n        self.window = AppKit.NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(\n            rect, AppKit.NSWindowStyleMaskTitled | AppKit.NSWindowStyleMaskClosable | AppKit.NSWindowStyleMaskResizable, AppKit.NSBackingStoreBuffered, False\n        )\n        self.window.setTitle_(\"PyObjC WebKit Demo\")\n\n        self.webView = WebKit.WKWebView.alloc().initWithFrame_(rect)\n        self.window.contentView().addSubview_(self.webView)\n\n        url = Foundation.NSURL.URLWithString_(\"https://www.apple.com/\" if not Foundation.NSBundle.mainBundle().bundleIdentifier() else \"https://www.google.com\")\n        request = Foundation.NSURLRequest.requestWithURL_(url)\n        self.webView.loadRequest_(request)\n\n        self.window.makeKeyAndOrderFront_(None)\n\n    def applicationShouldTerminateAfterLastWindowClosed_(self, sender):\n        return True\n\nif __name__ == \"__main__\":\n    app = AppKit.NSApplication.sharedApplication()\n    delegate = AppDelegate.alloc().init()\n    app.setDelegate_(delegate)\n    app.run()","lang":"python","description":"This minimal example demonstrates how to create a basic macOS application window using AppKit and embed a WKWebView to display a webpage. It defines an AppDelegate to manage the application lifecycle and sets up a window with a WKWebView loading a URL. To run this, save it as a .py file and execute it on macOS with PyObjC installed. Note that a full macOS application with an Info.plist and bundle identifier is typically created using tools like `py2app` for deployment, but this script provides a runnable demonstration within a standard Python environment. The URL is conditionally set to avoid issues when run from an unbundled script without a default bundle ID."},"warnings":[{"fix":"Upgrade to Python 3.10 or a newer supported version.","message":"PyObjC v12.0 dropped support for Python 3.9, and v11.0 dropped support for Python 3.8. Ensure your Python environment is 3.10 or newer for PyObjC 12.x.","severity":"breaking","affected_versions":"11.0+"},{"fix":"Upgrade to PyObjC 10.3.1 or newer. If implementing Objective-C style initializers, follow the `alloc().init...()` pattern or implement a custom `__new__` method in your Python class to allow `__init__` to be called.","message":"PyObjC v10.3 introduced a change where `__init__` methods in Python subclasses of Objective-C classes would not be called if a user-defined `__new__` was not present. This broke several projects. While partially reverted in v10.3.1 to allow `__init__` when a user *does* implement `__new__`, code relying on PyObjC's auto-generated `__new__` still cannot use `__init__` in the traditional Python sense.","severity":"breaking","affected_versions":"10.3 - 10.3.0"},{"fix":"Install Xcode Command Line Tools using `xcode-select --install` in your terminal.","message":"Building PyObjC (including framework bindings) from source requires Xcode Command Line Tools to be installed, which provides the necessary compilers and SDKs. Without them, installation via `pip install --no-binary :all: pyobjc-framework-webkit` will fail.","severity":"gotcha","affected_versions":"All versions (when installing from source)"},{"fix":"Uninstall any conflicting `AppKit` packages (e.g., `conda uninstall AppKit` or `pip uninstall AppKit`) and then reinstall PyObjC packages (`pip install --upgrade --force-reinstall pyobjc pyobjc-core`).","message":"Conflicting `AppKit` packages can cause `ImportError`. If you encounter 'No module named AppKit' after installing PyObjC, check if another non-PyObjC `AppKit` package is installed.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If you need string-like behavior, wrap `NSString` instances or use Python's built-in string types instead of subclassing directly.","message":"Due to the underlying Objective-C runtime, it's generally recommended to avoid subclassing `NSString` or `NSMutableString` in Python, as these classes have special handling in PyObjC and direct subclassing can lead to crashes.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}