{"id":6172,"library":"pyobjc-framework-sensitivecontentanalysis","title":"PyObjC framework SensitiveContentAnalysis","description":"PyObjC-framework-SensitiveContentAnalysis provides Python wrappers for Apple's macOS SensitiveContentAnalysis framework (macOS 14.0+). This framework enables apps to check images and videos for nudity, supporting features like Sensitive Content Warning and Communication Safety parental controls. The library is part of the larger PyObjC project, which acts as a bridge between Python and Objective-C, allowing Python applications to leverage macOS's native Cocoa APIs. Version 12.1 is the latest release, with regular updates aligning with macOS SDK changes and Python versions.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","objective-c","cocoa","apple","framework","content analysis","privacy","nude detection"],"install":[{"cmd":"pip install pyobjc-framework-sensitivecontentanalysis","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"This package provides the core Python-Objective-C bridge functionality, which is essential for all PyObjC framework wrappers.","package":"pyobjc-core","optional":false}],"imports":[{"note":"Main class for analyzing sensitive content in images and videos.","symbol":"SCSensitivityAnalyzer","correct":"from SensitiveContentAnalysis import SCSensitivityAnalyzer"},{"note":"Class representing the results of a content sensitivity check.","symbol":"SCSensitivityAnalysis","correct":"from SensitiveContentAnalysis import SCSensitivityAnalysis"}],"quickstart":{"code":"import SensitiveContentAnalysis\nimport objc\nfrom PyObjCTools import AppHelper\n\n# NOTE: For SensitiveContentAnalysis to return positive results,\n# your macOS application MUST be signed with the\n# 'com.apple.developer.sensitivecontentanalysis.client' entitlement.\n# This is typically added via Xcode capabilities, not Python code.\n# Without it, analysis might always return 'None' or errors like 'User Safety not enabled'.\n\n# Placeholder for a CGImage. In a real app, you'd load this\n# from a file (e.g., using Quartz.CGImageSourceCreateWithURL).\n# For a runnable example, we define a dummy function.\ndef create_dummy_cgimage():\n    # In a real application, you would load a CGImage from a file or buffer.\n    # This is a conceptual placeholder.\n    print(\"\\n--- Placeholder: Create a dummy CGImage ---\")\n    print(\"In a real app, load an image using e.g., Quartz.CGImageSourceCreateWithURL.\")\n    # A real CGImage object from a framework like Quartz would be passed here.\n    # For demonstration, we'll return None and assume external setup.\n    return None # Replace with an actual CGImage object\n\ndef analysis_completion_handler(result, error):\n    if error:\n        print(f\"Analysis Error: {error}\")\n        if 'User Safety either not entitled' in str(error):\n            print(\"HINT: Ensure your app has the 'com.apple.developer.sensitivecontentanalysis.client' entitlement.\")\n    elif result:\n        print(f\"Sensitive Content Analysis Result: {result.isSensitive()}\")\n        if result.isSensitive():\n            print(\"Intervention guidance:\", result.interventionPolicy())\n    else:\n        print(\"No result or error provided.\")\n    AppHelper.stopEventLoop()\n\ndef perform_analysis():\n    image = create_dummy_cgimage()\n    if image is None:\n        print(\"Cannot proceed without a real CGImage object. Please set up image loading.\")\n        return\n\n    analyzer = SensitiveContentAnalysis.SCSensitivityAnalyzer.alloc().init()\n    analyzer.analyzeCGImage_completionHandler_(image, analysis_completion_handler)\n\nif __name__ == '__main__':\n    print(\"Starting SensitiveContentAnalysis example...\")\n    # To run this in a context where the framework actually works,\n    # you'd typically embed it in a py2app created application bundle\n    # that has the necessary entitlements.\n    AppHelper.callAfter(perform_analysis)\n    AppHelper.runEventLoop()\n    print(\"SensitiveContentAnalysis example finished.\")","lang":"python","description":"This quickstart demonstrates how to initialize `SCSensitivityAnalyzer` and call its `analyzeCGImage_completionHandler_` method. It includes a critical warning about the required `com.apple.developer.sensitivecontentanalysis.client` entitlement, which is a common footgun and necessary for the framework to function correctly. Without this entitlement, the analysis will likely fail or return no sensitive results. Due to the nature of the framework, a real `CGImage` object is needed, which would typically be obtained via a graphics framework like `Quartz` (e.g., `Quartz.CGImageSourceCreateWithURL`). The example uses a placeholder for brevity."},"warnings":[{"fix":"Ensure your macOS application's `Info.plist` includes the `com.apple.developer.sensitivecontentanalysis.client` entitlement. Typically, this is managed by enabling the 'Sensitive Content Analysis' capability in Xcode.","message":"The SensitiveContentAnalysis framework requires a specific code-signing entitlement (`com.apple.developer.sensitivecontentanalysis.client`) for your macOS application bundle to return meaningful results. Without this entitlement, the framework may not detect sensitive content or may return errors indicating 'User Safety not enabled'. This entitlement must be added via Xcode capabilities, not programmatically in Python.","severity":"gotcha","affected_versions":"All versions (macOS 14.0+ requirement)"},{"fix":"Upgrade your Python environment to 3.10 or later for PyObjC 12.x, or to 3.9 or later for PyObjC 11.x. Always check `requires_python` in PyPI for specific version compatibility.","message":"PyObjC 12.0 dropped support for Python 3.9. Projects targeting older Python versions should use PyObjC 11.x or earlier. PyObjC 11.0 dropped support for Python 3.8.","severity":"breaking","affected_versions":"12.0+"},{"fix":"Review `init` method calls, particularly if manually managing object lifecycles or seeing unexpected crashes during object initialization. The more Pythonic `SomeClass(...)` constructor form (introduced in PyObjC 10.3) is generally safer than `SomeClass.alloc().init()`.","message":"PyObjC 11.1 introduced changes to how `init` family methods (constructors) handle object references, aligning with `clang`'s Automatic Reference Counting (ARC) documentation. This means `[NSObject alloc]` proxies now correctly model that `init` methods steal a reference to `self` and return a new one. Incorrect usage in previous versions, which might have accidentally worked, could now lead to crashes.","severity":"breaking","affected_versions":"11.1+"},{"fix":"If your Python classes subclass Objective-C classes and implement `__new__`, be aware of this interaction. If `__init__` is not being called as expected, consider restructuring your class or explicitly calling `__init__` where appropriate, or rely on the `SomeClass(...)` constructor style introduced in PyObjC 10.3 for a more consistent experience.","message":"There was a change in PyObjC 10.3 regarding `__init__` not being called when a user implements `__new__`. While PyObjC 10.3.1 partially reintroduced the ability to use `__init__` in such cases, code relying on the PyObjC-provided `__new__` still cannot use `__init__`.","severity":"gotcha","affected_versions":"10.3, 10.3.1+"},{"fix":"Avoid using `objc.selector.isAlloc` in your code. Replace with alternative checks if necessary, or update your code to rely on PyObjC's modern object handling.","message":"The `isAlloc` attribute of `objc.selector` is deprecated and will be removed in PyObjC 12. This attribute was related to internal reference counting mechanisms that are no longer used by the bridge.","severity":"deprecated","affected_versions":"10.0 - 11.x (removal in 12.0)"},{"fix":"If you have Python-defined subclasses of `NSProxy` that use KVO, you may need to refactor your code to avoid KVO on these specific classes or find alternative observation mechanisms.","message":"PyObjC 12.1 automatically disables Key-Value Observing (KVO) usage for subclasses of `NSProxy` defined in Python. If your application relies on KVO with such custom proxy classes, this change will prevent it from working as before.","severity":"breaking","affected_versions":"12.1+"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}