0% found this document useful (0 votes)
2 views

library management

The document certifies that S. Poorvaja Shree completed a project on Library Management under supervision, detailing the project's objectives, components, and future enhancements. It describes the automated Library Management System utilizing a MySQL database for managing library operations such as book issuance and returns. The project aims to streamline library processes, enhance data management, and improve user interaction through a text-based interface.

Uploaded by

sekar3498
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

library management

The document certifies that S. Poorvaja Shree completed a project on Library Management under supervision, detailing the project's objectives, components, and future enhancements. It describes the automated Library Management System utilizing a MySQL database for managing library operations such as book issuance and returns. The project aims to streamline library processes, enhance data management, and improve user interaction through a text-based interface.

Uploaded by

sekar3498
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

P. S.

Chidambara Nadar Senior English School


Virudhunagar
CERTIFICATE

This is to certify that S. Poorvaja Shree of class XII B of P. S. Chidambara Nadar

English School, Virudhunagar has done her project on 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.

Internal Examiner External Examiner

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

Computer Science. I have been greatly benefitted from her classes.

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.

 To utilize a MySQL database for backend storage of library data.

SYNOPSIS:

The program consists of several key components:

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 computer with sufficient processing power and memory.

 At least 4 GB of RAM is recommended.

 A hard drive with adequate storage to run the program and store the database.

SOFTWARE USED:

 Python: Python 3.9. 13 is used to write the program.

 MySQL: MySQL 8.0 Command Line Client for database management.

 MySQL Connector: Python MySQL connector to interact with MySQL database.

 Operating System: Windows

LIBRARIES USED:

 mysql.connector: For connecting to and interacting with the MySQL database.

 datetime: To validate and handle date formats3

4
CODE
import mysql.connector
from datetime import datetime

# Connect to MySQL database


def connect_to_db():
return mysql.connector.connect(
host="localhost",
user="root",
password="python123",
database="library"
)

# Initialize database with required tables


def initialize_db():
db = connect_to_db()
cursor = db.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS books (
book_id VARCHAR(10) PRIMARY KEY,
title VARCHAR(100),
author VARCHAR(100),
genre VARCHAR(50),
available BOOLEAN DEFAULT TRUE
)
""")
cursor.execute("""

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()

# Function to get the next available ID


def get_next_id(table_name, column_name):
db = connect_to_db()
cursor = db.cursor()
cursor.execute(f"SELECT MAX({column_name}) FROM {table_name}")
result = cursor.fetchone()[0]
db.close()
return 1 if result is None else result + 1

# Date validation function


def validate_date(date_str):
try:
datetime.strptime(date_str, '%Y-%m-%d')
return True
except ValueError:
return False

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: ")

# Validate issue date


issue_date = input("Enter Issue Date (YYYY-MM-DD): ")
while not validate_date(issue_date):

7
print("Invalid date format. Please enter the date in YYYY-MM-DD
format.")
issue_date = input("Enter Issue Date (YYYY-MM-DD): ")

cursor.execute("SELECT available FROM books WHERE book_id = %s",


(book_id,))
result = cursor.fetchone()

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]

# Validate return date


return_date = input("Enter Return Date (YYYY-MM-DD): ")
while not validate_date(return_date):
print("Invalid date format. Please enter the date in YYYY-MM-DD
format.")
return_date = input("Enter Return Date (YYYY-MM-DD): ")

cursor.execute("UPDATE books SET available = TRUE WHERE book_id


= %s", (book_id,))
cursor.execute("UPDATE transactions SET return_date = %s WHERE
transaction_id = %s", (return_date, transaction_id))
db.commit()
print("Book returned successfully.")

else:
print("Invalid Transaction ID.")
db.close()

# View all books


def view_books():
db = connect_to_db()
cursor = db.cursor()
cursor.execute("SELECT * FROM books")

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()

# View issued books


def view_issued_books():
db = connect_to_db()
cursor = db.cursor()
cursor.execute("""
SELECT t.transaction_id, b.title, t.student_name, t.issue_date,
t.return_date
FROM transactions t JOIN books b ON t.book_id = b.book_id
""")
records = cursor.fetchall()
print(f"{'Trans. ID':^10} {'Book Title':^30} {'Student':^20} {'Issue
Date':^12} {'Return Date':^12}")
for record in records:
issue_date = record[3].strftime('%Y-%m-%d') if record[3] else "N/A"
return_date = record[4].strftime('%Y-%m-%d') if record[4] else "Not
Returned"
print(f"{record[0]:^10} {record[1]:^30} {record[2]:^20} {issue_date:^12}
{return_date:^12}")
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")

choice = int(input("Enter your choice: "))


if choice == 1:
add_book()
elif choice == 2:

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.")

# Run the program


if name == " main ":
main()

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

1. W3Schools MySQL Tutorial: https://www.w3schools.com/mysql/


2. Python MySQL Documentation: https:pypi.org/project/mysql-connector-
python/
3. Computer Science with Python- Sumita Arora

36

You might also like