{"id":6128,"library":"pyobjc-framework-linkpresentation","title":"PyObjC LinkPresentation Framework","description":"PyObjC is a bridge between Python and Objective-C, enabling Python scripts to interact with macOS Cocoa frameworks. This specific package, `pyobjc-framework-linkpresentation`, provides Python wrappers for Apple's LinkPresentation framework on macOS, allowing developers to fetch and present rich link previews from URLs. It is actively maintained with regular releases, currently at version 12.1.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macOS","Objective-C","Cocoa","UI","LinkPresentation","Apple"],"install":[{"cmd":"pip install pyobjc-framework-linkpresentation","lang":"bash","label":"Install framework bindings"}],"dependencies":[{"reason":"Fundamental bridge between Python and Objective-C; required by all PyObjC framework bindings.","package":"pyobjc-core"},{"reason":"Provides core macOS classes like NSURL, frequently used when interacting with LinkPresentation objects.","package":"pyobjc-framework-Foundation","optional":true}],"imports":[{"note":"Framework classes, functions, and constants are exposed directly under the framework's package name.","symbol":"LinkPresentation","correct":"import LinkPresentation"}],"quickstart":{"code":"import LinkPresentation\nimport Foundation\nimport objc\nimport threading\n\n# Use a threading.Event to signal when the metadata fetching is complete\ndone_fetching = threading.Event()\nmetadata_result = None\nerror_result = None\n\ndef completion_handler(metadata, error):\n    global metadata_result, error_result\n    metadata_result = metadata\n    error_result = error\n    done_fetching.set() # Signal that fetching is done\n\n@objc.python_block\ndef py_completion_handler(metadata, error):\n    completion_handler(metadata, error)\n\ndef fetch_link_metadata(url_string):\n    global metadata_result, error_result\n    metadata_result = None\n    error_result = None\n    done_fetching.clear()\n\n    url = Foundation.NSURL.URLWithString_(url_string)\n    if not url:\n        print(f\"Invalid URL: {url_string}\")\n        return\n\n    provider = LinkPresentation.LPMetadataProvider.alloc().init()\n    provider.startFetchingMetadataForURL_completionHandler_(url, py_completion_handler)\n\n    # Wait for the completion handler to be called\n    print(f\"Fetching metadata for {url_string}...\")\n    if not done_fetching.wait(timeout=10): # Wait up to 10 seconds\n        print(\"Fetching timed out.\")\n        return\n\n    if error_result:\n        print(f\"Error fetching metadata: {error_result}\")\n    elif metadata_result:\n        print(\"Metadata fetched successfully:\")\n        print(f\"  Title: {metadata_result.title()}\")\n        print(f\"  URL: {metadata_result.URL()}\")\n    else:\n        print(\"No metadata or error received.\")\n\nif __name__ == \"__main__\":\n    # Fetch metadata for a remote URL\n    test_url = os.environ.get('TEST_URL', 'https://www.apple.com')\n    fetch_link_metadata(test_url)\n    \n    # Create and inspect custom metadata\n    print(\"\\nCreating custom metadata:\")\n    custom_metadata = LinkPresentation.LPLinkMetadata.alloc().init()\n    custom_metadata.setOriginalURL_(Foundation.NSURL.URLWithString_(\"https://example.com/custom\"))\n    custom_metadata.setURL_(Foundation.NSURL.URLWithString_(\"https://example.com/custom\"))\n    custom_metadata.setTitle_(\"My Custom Link Title\")\n    print(f\"  Title: {custom_metadata.title()}\")\n    print(f\"  URL: {custom_metadata.URL()}\")","lang":"python","description":"This quickstart demonstrates how to fetch rich link metadata from a URL using `LPMetadataProvider` and how to create custom `LPLinkMetadata` objects. It includes a mechanism to handle the asynchronous nature of `startFetchingMetadataForURL_completionHandler_` using a `threading.Event` to wait for the Objective-C callback."},"warnings":[{"fix":"Upgrade to Python 3.10 or newer, or pin `pyobjc` to `<12.0`.","message":"PyObjC v12.0 dropped support for Python 3.9. Projects targeting older Python versions must use an older PyObjC release (e.g., v11.x for Python 3.9).","severity":"breaking","affected_versions":">=12.0"},{"fix":"Upgrade to Python 3.9 or newer, or pin `pyobjc` to `<11.0`.","message":"PyObjC v11.0 dropped support for Python 3.8. Projects targeting Python 3.8 must use an older PyObjC release (e.g., v10.x).","severity":"breaking","affected_versions":">=11.0"},{"fix":"Review Python subclass implementations, especially for custom `__new__` methods. Ensure compatibility with `__init__` expectations based on your PyObjC version.","message":"The behavior of `__init__` and `__new__` for Python subclasses of Objective-C classes changed in v10.3 and was partially reverted in v10.3.1. If you implement `__new__` in a Python subclass, you must ensure `__init__` is callable, which was broken in 10.3. If using PyObjC's provided `__new__`, `__init__` is still not supported.","severity":"gotcha","affected_versions":"10.3, 10.3.1"},{"fix":"Review code interacting with Objective-C initializer methods to ensure correct reference counting, especially in manual memory management scenarios or when bridging complex ownership patterns.","message":"PyObjC v11.1 aligned its reference counting for initializer methods (e.g., `init` family) with clang's Automatic Reference Counting (ARC) documentation. Methods in the 'init' family now correctly steal a reference to `self` and return a new reference, which might change behavior if your code relied on previous PyObjC reference counting semantics.","severity":"breaking","affected_versions":">=11.1"},{"fix":"Update applications to use modern macOS communication APIs, as `IMServicePlugIn` is no longer available on recent macOS versions or in PyObjC.","message":"The `IMServicePlugIn` framework bindings were removed in PyObjC v10.0, as the framework itself was deprecated in macOS 10.13 and removed in macOS 14.","severity":"deprecated","affected_versions":">=10.0"},{"fix":"Exercise caution when using PyObjC in a free-threaded Python 3.13+ environment. Monitor for unexpected behavior related to concurrency and reference handling.","message":"PyObjC v11.0 introduced experimental support for free-threading (PEP 703) with Python 3.13. While this is a significant feature, it's experimental and might not be stable for all use cases, requiring careful testing in multi-threaded environments.","severity":"gotcha","affected_versions":">=11.0 (with Python 3.13+)"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}