library management
library management
under my supervision. She has taken interest and has shown at most sincerity completion of
this project.
I certify this Project up to my expectation and as per guidelines issued by CBSE, NEW
DELHI.
Principal
S. NO. CONTENT PAGE NO.
1. Acknowledgement 1
Introduction 2
2.
3. 4
Requirements
5
4. Code
5. 13
Output
6. Conclusion 35
33
36
7. Bibliography
It is with pleasure that I acknowledge my sincere gratitude to our teacher R. Saravana Priya
M.C.A., B.Ed., who taught and undertook the responsibility of teaching the subject
I am especially indebted to our Principal R. Saravana Priya M.C.A., B.Ed., who has always
been a source of encouragement and support without whose inspiration this project would not
have been successful. I would like to place on record heartful thanks to her.
Finally, I would like to express my sincere appreciation for all the other students of my
batch, for their co-operation and the fine times that we all shared together.
1
INTRODUCTION
The Library Management System is an automated software solution designed to manage the
operations of a library, including adding new books, issuing and returning books, and tracking
the availability of books. The system also allows viewing of all available books and the books
currently issued to users. It utilizes a MySQL database for storing and managing book and
transaction data.
The program interacts with the database to store book details and manage transactions such as
issuing and returning books, ensuring that book availability is updated in real time.
OBJECTIVE:
To automate the library management system, reducing manual work.
To store and manage books’ data such as title, author, genre, and availability status.
To manage transactions by issuing and returning books, keeping track of students who
borrow the books and the dates.
To provide a user-friendly interface for librarians to add, issue, and delete books, as
well as track issued books.
SYNOPSIS:
1. Database Setup: The system connects to a MySQL database to store information about
books and transactions.
2. Book Management: Books can be added to the database with a title, author, genre, and
availability status.
3. Transaction Management: The system tracks book issuance and returns, linking each
transaction to the books issued.
4. User Interface: A simple text-based menu-driven interface allows users to choose
operations like adding books, viewing books, issuing books, etc.
5. Error Handling: The system checks for invalid inputs, ensuring that users enter the correct
data (e.g., valid dates).
2
FUTURE ENHANCEMENT/SCOPE:
1. Web Interface: Implement a web interface using frameworks like Flask or Django for
broader accessibility.
2. User Authentication: Add authentication for librarians and students to track user activity
more effectively.
3. Search and Filter: Introduce advanced search and filter options to help find books more
easily.
4. Late Fee Management: Implement a feature to calculate and manage late fees for returned
books.
5. Notifications: Send email notifications for due dates and overdue books.
3
HARDWARE USED:
A hard drive with adequate storage to run the program and store the database.
SOFTWARE USED:
LIBRARIES USED:
4
CODE
import mysql.connector
from datetime import datetime
5
CREATE TABLE IF NOT EXISTS transactions (
transaction_id VARCHAR(10) PRIMARY KEY,
book_id INT,
student_name VARCHAR(100),
issue_date DATE,
return_date DATE,
FOREIGN KEY (book_id) REFERENCES books(book_id)
)
""")
db.close()
6
# Add a new book
def add_book():
db = connect_to_db()
cursor = db.cursor()
book_id = get_next_id("books", "book_id")
title = input("Enter Book Title: ")
author = input("Enter Author: ")
genre = input("Enter Genre: ")
cursor.execute("INSERT INTO books (book_id, title, author, genre,
available) VALUES (%s, %s, %s, %s, TRUE)",
(book_id, title, author, genre))
db.commit()
print("Book added successfully.")
db.close()
# Issue a book
def issue_book():
db = connect_to_db()
cursor = db.cursor()
transaction_id = get_next_id("transactions", "transaction_id")
book_id = int(input("Enter Book ID to issue: "))
student_name = input("Enter Student Name: ")
7
print("Invalid date format. Please enter the date in YYYY-MM-DD
format.")
issue_date = input("Enter Issue Date (YYYY-MM-DD): ")
if result is None:
print("Invalid Book ID.")
elif result[0]:
cursor.execute("INSERT INTO transactions (transaction_id, book_id,
student_name, issue_date) VALUES (%s, %s, %s, %s)",
(transaction_id, book_id, student_name, issue_date))
cursor.execute("UPDATE books SET available = FALSE WHERE book_id
= %s", (book_id,))
db.commit()
print("Book issued successfully.")
else:
print("Book is not available.")
db.close()
# Return a book
def return_book():
db = connect_to_db()
cursor = db.cursor()
transaction_id = int(input("Enter Transaction ID to return: "))
cursor.execute("SELECT book_id FROM transactions WHERE
transaction_id = %s", (transaction_id,))
8
result = cursor.fetchone()
if result:
book_id = result[0]
else:
print("Invalid Transaction ID.")
db.close()
9
records = cursor.fetchall()
print(f"{'ID':^5} {'Title':^30} {'Author':^20} {'Genre':^10}
{'Available':^10}")
for record in records:
available = "Yes" if record[4] else "No"
print(f"{record[0]:^5} {record[1]:^30} {record[2]:^20} {record[3]:^10}
{available:^10}")
db.close()
10
# Delete a book
def delete_book():
db = connect_to_db()
cursor = db.cursor()
book_id = int(input("Enter Book ID to delete: "))
cursor.execute("DELETE FROM books WHERE book_id = %s", (book_id,))
db.commit()
print("Book deleted successfully.")
db.close()
# Main menu
def main():
initialize_db()
while True:
print("\n--- Library Management System ---")
print("1. Add Book")
print("2. Issue Book")
print("3. Return Book")
print("4. View All Books")
print("5. View Issued Books")
print("6. Delete Book")
print("7. Exit")
11
issue_book()
elif choice == 3:
return_book()
elif choice == 4:
view_books()
elif choice == 5:
view_issued_books()
elif choice == 6:
delete_book()
elif choice == 7:
print("Exiting...")
break
else:
print("Invalid choice. Try again.")
12
OUTPUT
TABLE STRUCTURE
BOOKS TABLE:
13
TRANSACTIONS TABLE:
14
1. ADD BOOK:
15
16
17
18
19
20
21
22
23
24
2. ISSUE BOOK:
25
26
27
28
3. RETURN BOOK:
29
30
31
4.VIEW ALL BOOKS:
32
5.VIEW ISSUED BOOKS:
6. DELETE BOOK:
33
34
CONCLUSION
The Library Management System effectively automates essential library
functions, such as adding books, issuing, returning, and deleting them, as well
as tracking transactions. By using MySQL for database management and
Python for application logic, the system ensures that the library operations are
carried out efficiently and accurately. The text-based interface provides an easy
way for users to interact with the system, while the database structure maintains
a well-organized record of books and transactions. This system not only reduces
the manual workload but also enhances the accuracy and accessibility of library
management, making it a valuable tool for both administrators and users.
35
BIBLIOGRAPHY
36