Libsys Proj Xii 2024-25-1
Libsys Proj Xii 2024-25-1
Libsys Proj Xii 2024-25-1
New Delhi
&
Project File
Project Title: Library Management System
For the partial fulfillment of AISSCE Examination for the Academic Session: 2024-25
SUBMITTED BY
Name :
Class : XII
Stream : SCIENCE
Roll No. :
ID SHEET
Roll No. :
Page |2
CERTIFICATE
of Class XII Science of Techno India Group Public School, Siliguri has done his project titled on Library
The student has taken a keen interest and has shown utmost sincerity in completing the project.
I certify that this project is up to my expectation and as per the guidelines issued by Central Board
PRINCIPAL
Page |3
ACKNOWLEDGEMENT
It is with pleasure that I acknowledge my sincere gratitude to our teacher, Mr. Bikramadittya
Bagchi, PGT (Computer Science) who taught and undertook responsibility for teaching the subject
I am especially indebted to our Principal Dr. Nandita Nandi who has always been a source of
encouragement and support and without whose inspiration this project would not have been
Finally, I would like to express my sincere appreciation for all the other students for my batch their
Signature
Page |4
CONTENTS
ID SHEET................................................................................................................................................................................. 2
Certificate ............................................................................................................................................................................... 3
Acknowledgement ............................................................................................................................................................. 4
Hardware ........................................................................................................................................................................... 6
Software ............................................................................................................................................................................. 6
Introduction .......................................................................................................................................................................... 7
Library ..................................................................................................................................................................................... 8
Purpose .............................................................................................................................................................................. 9
Usage .................................................................................................................................................................................. 9
Code ..................................................................................................................................................................................... 11
Output.................................................................................................................................................................................. 20
Database ......................................................................................................................................................................... 24
Bibliography....................................................................................................................................................................... 26
Page |5
HARDWARE AND SOFTWARE REQUIREMENTS
Hardware
1. Desktop Computer/Laptop
2. Mobile Phone
Software
1. Python (Latest Version)
a. MySQL-Connector-Python
b. Pandas
2. MySQL
Page |6
INTRODUCTION
The project LIBRARY MANAGEMENT SYSTEM (DIGITAL LIBRARY) includes enrolment of users,
adding books into the library system. It includes an authentication facility for admin and users to log
in into the admin panel and the user panel resp. of the system. Users can see the books available,
details of books issued by the user in the digital library. The Library Management System can login
using a user ID and password. It is accessible either by an admin or user. Only the admin can add,
delete and update the data of users and books into the database. The data can be retrieved easily.
The interface is very user-friendly. The data is well protected for personal use and processes
the data very fast.
The purpose of the project entitled as “DIGITAL LIBRARY” is to computerize the Front Library
Management to develop software, which is user friendly, simple, fast, and cost- effective. It also has
a notes facility where the user can add notes at any point of the program into the database.
Page |7
LIBRARY
A library is a collection of books, and possibly other materials and media, that is accessible for use
by its members and members of allied institutions. Libraries provide physical or digital materials,
and maybe a physical location, a virtual space, or both. A library's collection normally includes
printed materials which may be borrowed, and usually also includes a reference section of
Libraries can vary widely in size and may be organized and maintained by a public body such as a
addition to providing materials, libraries also provide the services of librarians who are trained
experts in finding, selecting, circulating and organizing information while interpreting information
needs and navigating and analyzing large amounts of information with a variety of resources.
Page |8
LIBRARY MANAGEMENT SYSTEM
Digital Library
Library Management System (LMS), is an enterprise resource planning system for a library, used
to track enrolled users, available books, books issued and to whom, books returned and its fines,
etc.
Purpose
The purpose of a library management system is to operate a library efficiently and at reduced costs.
The system, being entirely automated, streamlines all the tasks involved in operations of the library.
Usage
The library management system helps with reducing operational costs. Managing a library manually
is labor intensive and an immense amount of paperwork is involved. The system saves time for both
the user and the librarian. With just a click the user can search for books available in the library. The
librarian can answer queries with ease regarding the availability of books. Adding, removing or
editing the database is a simple process. Adding new users or cancelling existing userships can be
done with ease. The automated system saves a considerable amount of time as opposed to the
manual system.
Page |9
PYTHON CODE
P a g e | 10
CODE
File: library_manager_functions.py
import mysql.connector
from mysql.connector import errorcode
import pandas as pd
# Database configuration
config = {
'user': 'root',
'passwd': '1234',
'host': 'localhost',
'auth_plugin':'mysql_native_password'
}
def initialize_database():
"""Create the LibraryDB database and necessary tables if they don't exist."""
try:
# Connect to MySQL
conn = mysql.connector.connect(**config)
cursor = conn.cursor()
# Create Database
cursor.execute("CREATE DATABASE IF NOT EXISTS LibraryDB")
cursor.execute("USE LibraryDB")
cursor.execute('''
INSERT IGNORE INTO USERS (user_id, username, password, role)
VALUES (1, 'admin', 12345, 'admin');
''')
P a g e | 11
""")
def connect():
"""Connect to the LibraryDB database."""
config_with_db = config.copy()
config_with_db['database'] = 'LibraryDB'
try:
conn = mysql.connector.connect(**config_with_db)
if conn.is_connected():
print("Connected to LibraryDB.")
return conn
except mysql.connector.Error as e:
print(f"Error: {e}")
return None
cursor = conn.cursor(dictionary=True)
try:
query = "SELECT * FROM Users WHERE username = %s AND password = %s"
cursor.execute(query, (username, password))
user = cursor.fetchone()
if user:
print(f"Welcome, {user['username']} ({user['role']})!")
return user
else:
print("Invalid username or password.")
return None
except mysql.connector.Error as e:
print(f"Error: {e}")
finally:
cursor.close()
conn.close()
P a g e | 12
conn.commit()
print(f"User ID {user_id} deleted successfully.")
except mysql.connector.Error as err:
print(f"Error: {err}")
finally:
cursor.close()
try:
# Check if the user exists
cursor.execute("SELECT * FROM Users WHERE user_id = %s", (user_id,))
user = cursor.fetchone()
if not user:
print(f"User ID {user_id} not found. Update operation aborted.")
return # Exit the function if user does not exist
if username:
updates.append("username = %s")
values.append(username)
if password:
# If necessary, we can use password hashing here for better security (e.g., hashlib)
updates.append("password = %s")
values.append(password)
if role:
updates.append("role = %s")
values.append(role)
finally:
cursor.close()
def display_users(conn):
"""Display all users."""
cursor = conn.cursor(dictionary=True)
try:
cursor.execute("SELECT user_id, username, role FROM Users")
users = cursor.fetchall()
df = pd.DataFrame(users)
print("Users:")
print(df.to_string(index=False))
except mysql.connector.Error as e:
print(f"Error: {e}")
finally:
cursor.close()
P a g e | 13
def search_user(conn, **kwargs):
"""Search for users based on specified fields."""
cursor = conn.cursor(dictionary=True)
conditions = []
values = []
for field, value in kwargs.items():
conditions.append(f"{field} LIKE %s")
values.append(f"%{value}%")
query = "SELECT user_id, username, role FROM Users WHERE " + " AND ".join(conditions)
try:
cursor.execute(query, values)
users = cursor.fetchall()
df = pd.DataFrame(users)
print("Search Results:")
print(df.to_string(index=False))
except mysql.connector.Error as e:
print(f"Error: {e}")
finally:
cursor.close()
if title:
updates.append("title = %s")
values.append(title)
if author:
updates.append("author = %s")
values.append(author)
if genre:
updates.append("genre = %s")
values.append(genre)
if publish_year:
updates.append("publish_year = %s")
values.append(publish_year)
if isbn:
updates.append("isbn = %s")
values.append(isbn)
P a g e | 14
if updates:
query = f"UPDATE Books SET {', '.join(updates)} WHERE book_id = %s"
values.append(book_id)
try:
cursor.execute(query, values)
conn.commit()
print(f"Book ID {book_id} updated successfully.")
except mysql.connector.Error as err:
print(f"Error: {err}")
else:
print("No fields provided to update.")
cursor.close()
if issue_record:
# Update the return date and book status
cursor.execute("UPDATE IssuedBooks SET return_date = CURRENT_DATE WHERE issue_id = %s",
(issue_record[0],))
cursor.execute("UPDATE Books SET status = 'available' WHERE book_id = %s", (book_id,))
conn.commit()
print(f"Book ID {book_id} returned by User ID {user_id}.")
else:
print("No active record found for this book and user.")
except mysql.connector.Error as e:
print(f"Error: {e}")
finally:
cursor.close()
def display_books(conn):
"""Display all available books."""
cursor = conn.cursor(dictionary=True)
try:
query = "SELECT * FROM Books WHERE status = 'available'"
cursor.execute(query)
books = cursor.fetchall()
df = pd.DataFrame(books)
print("Available Books:")
print(df.to_string(index=False))
P a g e | 15
except mysql.connector.Error as e:
print(f"Error: {e}")
finally:
cursor.close()
query = "SELECT * FROM Books WHERE " + " AND ".join(conditions) + " AND status = 'available'"
cursor = conn.cursor(dictionary=True)
try:
cursor.execute(query, values)
books = cursor.fetchall()
df = pd.DataFrame(books)
print("Search Results:")
print(df.to_string(index=False))
except mysql.connector.Error as e:
print(f"Error: {e}")
finally:
cursor.close()
File: main.py
def admin_menu(conn):
"""Admin menu with options for user and book management."""
while True:
print("\nAdmin Menu:")
print("1. Add User")
print("2. Delete User")
print("3. Update User")
print("4. Display Users")
print("5. Search Users")
print("6. Add Book")
P a g e | 16
print("7. Delete Book")
print("8. Update Book")
print("9. Issue Book")
print("10. Return Book")
print("11. Display All Books")
print("12. Search Books")
print("13. Log Out")
if choice == '1':
username = input("Enter username: ")
password = input("Enter password: ")
role = input("Enter role (admin/user): ")
add_user(conn, username, password, role)
P a g e | 17
elif choice == '12':
field = input("Enter field to search by (title/author/genre): ")
value = input(f"Enter {field} value to search for: ")
search_books(conn, **{field: value})
else:
print("Invalid choice, please try again.")
if choice == '1':
display_books(conn)
else:
print("Invalid choice, please try again.")
def main():
# Step 1: Initialize the database and tables if they don't exist
initialize_database()
# Step 3: Login
while True:
print("\n1. Log In")
print("2. Exit")
choice = input("Enter your choice: ")
if choice == '1':
username = input("Enter username: ")
password = input("Enter password: ")
user = authenticate(username, password)
if user:
if user['role'] == 'admin':
admin_menu(conn)
elif user['role'] == 'user':
user_menu(conn, user['user_id'])
P a g e | 18
else:
print("Login failed. Please try again.")
else:
print("Invalid choice, please try again.")
if __name__ == "__main__":
main()
P a g e | 19
OUTPUT
Python Interface
Database and tables are ready.
RUN Connected to LibraryDB.
TIME Welcome to the Library Management System
1. Log In
2. Exit
Enter your choice: 1
Enter username: admin
Enter password: 12345
Connected to LibraryDB.
Welcome, admin (admin)!
Admin Menu:
1. Add User
2. Delete User
3. Update User
4. Display Users
5. Search Users
6. Add Book
7. Delete Book
8. Update Book
9. Issue Book
10. Return Book
11. Display All Books
12. Search Books
13. Log Out
Enter your choice: 4
Users:
user_id username role
1 admin admin
2 john user
4 jane user
Admin Menu:
1. Add User
2. Delete User
3. Update User
4. Display Users
5. Search Users
6. Add Book
7. Delete Book
8. Update Book
9. Issue Book
10. Return Book
11. Display All Books
12. Search Books
13. Log Out
Enter your choice: 11
Available Books:
book_id title author genre publish_year isbn status
1 SAMPLE BOOK CS LAB FICTION 2024 11223344 available
2 SAMPLE BOOK 1 PHYSICS SCIENCE 2021 220033 available
Admin Menu:
1. Add User
2. Delete User
3. Update User
4. Display Users
5. Search Users
6. Add Book
7. Delete Book
8. Update Book
9. Issue Book
10. Return Book
11. Display All Books
12. Search Books
13. Log Out
Enter your choice: 9
Enter Book ID to issue: 1
Enter User ID to issue to: 2
Book ID 1 issued to User ID 2.
P a g e | 20
Admin Menu:
1. Add User
2. Delete User
3. Update User
4. Display Users
5. Search Users
6. Add Book
7. Delete Book
8. Update Book
9. Issue Book
10. Return Book
11. Display All Books
12. Search Books
13. Log Out
Enter your choice: 11
Available Books:
book_id title author genre publish_year isbn status
2 SAMPLE BOOK 1 PHYSICS SCIENCE 2021 220033 available
Admin Menu:
1. Add User
2. Delete User
3. Update User
4. Display Users
5. Search Users
6. Add Book
7. Delete Book
8. Update Book
9. Issue Book
10. Return Book
11. Display All Books
12. Search Books
13. Log Out
Enter your choice: 12
Enter field to search by (title/author/genre): title
Enter title value to search for: sample
Search Results:
book_id title author genre publish_year isbn status
2 SAMPLE BOOK 1 PHYSICS SCIENCE 2021 220033 available
Admin Menu:
1. Add User
2. Delete User
3. Update User
4. Display Users
5. Search Users
6. Add Book
7. Delete Book
8. Update Book
9. Issue Book
10. Return Book
11. Display All Books
12. Search Books
13. Log Out
Enter your choice: 8
Enter Book ID to update: 2
New title (leave blank to skip): SAMPLE BOOK 2024 1
New author (leave blank to skip):
New genre (leave blank to skip):
New publish year (leave blank to skip):
New ISBN (leave blank to skip):
Book ID 2 updated successfully.
Admin Menu:
1. Add User
2. Delete User
3. Update User
4. Display Users
5. Search Users
6. Add Book
7. Delete Book
8. Update Book
9. Issue Book
10. Return Book
11. Display All Books
12. Search Books
13. Log Out
Enter your choice: 11
Available Books:
P a g e | 21
book_id title author genre publish_year isbn status
2 SAMPLE BOOK 2024 1 PHYSICS SCIENCE 2021 220033 available
Admin Menu:
1. Add User
2. Delete User
3. Update User
4. Display Users
5. Search Users
6. Add Book
7. Delete Book
8. Update Book
9. Issue Book
10. Return Book
11. Display All Books
12. Search Books
13. Log Out
Enter your choice: 13
Logging out from Admin Menu.
1. Log In
2. Exit
Enter your choice: 1
Enter username: john
Enter password: 123
Connected to LibraryDB.
Welcome, john (user)!
User Menu:
1. Display All Books
2. Search Books
3. View Issued Book Details
4. Log Out
Enter your choice: 3
Issued Book Details:
book_id title author issue_date return_date
1 SAMPLE BOOK CS LAB 2024-11-14 09:48:00 None
2 SAMPLE BOOK 2024 1 PHYSICS 2024-11-14 09:44:20 2024-11-14
User Menu:
1. Display All Books
2. Search Books
3. View Issued Book Details
4. Log Out
Enter your choice: 1
Available Books:
book_id title author genre publish_year isbn status
2 SAMPLE BOOK 2024 1 PHYSICS SCIENCE 2021 220033 available
User Menu:
1. Display All Books
2. Search Books
3. View Issued Book Details
4. Log Out
Enter your choice: 4
Logging out from User Menu.
1. Log In
2. Exit
Enter your choice: 1
Enter username: admin
Enter password: 12345
Connected to LibraryDB.
Welcome, admin (admin)!
Admin Menu:
1. Add User
2. Delete User
3. Update User
4. Display Users
5. Search Users
6. Add Book
7. Delete Book
8. Update Book
9. Issue Book
10. Return Book
11. Display All Books
12. Search Books
13. Log Out
Enter your choice: 10
P a g e | 22
Enter Book ID to return: 1
Enter User ID returning the book: 2
Book ID 1 returned by User ID 2.
Admin Menu:
1. Add User
2. Delete User
3. Update User
4. Display Users
5. Search Users
6. Add Book
7. Delete Book
8. Update Book
9. Issue Book
10. Return Book
11. Display All Books
12. Search Books
13. Log Out
Enter your choice: 11
Available Books:
book_id title author genre publish_year isbn status
1 SAMPLE BOOK CS LAB FICTION 2024 11223344 available
2 SAMPLE BOOK 2024 1 PHYSICS SCIENCE 2021 220033 available
Admin Menu:
1. Add User
2. Delete User
3. Update User
4. Display Users
5. Search Users
6. Add Book
7. Delete Book
8. Update Book
9. Issue Book
10. Return Book
11. Display All Books
12. Search Books
13. Log Out
Enter your choice: 13
Logging out from Admin Menu.
1. Log In
2. Exit
Enter your choice: 1
Enter username: john
Enter password: 123
Connected to LibraryDB.
Welcome, john (user)!
User Menu:
1. Display All Books
2. Search Books
3. View Issued Book Details
4. Log Out
Enter your choice: 3
Issued Book Details:
book_id title author issue_date return_date
1 SAMPLE BOOK CS LAB 2024-11-14 09:48:00 2024-11-14
2 SAMPLE BOOK 2024 1 PHYSICS 2024-11-14 09:44:20 2024-11-14
User Menu:
1. Display All Books
2. Search Books
3. View Issued Book Details
4. Log Out
Enter your choice: 4
Logging out from User Menu.
1. Log In
2. Exit
Enter your choice: 2
Exiting the Library Management System.
P a g e | 23
Database
1.
2.
3.
P a g e | 24
4.
5.
6.
P a g e | 25
BIBLIOGRAPHY
P a g e | 26