PyObjC CoreWLAN Framework Bindings for macOS
The `pyobjc-framework-corewlan` package provides Python bindings for Apple's CoreWLAN framework on macOS. It allows Python applications to interact with Wi-Fi interfaces, retrieve network information, and manage wireless connections. It is part of the larger PyObjC project, which bridges Python and Objective-C, enabling Python developers to leverage macOS Cocoa frameworks directly. The current version is 12.1, with a regular release cadence aligned with macOS SDK updates and Python version support.
Warnings
- breaking PyObjC v12.0 and later dropped support for Python 3.9. Attempting to use these versions with Python 3.9 will result in installation or runtime errors.
- breaking PyObjC v11.0 and later dropped support for Python 3.8. Similar to Python 3.9, this will cause compatibility issues.
- breaking PyObjC v11.1 introduced changes to align reference counting behavior for Objective-C 'init' family methods with `clang`'s automatic reference counting (ARC) documentation. This means `init` methods now correctly model stealing a reference to `self` and returning a new one.
- gotcha The interaction between Python's `__init__` and `__new__` methods for PyObjC subclasses was altered in v10.3, partially reverted in v10.3.1. While `__init__` can now be used with user-implemented `__new__`, it still cannot be used with PyObjC's provided `__new__`.
- breaking The 'IMServicePlugIn' framework bindings were removed in PyObjC v10.0 because the framework itself was deprecated in macOS 10.13 and removed in macOS 14.
- gotcha Accessing privacy-relevant CoreWLAN information or performing actions (like changing Wi-Fi power) in macOS requires the application binary to be properly signed, not just an ad-hoc signature.
Install
-
pip install pyobjc-framework-CoreWLAN
Imports
- CoreWLAN
import CoreWLAN
Quickstart
import CoreWLAN
def get_wifi_info():
try:
# Get the default wireless interface
interface = CoreWLAN.CWInterface.interface()
if interface:
print(f"Current Wi-Fi interface Hardware Address: {interface.hardwareAddress()}")
print(f"Current Wi-Fi Power Status: {'On' if interface.powerOn() else 'Off'}")
current_ssid = interface.ssid()
if current_ssid:
print(f"Currently connected to network: {current_ssid}")
else:
print("Not currently connected to a Wi-Fi network.")
# List available Wi-Fi networks
print("\nAvailable Wi-Fi Networks:")
for network in CoreWLAN.CWInterface.interface().cachedScanResults():
print(f" - SSID: {network.ssid()}, RSSI: {network.rssiValue()} dBm")
else:
print("No Wi-Fi interface found.")
except Exception as e:
print(f"An error occurred: {e}")
print("Note: Accessing CoreWLAN functionality, especially for modifications, often requires a properly signed application or elevated privileges on macOS.")
if __name__ == "__main__":
get_wifi_info()