A comprehensive Python-based Library Management System that enables efficient management of books, magazines, and DVDs. The system supports user registration, item borrowing/returning, reservations, and persistent data storage through JSON files.
- 📖 Multi-format Support: Manage Books, Magazines, and DVDs
- 👥 User Management: Register and manage library users
- 🔍 Smart Search: Search items by title or type keywords
- 📋 Borrowing System: Complete borrow and return functionality
- 🔖 Reservation System: Reserve items that support reservations
- 💾 Data Persistence: Automatic save/load using JSON files
⚠️ Error Handling: Comprehensive exception handling- 🖥️ CLI Interface: User-friendly command-line interface
library-management-system/
│
├── models/
│ ├── book.py # Book class (LibraryItem + Reservable)
│ ├── dvd.py # DVD class (LibraryItem + Reservable)
│ ├── magazine.py # Magazine class (LibraryItem only)
│ ├── library.py # Core Library management class
│ ├── user.py # User class definition
│ └── reservable.py # Abstract Reservable interface
│
├── exceptions/
│ ├── item_exceptions.py # Item-related exceptions
│ ├── user_exceptions.py # User-related exceptions
│ └── reservation_exception.py # Reservation exceptions
│
├── data/
│ ├── items.json # Persistent item storage
│ └── users.json # Persistent user storage
│
├── main.py # Application entry point
└── README.md # Project documentation
- Python 3.7 or higher
- No external dependencies required (uses only standard library)
-
Clone the repository
git clone <repository-url> cd library-management-system
-
Create data directory (if not exists)
mkdir -p data
-
Run the application
python main.py
Launch the application and you'll see the main menu:
Welcome to the Library System
1. View all items
2. Search items
3. Register new user
4. Add new item
5. Borrow item
6. Reserve item
7. Return item
8. Delete item
9. Delete user
10. Save and exit
- Select option
3 - Enter user details when prompted
- User will be assigned a unique ID
- Select option
4 - Choose item type (Book/Magazine/DVD)
- Enter item details
- Item will be added to the library
- Borrow: Select option
5, provide user ID and item ID - Return: Select option
7, provide user ID and item ID
- Select option
6 - Provide user ID and item ID
- Only Books and DVDs support reservations
Use option 2 to search for items:
- Search by title: Enter partial or full title
- Search by type: Enter "book", "magazine", or "dvd"
- Data is automatically loaded on startup
- All changes are saved when selecting "Save and exit"
- JSON files store all user and item information
data/items.json: Contains all library itemsdata/users.json: Contains all registered users
The system includes comprehensive error handling:
| Exception | Description |
|---|---|
UserNotFoundError |
User ID doesn't exist |
ItemNotFoundError |
Item ID doesn't exist |
ItemNotAvailableError |
Item is already borrowed |
ReservationError |
Reservation conflicts or unsupported items |
LibraryItem (Abstract Base)
├── Book (+ Reservable)
├── Magazine
└── DVD (+ Reservable)
Reservable (Abstract Interface)
├── Book
└── DVD
- Library: Central management class
- User: Handles user information and borrowed items
- LibraryItem: Base class for all library items
- Reservable: Interface for items that can be reserved
- Create new class inheriting from
LibraryItem - Implement required abstract methods
- Add
Reservableinterface if needed - Update the main menu logic
The modular design allows easy extension:
- Add new item types
- Implement additional search filters
- Add user roles and permissions
- Integrate with external databases
# Example of programmatic usage
from models.library import Library
from models.user import User
from models.book import Book
# Create library instance
library = Library()
# Add a user
user = User("123","John Doe", "john@email.com")
library.add_user(user)
# Add a book
book = Book("123456789","Python Programming", "Jane Smith", "Programming")
library.add_item(book)
# Borrow the book
library.borrow_item(user.user_id, book.item_id)Developer: Rand Haymouni
Email: randhaymouni@gmail.com