PyObjC provides Python bindings for Apple's macOS frameworks, allowing Python applications to interact with native macOS APIs. `pyobjc-framework-corebluetooth` specifically offers wrappers for the CoreBluetooth framework, enabling Python programs to communicate with Bluetooth Low Energy (BLE) devices. The current version is 12.1, and PyObjC typically releases new versions in sync with macOS SDK updates and Python version support changes.
pip install pyobjc-framework-corebluetoothVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes a `CBCentralManager` and uses a Python class as its delegate. It demonstrates how to create a PyObjC-compatible delegate and receive the `centralManagerDidUpdateState_` callback, which is essential for any CoreBluetooth interaction. For full asynchronous operation and to handle ongoing events, a dedicated Cocoa event loop (e.g., using `PyObjCTools.AppHelper.runConsoleEventLoop()` from `pyobjc-tools`) is required.
Upgrade to a supported Python version (>=3.10 for PyObjC 12.x) or use an older PyObjC version compatible with your Python environment.
Ensure your development and deployment environment is macOS. Consider platform-agnostic libraries like `bleak` for cross-platform BLE development, or use `platform.system() == 'Darwin'` for conditional execution.
Review custom Python `init` methods in classes that bridge to Objective-C to ensure they correctly handle object retention and release, especially when overriding `NSObject`'s `init` or similar methods. Consult PyObjC's documentation on memory management.
If encountering issues with `__init__` not being called or unexpected object instantiation behavior in bridged classes, ensure your `__new__` and `__init__` implementations conform to PyObjC's current guidelines. For many cases, `init()` (Objective-C style) should be used instead of `__init__`.
Use `PyObjCTools.AppHelper.runConsoleEventLoop()` from the `pyobjc-tools` package to keep the application's event loop active and process Objective-C callbacks. This is essential for most interactive PyObjC console applications.