Skip to content

Contacts

Contacts

Contacts(auth: GoogleAuth)

High-level Google Contacts client (People API).

Example

auth = GoogleAuth(scopes=Scopes.contacts()) auth.authenticate()

contacts = Contacts(auth)

for contact in contacts.search("ana"): print(contact.display_name, contact.email)

contact = contacts.create(given_name="Ana", emails=["ana@example.com"]) contacts.update(contact.id, phones=["+54 11 5555-5555"])

service property

service: Any

Lazy-load People API service.

iter_contacts

iter_contacts(max_results: int | None = None, sort_order: SortOrder | None = None) -> Iterator[Contact]

Iterate over the user's contacts, following pagination.

list_contacts

list_contacts(max_results: int | None = None, **kwargs: Any) -> list[Contact]

The user's contacts (see iter_contacts).

search

search(query: str, max_results: int = 10) -> list[Contact]

Contacts whose names, emails, phones or organizations start with query.

The People API serves searches from a cache that a first, empty query warms up; without it the first results can be stale or empty. The client sends that warm-up once.

get

get(contact_id: str) -> Contact | None

A contact by ID ("c123" or "people/c123"), or None if it doesn't exist.

create

create(given_name: str | None = None, family_name: str | None = None, emails: list[str] | None = None, phones: list[str] | None = None, organization: str | None = None, job_title: str | None = None, notes: str | None = None) -> Contact

Create a contact. Needs at least a name, an email or a phone.

update

update(contact_id: str, given_name: str | None = None, family_name: str | None = None, emails: list[str] | None = None, phones: list[str] | None = None, organization: str | None = None, job_title: str | None = None, notes: str | None = None) -> Contact

Change fields of a contact; fields left as None are kept.

emails and phones replace the whole list ([] clears it). Changing the given name keeps the family name and vice versa, and the same for organization and job title.

Raises:

Type Description
NotFoundError

The contact doesn't exist.

delete

delete(contact_id: str) -> bool

Delete a contact. False if it didn't exist.

Contact dataclass

Contact(resource_name: str, etag: str | None = None, display_name: str | None = None, given_name: str | None = None, family_name: str | None = None, emails: list[str] = list(), phones: list[str] = list(), organization: str | None = None, job_title: str | None = None, notes: str | None = None, raw: dict[str, Any] = dict())

A contact of the user (a People API Person in the "myContacts" group).

Only the primary value of single-valued fields is kept; emails and phones keep every value, primary first. raw has the full resource.

id property

id: str

The ID without the "people/" prefix.

email property

email: str | None

Primary email.

phone property

phone: str | None

Primary phone number.