{"library":"pyobjc-framework-multipeerconnectivity","title":"PyObjC Framework: MultipeerConnectivity","description":"The `pyobjc-framework-multipeerconnectivity` library provides Python bindings for Apple's Multipeer Connectivity framework on macOS, enabling Python applications to discover nearby devices and communicate via Wi-Fi, Peer-to-Peer Wi-Fi, and Bluetooth personal area networks. It is part of the larger PyObjC project, allowing Python developers to interact with Objective-C APIs directly. The current version is 12.1, and releases generally align with macOS SDK updates and Python version compatibility.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install pyobjc-framework-multipeerconnectivity"],"cli":null},"imports":["from MultipeerConnectivity import *","from Foundation import *","from PyObjCTools import AppHelper"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import objc\nfrom Foundation import *\nfrom MultipeerConnectivity import *\nfrom PyObjCTools import AppHelper\nimport sys\n\n# Define a service type (must be 1-15 lowercase ASCII characters, no hyphens, no underscores)\nSERVICE_TYPE = \"my-p2p-app\"\n\nclass BrowserDelegate(NSObject):\n    \"\"\"\n    Delegate for MCNearbyServiceBrowser to handle found and lost peers.\n    \"\"\"\n    def browser_foundPeer_withDiscoveryInfo_(self, browser, peerID, info):\n        print(f\"[Browser] Found peer: {peerID.displayName()} (Info: {info})\")\n        # In a real app, you'd now invite the peer to a session.\n\n    def browser_lostPeer_(self, browser, peerID):\n        print(f\"[Browser] Lost peer: {peerID.displayName()}\")\n\nclass AdvertiserDelegate(NSObject):\n    \"\"\"\n    Delegate for MCNearbyServiceAdvertiser to handle invitations.\n    \"\"\"\n    def advertiser_didReceiveInvitationFromPeer_withContext_invitationHandler_(self, advertiser, peerID, context, invitationHandler):\n        print(f\"[Advertiser] Received invitation from {peerID.displayName()} (Context: {context})\")\n        # For this simple example, we decline any invitations.\n        invitationHandler(False, None) \n\n# 1. Create a peer ID for this device\nmyPeerID = MCPeerID.alloc().initWithDisplayName_(NSHost.currentHost().name())\nprint(f\"Starting MultipeerConnectivity as: {myPeerID.displayName()}\")\n\n# 2. Setup a browser to find other peers\nbrowserDelegate = BrowserDelegate.alloc().init()\nbrowser = MCNearbyServiceBrowser.alloc().initWithPeer_serviceType_(myPeerID, SERVICE_TYPE)\nbrowser.setDelegate_(browserDelegate)\nbrowser.startBrowsingForPeers()\nprint(f\"Started browsing for peers using service type: '{SERVICE_TYPE}'\")\n\n# 3. Setup an advertiser to be discovered by other peers\nadvertiserDelegate = AdvertiserDelegate.alloc().init()\nadvertiser = MCNearbyServiceAdvertiser.alloc().initWithPeer_discoveryInfo_serviceType_(myPeerID, None, SERVICE_TYPE)\nadvertiser.setDelegate_(advertiserDelegate)\nadvertiser.startAdvertisingPeer()\nprint(f\"Started advertising using service type: '{SERVICE_TYPE}'\")\n\nprint(\"\\n--- Running event loop. Press Ctrl+C to stop. ---\")\ntry:\n    AppHelper.runConsoleEventLoop(installInterrupt=True)\nexcept KeyboardInterrupt:\n    print(\"\\nStopping...\")\nfinally:\n    browser.stopBrowsingForPeers()\n    advertiser.stopAdvertisingPeer()\n    print(\"Stopped browsing and advertising.\")\n    sys.exit(0)","lang":"python","description":"This example demonstrates how to set up `MCNearbyServiceBrowser` and `MCNearbyServiceAdvertiser` to discover and be discovered by other devices using Multipeer Connectivity. It defines Python classes to act as delegates for handling discovery events and runs a console event loop to process callbacks. This simplified example focuses on peer discovery rather than full session management or data transfer.","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-multipeerconnectivity","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-multipeerconnectivity","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-multipeerconnectivity","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-multipeerconnectivity","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":3,"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-multipeerconnectivity","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-multipeerconnectivity","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":2.8,"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-multipeerconnectivity","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-multipeerconnectivity","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":2.5,"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-multipeerconnectivity","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-multipeerconnectivity","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":3.6,"import_time_s":null,"mem_mb":null,"disk_size":null}]}}