{"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.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install pyobjc-framework-security"],"cli":null},"imports":["import Security"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":null,"pypi_latest":"12.1","is_stale":null,"summary":{"python_range":"3.10–3.9","success_rate":0,"avg_install_s":null,"avg_import_s":null,"wheel_type":null},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pyobjc-framework-security","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pyobjc-framework-security","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":2.9,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pyobjc-framework-security","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pyobjc-framework-security","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":2.9,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pyobjc-framework-security","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pyobjc-framework-security","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":2.9,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pyobjc-framework-security","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pyobjc-framework-security","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":2.6,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pyobjc-framework-security","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pyobjc-framework-security","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":3.4,"import_time_s":null,"mem_mb":null,"disk_size":null}]}}