{"id":6072,"library":"pyobjc-framework-avkit","title":"PyObjC AVKit Framework","description":"PyObjC is a bridge between Python and Objective-C, enabling Python scripts to use and extend macOS Cocoa libraries. `pyobjc-framework-avkit` provides Python wrappers for Apple's AVKit framework on macOS, allowing developers to integrate video playback and related UI elements into Python applications. It is part of the larger PyObjC project, which is actively maintained with frequent updates to support new macOS SDKs and Python versions. The current version is 12.1.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","cocoa","avkit","video","gui","apple"],"install":[{"cmd":"pip install pyobjc-framework-avkit","lang":"bash","label":"Install specific AVKit wrapper"},{"cmd":"pip install pyobjc","lang":"bash","label":"Install all PyObjC frameworks (including AVKit)"}],"dependencies":[{"reason":"Provides the core bridge between Python and Objective-C, required by all PyObjC framework wrappers.","package":"pyobjc-core"}],"imports":[{"symbol":"AVPlayer","correct":"from AVKit import AVPlayer"},{"symbol":"AVPlayerViewController","correct":"from AVKit import AVPlayerViewController"},{"note":"Commonly used for application lifecycle management alongside AVKit.","symbol":"NSApplication","correct":"from AppKit import NSApplication"},{"note":"Commonly used for specifying media URLs, part of the Foundation framework.","symbol":"NSURL","correct":"from Foundation import NSURL"}],"quickstart":{"code":"import objc\nfrom Foundation import NSURL\nfrom AppKit import NSApplication, NSWindow, NSView, NSNotificationCenter, NSApplicationDidFinishLaunchingNotification, NSObject, NSRect\nfrom AVKit import AVPlayer, AVPlayerViewController\n\nclass AppDelegate(NSObject):\n    def applicationDidFinishLaunching_(self, notification):\n        print(\"Application finished launching.\")\n        self.mainWindow = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(\n            NSRect(100, 100, 640, 480),\n            4|8|16|1, # Titled | Closable | Miniaturizable | Resizable\n            2, # Backing store buffered\n            False # Not deferred\n        )\n        self.mainWindow.setTitle_(\"PyObjC AVKit Demo\")\n\n        # Create an AVPlayer with a sample video URL\n        video_url = NSURL.URLWithString_(\"https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4\")\n        self.player = AVPlayer.playerWithURL_(video_url)\n\n        # Create an AVPlayerViewController\n        self.playerViewController = AVPlayerViewController.alloc().init()\n        self.playerViewController.setPlayer_(self.player)\n\n        # Add the player view controller's view to the window's content view\n        playerView = self.playerViewController.view()\n        playerView.setFrame_(self.mainWindow.contentView().bounds())\n        playerView.setAutoresizingMask_(NSView.ViewWidthSizable | NSView.ViewHeightSizable)\n        self.mainWindow.contentView().addSubview_(playerView)\n\n        self.mainWindow.makeKeyAndOrderFront_(self)\n        self.player.play()\n\ndef main():\n    app = NSApplication.sharedApplication()\n    delegate = AppDelegate.alloc().init()\n    app.setDelegate_(delegate)\n    NSApplication.sharedApplication().run()\n\nif __name__ == '__main__':\n    main()","lang":"python","description":"This example demonstrates how to create a basic macOS application using PyObjC that displays and plays a video using AVKit. It sets up an `NSApplication` with an `NSWindow` and embeds an `AVPlayerViewController` to play a video from a URL. Remember that Objective-C method calls are translated to Python by replacing colons with underscores and appending an underscore for each argument."},"warnings":[{"fix":"Upgrade to Python 3.10 or later, or use PyObjC <12.0.","message":"PyObjC 12.0 dropped support for Python 3.9. Ensure your Python version is 3.10 or newer.","severity":"breaking","affected_versions":">=12.0"},{"fix":"Upgrade to Python 3.9 or later, or use PyObjC <11.0.","message":"PyObjC 11.0 dropped support for Python 3.8. Ensure your Python version is 3.9 or newer.","severity":"breaking","affected_versions":">=11.0, <12.0"},{"fix":"Review custom Objective-C initializers and Python subclasses that override `init` methods to ensure correct reference handling based on ARC rules.","message":"PyObjC 11.1 aligned initializer method behavior with `clang`'s documentation for automatic reference counting. Methods in the 'init' family now correctly steal a reference to `self` and return a new reference, which might change behavior for custom initializers or subclasses.","severity":"gotcha","affected_versions":">=11.1"},{"fix":"Avoid using `__init__` in conjunction with PyObjC-provided `__new__` for Objective-C subclasses. For user-defined `__new__`, verify `__init__` behavior with 10.3.1+.","message":"When subclassing Objective-C classes in Python and implementing both `__new__` and `__init__`, PyObjC 10.3 initially broke the ability to use `__init__`. While partially re-enabled in 10.3.1 for user-defined `__new__`, code relying on PyObjC's provided `__new__` still cannot use `__init__`.","severity":"gotcha","affected_versions":">=10.3, <10.3.1 (full impact); >=10.3.1 (partial impact)"},{"fix":"Ensure development and deployment environment is macOS.","message":"PyObjC is a macOS-specific library and will not run on other operating systems.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult Objective-C documentation and apply the colon-to-underscore translation when calling methods from Python.","message":"Objective-C method names containing colons (`:`) are translated to Python with underscores (`_`) replacing colons, and an additional trailing underscore for each argument. E.g., `method:arg1 withOtherArgs:arg2` becomes `method_withOtherArgs_(arg1, arg2)`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z","problems":[]}