PyObjC Framework: LibXPC
PyObjC-framework-libxpc provides Python bindings for the macOS XPC framework, allowing Python applications to interact with XPC services. It is part of the larger PyObjC project, currently at version 12.1, and follows a release cadence tied to macOS SDK updates and Python version support.
Warnings
- breaking PyObjC major versions frequently drop support for older Python versions. PyObjC 12.x dropped Python 3.9 support, and PyObjC 11.x dropped Python 3.8 support. Always check `requires_python`.
- gotcha Behavioral changes related to `__init__` and `__new__` in Python subclasses of Objective-C classes can cause unexpected initialization issues. PyObjC 10.3 prevented calling `__init__` in some scenarios, which was partially reverted in 10.3.1.
- gotcha PyObjC 11.1 introduced changes to how initializer methods are handled to align with Objective-C's Automatic Reference Counting (ARC) model. This ensures correct memory management but might subtly change behavior if existing code relied on previous reference counting semantics.
- deprecated Older frameworks or parts of frameworks may be removed entirely when macOS drops support for them. For example, PyObjC 10.0 removed `IMServicePlugIn` bindings as the framework was deprecated in macOS 10.13 and removed in macOS 14.
Install
-
pip install pyobjc-framework-libxpc
Imports
- libxpc
import libxpc
Quickstart
import libxpc
import objc
def main():
print(f"Accessing XPC framework symbols: {libxpc.xpc_main.__name__}")
print(f"XPC types available: {libxpc.xpc_type_connection.__name__}")
# Note: A full XPC client/server requires more setup beyond a quickstart.
# This example only verifies the framework import and symbol access.
# Example of a common PyObjC utility function, not directly libxpc but relevant.
class MyDelegate(objc.lookUpClass('NSObject')):
pass
print(f"Successfully looked up NSObject: {MyDelegate.__name__}")
if __name__ == '__main__':
main()