The Library Management System is a Python-based application that allows users to interact with a library's book inventory. The project integrates with Microsoft SQL Server to manage book records, transactions, and borrowing history. This system is designed for ease of use, modularity, and scalability.
- List Available Books: Displays all books currently available in the library.
- Borrow Books: Allows users to borrow a book from the library, updating the database.
- Return Books: Enables users to return a borrowed book, marking it as available again in the database.
- Error Handling: Robust error handling to manage database connection issues, invalid user inputs, and unexpected errors.
- Python: Core programming language.
- Microsoft SQL Server: Backend database to store and manage book data.
- pyodbc: Python library to connect and interact with the SQL database.
LibraryManagement/
│
├── main.py # Main script to run the application
├── database/
│ ├── setup.sql # SQL script to create and populate the database
├── lib/
│ ├── library.py # Library class to manage book operations
│ ├── student.py # Student class to handle user interactions
│ ├── db_connection.py # Database connection logic
│
├── README.md # Project documentation
├── requirements.txt # Python dependencies
└── .gitignore # Files and directories to be ignored by git
- Python 3.8 or later
- Microsoft SQL Server installed and configured
- Python library dependencies (listed in
requirements.txt)
- Open the SQL Server Management Studio.
- Run the
database/setup.sqlscript to create the database and tables, and populate initial data.
CREATE DATABASE LibraryDB;
USE LibraryDB;
CREATE TABLE Books (
BookID INT PRIMARY KEY IDENTITY(1,1),
Title NVARCHAR(100) NOT NULL,
IsAvailable BIT DEFAULT 1
);
CREATE TABLE Transactions (
TransactionID INT PRIMARY KEY IDENTITY(1,1),
BookID INT,
BorrowerName NVARCHAR(100),
BorrowDate DATETIME DEFAULT GETDATE(),
ReturnDate DATETIME,
FOREIGN KEY (BookID) REFERENCES Books(BookID)
);
INSERT INTO Books (Title) VALUES
('Algorithms'),
('Django'),
('Clrs'),
('Python Notes');Install required Python libraries:
pip install -r requirements.txtEdit lib/db_connection.py and replace YourServerName with your SQL Server instance name:
conn = pyodbc.connect('DRIVER={SQL Server};'
'SERVER=YourServerName;'
'DATABASE=LibraryDB;'
'Trusted_Connection=yes;')Run the application using:
python main.pyYou will see the following menu:
====== Welcome to Central Library ======
Please choose an option:
1. List all the books
2. Request a book
3. Add/Return a book
4. Exit the Library
- List Books: Choose option
1to display available books. - Borrow a Book: Choose option
2and enter the book name. - Return a Book: Choose option
3and enter the book name. - Exit: Choose option
4to exit the system.
- Database Connection Issues: Displays an error message if the connection to the database fails.
- Invalid Inputs: Handles incorrect menu choices and provides user-friendly feedback.
- Unexpected Errors: Catches and displays error details for debugging purposes.
- Add a web interface using Flask or Django.
- Implement user authentication and authorization.
- Include book search functionality.
- Add support for fine calculation for overdue books.
- Introduce logging to track system activities.
For any queries or contributions, please reach out at: [email protected]