Simple terminal-based phonebook application implemented in Python. It provides basic CRUD operations (Create, Read, Update, Delete) and stores contacts in a JSON file (phonebook.json) in the project directory.
- Add a contact (name, phone, email)
- View all contacts with index numbers
- Update a contact by name
- Delete a contact by name
- Stores contacts in
phonebook.jsonusing a list of objects
- Python 3.7+ (only standard library is required:
os,json)
- Open a PowerShell prompt in the project folder (where
phonebook.pyis located). - Run the program:
python .\phonebook.pyNotes: If your system uses python3 for the Python 3 interpreter, use python3 .\phonebook.py instead.
When you run phonebook.py it will display a simple menu:
- 0 — View contacts: prints all saved contacts from
phonebook.json. - 1 — Add contact: prompts for Name, Phone, Email and saves the contact.
- 2 — Update contact: prompts for the contact Name to find, then asks for new Name/Phone/Email.
- 3 — Delete contact: prompts for the contact Name to delete.
- 4 — Quit: exit the menu loop.
After each action you'll be asked whether to continue (y/n).
Validation: phone numbers are validated to contain only digits. If the phone is invalid when saving/updating, you'll be prompted to edit it; otherwise the contact will not be saved.
Contacts are stored in the file phonebook.json as a JSON array. Each contact is an object with the keys:
[
{
"name": "Alice",
"phone": "1234567890",
"email": "alice@example.com"
}
]If phonebook.json doesn't exist yet it will be created automatically when you add the first contact.
- Add a contact: choose
1, then enterKwabena,0541234567,kwabena@example.com. - View contacts: choose
0. - Update: choose
2, enter the name of the contact to update, then provide new fields. - Delete: choose
3, enter the name of the contact to remove.
- Searching for a contact to update/delete uses a simple membership check (it looks for the entered string among the contact object's values). This may match partial values or multiple contacts with the same name.
- There is no advanced duplicate-detection or sophisticated search; consider adding exact-match or ID-based operations for larger datasets.
To modify the program, edit phonebook.py. The project is a single-file, small learning project using OOP for the PhoneBook class.
Suggested improvements you can implement:
- Add unit tests and a small CLI argument parser to support non-interactive operations.
- Use a unique ID for contacts to avoid ambiguous updates/deletes.
- Improve validation for emails and phone numbers (international formats).
- Pretty-printing and sorting of the contact list.
Kwabena Amoako Embedded Systems | Hardware & Firmware | Robotics
Social: LinkedIn