{"id":5410,"library":"pyobjc-framework-security","title":"PyObjC Framework Security","description":"PyObjC is a bridge between Python and Objective-C, enabling Python scripts to use and extend existing Objective-C class libraries on macOS. The `pyobjc-framework-security` package provides Python wrappers for Apple's Security framework, allowing developers to access macOS security services like authentication, authorization, and secure data handling from Python. The current version is 12.1.","status":"active","version":"12.1","language":"python","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","objc","security","framework","apple"],"install":[{"cmd":"pip install pyobjc-framework-security","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Provides the core Python to Objective-C bridge functionality required by all PyObjC framework wrappers.","package":"pyobjc-core","optional":false}],"imports":[{"note":"The bindings for the Security framework are accessed directly through the 'Security' package name.","symbol":"Security","correct":"import Security"}],"quickstart":{"code":"import Security\nimport objc\n\ndef generate_random_bytes(length):\n    \"\"\"Generates cryptographically secure random bytes using Security.framework.\"\"\"\n    # SecRandomCopyBytes is a C function in the Security framework.\n    # We need to load it explicitly if not already exposed as a Python function.\n    # It's usually exposed automatically, but this demonstrates explicit loading for C functions.\n    # The 'b' format indicates a C array of bytes.\n    _functions = [\n        ('SecRandomCopyBytes', 'iI^v'), # OSStatus SecRandomCopyBytes(SecRandomGeneratorRef, size_t, void *)\n    ]\n\n    # Load the function from the Security framework bundle\n    # Security.bundle() is the NSBundle for the Security framework\n    # Use globals() to make the loaded function available directly\n    objc.loadBundleFunctions(Security.bundle(), globals(), _functions)\n\n    buffer = bytearray(length)\n    # kSecRandomDefault is typically passed as the first argument (generatorRef)\n    # Its value is usually 0 for the default generator, or None in PyObjC often works for NULL\n    # The correct value for kSecRandomDefault is implicitly handled by PyObjC for simple cases.\n    # If the function signature is 'iI^v', the 'I' is size_t (length), '^v' is void* (buffer).\n    # PyObjC often allows passing bytearray directly for buffer pointers.\n\n    # SecRandomCopyBytes(generator, count, bytes)\n    # We use 0 for kSecRandomDefault, and 'buffer' for the output bytes.\n    status = SecRandomCopyBytes(0, length, buffer)\n\n    if status == 0: # noErr\n        return bytes(buffer)\n    else:\n        raise RuntimeError(f\"Failed to generate random bytes: {status}\")\n\nif __name__ == \"__main__\":\n    try:\n        random_data = generate_random_bytes(16)\n        print(f\"Generated 16 random bytes: {random_data.hex()}\")\n    except Exception as e:\n        print(f\"Error: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to use `pyobjc-framework-security` to generate cryptographically secure random bytes using the `SecRandomCopyBytes` C function from the macOS Security framework. It showcases loading a C function and handling byte buffers."},"warnings":[{"fix":"Upgrade to Python 3.10 or later. PyObjC 12.1 requires Python >=3.10.","message":"Support for Python 3.9 was dropped in PyObjC version 12.0.","severity":"breaking","affected_versions":">=12.0"},{"fix":"Upgrade to Python 3.9 or later (preferably 3.10+ for current versions).","message":"Support for Python 3.8 was dropped in PyObjC version 11.0.","severity":"breaking","affected_versions":">=11.0"},{"fix":"Migrate away from `IMServicePlugIn` to modern macOS APIs, as the framework is no longer supported by Apple or PyObjC.","message":"The `IMServicePlugIn` framework bindings were removed in PyObjC 10.0 as the entire framework was deprecated in macOS 10.13 and removed in macOS 14.","severity":"breaking","affected_versions":">=10.0"},{"fix":"If implementing custom object creation, ensure `__new__` is handled carefully. Avoid using `__init__` if relying on PyObjC's default `__new__` implementation for Objective-C classes, or upgrade to 10.3.1+ if a user-defined `__new__` requires `__init__`.","message":"PyObjC 10.3 initially broke the ability to use `__init__` when a class defined `__new__`. While partially re-enabled in 10.3.1 for user-defined `__new__` methods, `__init__` cannot be used with `__new__` provided by PyObjC itself.","severity":"gotcha","affected_versions":"10.3 - 10.3.x"},{"fix":"Developers working with custom `init` methods in Objective-C classes wrapped by PyObjC should be aware of this change in reference counting behavior to prevent memory leaks or premature deallocation. Consult Apple's ARC documentation for details.","message":"PyObjC 11.1 aligned the core bridge's behavior with `clang's` documentation for Automatic Reference Counting (ARC) regarding initializer methods. Methods in the 'init' family now correctly steal a reference to `self` and return a new reference.","severity":"gotcha","affected_versions":">=11.1"},{"fix":"Consult the PyObjC API notes for the Security framework and Apple's documentation for modern alternatives. File an issue with PyObjC if a critical API is missing.","message":"Several legacy Security.framework APIs, such as `SecKeychainItemCopyAttributesAndData` and `SecIdentityCopyPreference`, are not available from Python as they are soft-deprecated or explicitly not exposed by PyObjC.","severity":"deprecated","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'12.1':63 'access':46 'allow':43 'appl':39,68 'authent':51 'author':52 'bridg':7 'c':13,24 'class':25 'current':60 'data':55 'develop':44 'enabl':14 'exist':21 'extend':20 'framework':2,32,42,67 'handl':56 'librari':26 'like':50 'maco':28,47,64 'objc':65 'object':12,23 'objective-c':11,22 'packag':34 'provid':35 'pyobjc':1,4,31 'pyobjc-framework-secur':30 'python':9,15,36,58 'script':16 'secur':3,33,41,48,54,66 'servic':49 'use':18 'version':61 'wrapper':37","created_at":"2026-04-14T01:32:39.982819+00:00","updated_at":"2026-04-16T19:31:25.580528+00:00","problems":{"verify_error":"× Failed to build `pyobjc-core==12.2.1`\n  ├─▶ The build backend returned an error\n  ╰─▶ Call to `setuptools.build_meta.build_wheel` failed (exit status: 1)\n\n      [stdout]\n      running egg_info\n\n      [stderr]\n      error: PyObjC requires macOS to build\n\n      hint: This usually indicates a problem"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"12.2.2","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/ronaldoussoren/pyobjc","docs":"https://pyobjc.readthedocs.io/en/latest/","changelog":null,"pypi":"https://pypi.org/project/pyobjc-framework-security/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["auth-security","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"failing","verified_at":"2026-06-28","last_verified":"2026-08-30","next_check":"2026-07-05","install_tag":null}}