Accessing Contacts:
#Copyright (c) 2008 Pankaj Nathani
#Getting the number and email address of a certain contact
import contacts
#Open the contacts database
c=contacts.open()
#Find the contact by name
person=c.find("Eric")[0]
#Get the number
no=person.find('mobile_number')[0].value #The first number only
print "Number: "+str(no)
#And the email address
eaddress=person.find('email_address')[0].value
print "Email: "+str(eaddress)
Adding - Deleting Contact entries:
#Copyright (c) 2008 Pankaj Nathani
#Adding and deleting contacts
import contacts
#Open the contacts database
c=contacts.open()
#Add new contact's details
n=c.add_contact()
n.add_field('first_name', 'Angelina')
n.add_field('mobile_number', '0123456789')
#And save the changes
n.commit()
#Now we delete it:
#Get its ID
d=c.find('Angelina')[0]
id=d.id
#Delete it
c.__delitem__(id)