PyObjC DeviceDiscoveryExtension
PyObjC is a bridge between Python and Objective-C, enabling Python scripts to use and extend existing Objective-C class libraries, most notably Apple's Cocoa frameworks on macOS. This specific package provides Python wrappers for the DeviceDiscoveryExtension framework. It is currently at version 12.1 and is actively maintained as part of the broader PyObjC project, which typically sees releases monthly or bi-monthly, with framework updates following macOS SDK releases.
Warnings
- breaking Python 3.9 support was dropped in PyObjC 12.0. Projects using PyObjC 12.0 or later (including `pyobjc-framework-devicediscoveryextension` 12.x) must use Python 3.10 or newer.
- breaking Python 3.8 support was dropped in PyObjC 11.0. Projects using PyObjC 11.0 or later must use Python 3.9 or newer.
- breaking PyObjC 11.1 introduced significant changes to how automatic reference counting (ARC) is modeled, specifically for Objective-C initializer methods (those in the 'init' family). This aligns PyObjC with `clang`'s documentation, where these methods now 'steal' a reference to `self` and return a new one. Code relying on previous reference counting behavior for initializers may break.
- gotcha PyObjC framework wrappers are tightly coupled to macOS SDK versions. The `DeviceDiscoveryExtension` framework itself was introduced in macOS 15. Using a `pyobjc-framework-devicediscoveryextension` version compiled with a newer SDK on an older macOS version (especially below macOS 15) can lead to runtime errors due to missing symbols or API incompatibility.
- gotcha PyObjC 10.3 changed the interaction between user-defined `__init__` and `__new__` methods in Python subclasses of Objective-C classes. While 10.3.1 partially reverted this, if PyObjC provides the `__new__` implementation (e.g., for default object creation), a user-defined `__init__` *still cannot be used* without carefully understanding PyObjC's two-phase instantiation model.
Install
-
pip install pyobjc-framework-devicediscoveryextension
Imports
- DeviceDiscoveryExtension
import DeviceDiscoveryExtension
Quickstart
import Foundation
# PyObjC allows you to interact with macOS frameworks.
# This example uses Foundation, a core Cocoa framework.
# For DeviceDiscoveryExtension, the import pattern is similar.
# Most Cocoa objects use a two-phase initialization: allocation followed by initialization.
my_object = Foundation.NSObject.alloc().init()
print(f"Successfully created a Foundation.NSObject: {my_object}")
print(f"Class name of the object: {my_object.className()}")
# To use DeviceDiscoveryExtension, you would follow a similar pattern:
# import DeviceDiscoveryExtension
# from DeviceDiscoveryExtension import DDEDiscoverySession
# session = DDEDiscoverySession.alloc().init() # Example for a potential class within the framework
# print(f"DeviceDiscoveryExtension session created (conceptual): {session}")