PyObjC ThreadNetwork Framework
pyobjc-framework-threadnetwork provides Python wrappers for the macOS ThreadNetwork framework, enabling Python scripts to interact with Apple's Thread networking APIs. As part of the larger PyObjC project, it acts as a bridge between Python and Objective-C, allowing full-featured Cocoa applications to be written in pure Python. The library is actively maintained, with version 12.1 released on 2025-11-14, following a regular release cadence.
Warnings
- breaking PyObjC releases frequently drop support for older Python versions. Version 12.0 dropped Python 3.9, and version 11.0 dropped Python 3.8. Users should ensure their Python environment is compatible with the installed PyObjC version.
- breaking PyObjC 11.1 introduced a significant change in how Automatic Reference Counting (ARC) is handled for Objective-C initializer methods. The core bridge now correctly models that methods in the 'init' family steal a reference to self and return a new one, which might alter behavior for code relying on the prior 'partially initialized' proxy state for `[NSObject alloc]` results.
- gotcha There was a temporary breakage in PyObjC 10.3 regarding the interaction between Python's `__init__` and `__new__` methods when subclassing Objective-C classes. While `__init__` usage was re-introduced in 10.3.1 for classes with user-implemented `__new__`, code relying on PyObjC's default `__new__` still cannot use `__init__` in specific scenarios. This reflects the inherent complexity of integrating Python's object model with Objective-C's two-phase instantiation.
- gotcha Building PyObjC from source, or using features dependent on specific macOS SDKs, requires a compatible Xcode or Command Line Tools installation. Using an older SDK than intended by the PyObjC version can lead to build errors.
- gotcha While PyObjC 11.0 introduced experimental support for PEP 703 (free-threading) in Python 3.13, earlier versions like PyObjC 10.3 did not support it. Developers should be mindful of this when targeting free-threaded Python environments.
Install
-
pip install pyobjc-framework-threadnetwork
Imports
- ThreadNetwork
import ThreadNetwork
Quickstart
import ThreadNetwork
import Foundation
# The ThreadNetwork framework often requires specific macOS APIs and hardware
# to perform meaningful operations. This quickstart demonstrates importing
# the framework and a basic PyObjC interaction with NSObject from Foundation
# to illustrate the bridge's functionality.
# Instantiate a generic Objective-C NSObject using PyObjC's Pythonic syntax (since PyObjC 10.4)
# For older PyObjC versions or explicit Objective-C style:
# obj = Foundation.NSObject.alloc().init()
obj = Foundation.NSObject.new()
print(f"Successfully imported ThreadNetwork and created an NSObject: {obj.description()}")
print(f"Is obj an instance of NSObject? {isinstance(obj, Foundation.NSObject)}")