The Library Management System is a Command-Line Interface (CLI) application developed in Python to streamline the management of books, borrowers, and loan records for a small library. This project leverages SQLAlchemy ORM to handle database operations and ensures best practices in Python programming, including proper package structure, virtual environment setup, and use of Python collections such as lists, dictionaries, and tuples.
This project is part of a phase 3 assignment, focusing on practical implementation of CLI tools and database integration.
- Books Management
- Add new books with title, author, and number of copies.
- View a list of all books in the library.
- Delete books from the library.
- Borrowers Management
- Add new borrowers with name and email.
- View a list of all borrowers and their active loans.
- Delete borrowers (only if they have no active loans).
- Loans Management
- Borrow books by associating a borrower with a book.
- Return borrowed books, updating availability.
- Delete loans.
- Database Integrity
- Ensure relational integrity between books, borrowers, and loans.
- Automatically handle availability of books upon borrowing and returning.
The project is organized into a modular structure:
library_management/
├── cli.py # Main CLI interface for user interaction
├── database.py # Database setup and SQLAlchemy engine configuration
├── models.py # ORM models for Book, Borrower, and Loan
├── Pipfile # Pipenv configuration for dependencies
├── library.db # SQLite database (generated after first run)
└── README.md # Project documentation
- Python
- Core programming language for the application.
- SQLAlchemy ORM
- For database management and handling relationships between tables.
- SQLite
- Lightweight, file-based database for storage.
- Pipenv
- For dependency management and virtual environment.
- Python 3.8 or higher
- Pipenv (Install using
pip install pipenv)
-
Clone the repository:
git clone https://github.com/your-username/library-management-system.git cd library-management-system -
Install dependencies using Pipenv:
pipenv install
-
Activate the virtual environment:
pipenv shell
-
Run the application:
python main.py
Upon running the application, you will see a menu with the following options:
Library Management System
1. Add a Book
2. View Books
3. Add a Borrower
4. View Borrowers
5. Borrow a Book
6. Return a Book
7. Delete a Borrower
8. Delete a Book
9. Delete a Loan
10. Exit
- Select Option 1.
- Enter the book title, author, and number of copies when prompted.
- Select Option 5.
- Enter the borrower ID and book ID to create a loan.
- Select Option 6.
- Provide the loan ID to mark the book as returned.
- Select Option 4.
- See a list of all borrowers and their active loans.
The application uses a relational database with three tables:
-
Books
id(Primary Key)titleauthorcopies_available
-
Borrowers
id(Primary Key)nameemail
-
Loans
id(Primary Key)book_id(Foreign Key)borrower_id(Foreign Key)date_borroweddate_returned
- Modular Code: Separate files for CLI logic, models, and database configuration.
- SQLAlchemy ORM: Ensures easy database management with proper relationships.
- Virtual Environment: Dependencies isolated using Pipenv.
- Error Handling: Includes checks for invalid operations (e.g., deleting a borrower with active loans).
- Add user authentication for secure access.
- Introduce reporting features to view loan history over time.
- Add support for overdue book notifications.