AddressBook Framework Bindings for PyObjC

12.1 · active · verified Tue Apr 14

pyobjc-framework-addressbook provides Pythonic wrappers for the macOS AddressBook framework, allowing Python applications to interact with contact data. It is part of the larger PyObjC project, which bridges Python and Objective-C. The current version is 12.1 and new releases generally align with macOS SDK updates and Python version support changes.

Warnings

Install

Imports

Quickstart

Fetches the default AddressBook instance and prints the name of the first person found, if any. Note that on modern macOS, this might trigger a privacy permission prompt.

from AddressBook import ABAddressBook, ABPerson

def get_first_person_name():
    try:
        # On modern macOS, you might need to grant permission to access contacts.
        # This code will likely prompt for permission the first time it's run.
        book = ABAddressBook.sharedAddressBook() #
        people = book.people() #

        if people.count() > 0:
            person = people[0] #
            display_name = person.displayName() #
            return display_name
        else:
            return "No contacts found."
    except Exception as e:
        return f"An error occurred: {e}"

if __name__ == '__main__':
    print(f"First contact's display name: {get_first_person_name()}")

view raw JSON →