CS Project
CS Project
Siliguri
Page:
Index
1. Certificate
2. Acknowledgment
3. Introduction
4. Database Schema
5. Code
11. Screenshots
14. Suggested Improvements
15. Bibliography
Certificate
This is to certify that Isaac Thakur of XII-Science has
successfully completed and submitted his Computer Science
project on the topic “Library Management System” under the
guidance of his teacher Mithun Chakraborty in the given
time frame.
Page: 1
Acknowledgment
I sincerely express my gratitude to Mrs. Anisha Sharma,
our respected Principal, for her encouragement and support
throughout this project.
Yours Sincerely,
Isaac Thakur
Page: 2
Introduction
The Library Management Software is a simple Command Line
Interface program that aims to help with basic tasks for
maintaining a library in a digital way. The project uses
MySQL to store the data on tables and functions are made in
Python for basic functions like adding/removing books, adding/
removing users, borrow records/information and viewing the
existing records. It is a lightweight and efficient program for
reducing manual work and can maintain large databases too.
System Requirements
Software:
1. mysql ; Version: 8.0.40
2. python ; Version: 3.13
3. mysql-connector-python ; Version: 9.1.0
4. Windows 7/8//10/11 (x86 or 64 based)
Hardware
1. Processor: i3 CPU
2. Ram: 2GB
3. Storage: at least 256GB
Page: 3
Database Schema
The SQL database contains three tables for storing the record
of books, users and the borrowings. Their structures are
given below:
1. Books:
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| BookID | int | NO | PRI | NULL | auto_increment |
| Title | varchar(255) | NO | | NULL | |
| Author | varchar(255) | YES | | NULL | |
| Available | tinyint(1) | YES | |1 | |
+-----------+--------------+------+-----+---------+----------------+
2. Users:
+--------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+---------+----------------+
| UserID | int | NO | PRI | NULL | auto_increment |
| Name | varchar(255) | NO | | NULL | |
| Email | varchar(255) | YES | | NULL | |
+--------+--------------+------+-----+---------+----------------+
3. Borrowings:
+-------------+------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------+------+-----+---------+----------------+
| BorrowingID | int | NO | PRI | NULL | auto_increment |
| UserID | int | YES | MUL | NULL | |
| BookID | int | YES | MUL | NULL | |
+-------------+------+------+-----+---------+----------------+
Page: 4
Code
import mysql.connector
# -------------------------------------------------------
# Database Connection
# -------------------------------------------------------
def connect_db():
“””Establish connection to the database.”””
return mysql.connector.connect(
host=”localhost”,
user=”root”,
password=”0703”,
database=”library_management”
)
# -------------------------------------------------------
# Functions for Library Management System
# -------------------------------------------------------
def view_users():
“””Display all registered users.”””
cursor.execute(“SELECT * FROM Users”)
users = cursor.fetchall()
print(“\nUsers:”)
for u in users:
print(f”UserID: {u[0]} | Name: {u[1]} | Email: {u[2]}”)
def view_books():
“””Display all books in the library.”””
cursor.execute(“SELECT * FROM Books”)
books = cursor.fetchall()
print(“\nBooks:”)
for book in books:
Page: 5
print(f”BookID: {book[0]} | Title: {book[1]} | Author:
{book[2]} | Available: {‘Yes’ if book[3] else ‘No’}”)
print()
def view_borrowings():
“””Display borrowing details (User, Book, Period).”””
cursor.execute(“””
SELECT Borrowing.BorrowingID, Users.Name, Books.Title
FROM Borrowing
JOIN Users ON Borrowing.UserID = Users.UserID
JOIN Books ON Borrowing.BookID = Books.BookID
“””)
borrowings = cursor.fetchall()
print(“\nBorrowings:”)
for b in borrowings:
print(f”BorrowingID: {b[0]} | User: {b[1]} | Book:{b[2]}”)
print()
def view_infos():
“””Allow the user to view Users, Books, or Borrowings.”””
while True:
print(“\nView Information”)
print(“1. View Users”)
print(“2. View Books”)
print(“3. View Borrowings”)
print(“4. Back to Main Menu”)
def add_book():
“””Add a new book to the library.”””
view_books()
Page: 6
title = input(“Enter the book title: “)
author = input(“Enter the book author: “)
cursor.execute(“INSERT INTO books (Title, Author) VALUES (%s,
%s);”, (title, author))
conn.commit()
print(f”Book ‘{title}’ by {author} added successfully.”)
def add_user():
“””Register a new user.”””
view_users()
name = input(“Enter the name of the user: “)
email = input(“Enter the email of the user: “)
cursor.execute(“INSERT INTO users (Name, Email) VALUES (%s,
%s);”, (name, email))
conn.commit()
print(f”User ‘{name}’ added successfully.”)
def borrow_book():
“””Borrow a book for a user.”””
view_users()
user_id = int(input(“Enter the user ID: “))
view_books()
book_id = int(input(“Enter the book ID: “))
Page: 7
(%s, %s);”, (user_id, book_id))
cursor.execute(“UPDATE books SET Available = FALSE WHERE
BookID = %s;”, (book_id,))
conn.commit()
print(f”Book ‘{book[1]}’ borrowed successfully by User ID
{user_id}.”)
def return_book():
“””Return a borrowed book.”””
view_users()
user_id = int(input(“Enter user ID: “))
if not borrowings:
print(“No borrowed books for this user.”)
return
print(“Borrowed Books:”)
for b in borrowings:
print(f”BorrowingID: {b[0]}, BookID: {b[1]}, Title:
{b[2]}, Author: {b[3]}”)
def delete_record():
“””Delete a user or book from the system.”””
Page: 8
print(“\nDelete Record”)
print(“1. Delete a User”)
print(“2. Delete a Book”)
choice = input(“Enter your choice: “)
if choice == ‘1’:
view_users()
user_id = int(input(“Enter User ID to delete: “))
else:
Page: 9
print(“Invalid choice. Returning to main menu.”)
def menu():
“””Main menu for Library Management System.”””
while True:
print(“\nLibrary Management System”)
print(“1. Add Book”)
print(“2. Borrow Book”)
print(“3. Return Book”)
print(“4. Add User”)
print(“5. View Infos”)
print(“6. Delete Record”)
print(“7. Exit”)
Page: 10
Screenshots
This section contains the screenshots of the programs
execution windows.
1. Adding a book:
2.Adding users:
Page: 11
3. Borrowing book:
4. Returning Book:
Page: 12
4. Deleting a book
5. Viewing users:
Page: 13
Suggested Improvements
1. User Authentication: Currently, the system does not have
user authentication. A user login system could be added
to track activities securely.
2. GUI Interface: The system currently operates through the
command line, but a graphical user interface (GUI) could
make it more user-friendly
3. Late Return Fines: The system does not handle late re-
turns or fines, which could be added in future versions.
Page: 14
Bibliography
1. www.geeksforgeeks.org
2. www.w3schools.com
Page: 15