PyObjC NetFS Framework
PyObjC-framework-NetFS provides Python wrappers for the NetFS framework on macOS, enabling Python scripts to interact with macOS's network file system APIs. It is part of the larger PyObjC project, which bridges Python and Objective-C to facilitate macOS application development. The library is actively maintained, with version 12.1 currently available, and releases often align with macOS SDK updates.
Warnings
- breaking Python 3.9 support was dropped with PyObjC 12.0. Python 3.8 support was dropped with PyObjC 11.0. Ensure your Python environment is 3.10 or newer.
- breaking PyObjC 11.1 introduced significant changes in how it models Objective-C initializer methods (methods in the 'init' family) to align with `clang`'s Automatic Reference Counting (ARC) documentation. These methods now correctly steal a reference to `self` and return a new one.
- gotcha PyObjC 10.3 temporarily broke the ability to use `__init__` in Python classes that subclass Objective-C classes (when `__new__` was not user-implemented). While 10.3.1 partially restored this for classes with user-implemented `__new__`, code relying on PyObjC's provided `__new__` still cannot use `__init__` for initialization.
- gotcha PyObjC frequently updates its framework bindings for new macOS SDK versions. Building PyObjC from source or with specific extensions using an older SDK than the target macOS or the PyObjC release was built against can lead to compilation and runtime errors.
- gotcha Subclassing Cocoa string classes (e.g., NSString) directly in Python with PyObjC is not supported and will result in crashes due to special handling of these types within the bridge.
- gotcha While PyObjC 11.0 introduced experimental support for free-threading (PEP 703) with Python 3.13, this is an advanced feature and earlier versions (e.g., 10.3) explicitly stated lack of support. Users experimenting with free-threading should be aware of potential instabilities or limitations.
Install
-
pip install pyobjc-framework-netfs
Imports
- NetFS
import NetFS
Quickstart
import NetFS
from Foundation import NSObject
# The NetFS framework provides APIs for managing network file system mounts.
# To use specific classes, refer to Apple's NetFS documentation.
# For example, checking for a common class:
if hasattr(NetFS, 'NetFSMountSession'):
print('NetFSMountSession class is available.')
else:
print('NetFSMountSession class not found.')
# This example just demonstrates loading the framework and checking for a symbol.
# Real-world usage would involve creating instances and calling methods.
# For example, to instantiate a dummy NSObject (part of Foundation, often used with Cocoa):
obj = NSObject.alloc().init()
print(f'Created an NSObject: {obj}')