This project is a simple Library Management System written in Python. It allows you to manage books using classes, objects, and JSON file storage. You can add, remove, find, count, filter, and sort books.
- Add a book with title, author, and year.
- Remove a book by title.
- Find a book by title.
- Show all books in the library.
- Count books in the library.
- Filter books by author or year.
- Sort books by title or year.
- Persistent storage using JSON file (
data.json).
/project
│
├─ main.py # Main program
├─ library.py # Classes for Book and Library
├─ commands.py # Functions for user commands
├─ json_storage.py # Functions to handle JSON storage
├─ data.json # JSON file storing book data
- Make sure you have Python 3 installed.
- Run the main program:
python main.py- Use the following commands:
add - add a new book
show - show all books
find - find a book by title
remove - remove a book by title
count - count books in the library
filter - filter books by author or year
sort - sort books by title or year
help - show help menu
exit - exit the program
Enter command: add
Enter title: Dune
Enter author: Frank Herbert
Enter year: 1965
Book added successfully!
Enter command: show
Library collection:
1984 — George Orwell (1949)
The Master and Margarita — Mikhail Bulgakov (1967)
Dune — Frank Herbert (1965)
Enter command: find
Enter book title: Dune
Found: Dune — Frank Herbert (1965)
Enter command: remove
Enter book title: Dune
Book 'Dune' has been removed.
Enter command: filter
Which filter you want: by author name of author(write 'author') or year of book(write 'year')?author
Enter author name: George Orwell
Filtered books:
1984 — George Orwell (1949)
Enter command: sort
Which sort you want: 'title' or 'year'?year
1984 — George Orwell (1949)
The Master and Margarita — Mikhail Bulgakov (1967)
[
{
"title": "1984",
"author": "George Orwell",
"year": 1949
},
{
"title": "The Master and Margarita",
"author": "Mikhail Bulgakov",
"year": 1967
},
{
"title": "Dune",
"author": "Frank Herbert",
"year": 1965
}
]- Uses OOP (Object-Oriented Programming) principles: classes, objects, methods.
- Commands are handled via functions in
commands.py. - JSON module is used for persistent storage.
- All books remain in the list and JSON file; nothing is removed from memory unless using the remove command.
- Proper error handling is implemented for missing books or invalid filters.
Bohdan Borsuk