VOOZH about

URL: https://www.geeksforgeeks.org/python/library-management-system-using-python/

⇱ Library Management System using Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Library Management System using Python

Last Updated : 15 Jul, 2025

Library Management System is a project developed using Object-Oriented Programming (OOP) in Python. The goal of this project is to simulate the operations of a real-world library, including adding books, registering users, borrowing and returning books, and searching for books by their title. This system will help manage library resources efficiently and is built around three main components: Books, Users, and the Library itself.

Features of the Library Management System

  • View all books: Display a list of all available books in the library.
  • Add new books: Allow adding new books to the library’s collection.
  • Search for books by title: Search for books based on their title.
  • Borrow a book: Users can borrow a book if it's available.
  • Return a book: Borrowed books can be returned to the library.
  • View borrowed books: Users can view all the books they have borrowed.
  • Add new users: New users can be registered in the system.

Let's start building the project:

Book Class

The Book class is responsible for storing and managing details about the books in the library. Each book has a unique identifier, a title, an author, and a quantity representing how many copies are available in the library.

Explanation:

  • display_book_info(): Displays the book's information, such as the title, author, and quantity.
  • check_availability(): Returns True if the book is available for borrowing (i.e., quantity is greater than 0), otherwise returns False.
  • update_quantity(quantity): Updates the available quantity of the book based on the action (borrowing or returning). A negative value decreases the quantity, while a positive value increases it.

User Class

The User class represents a person who borrows books from the library. It stores the user’s information, such as their ID, name, and the list of books they have borrowed. This class also contains methods for borrowing and returning books.

Explanation:

  • borrow_book(book): Allows a user to borrow a book, if it's available.
  • return_book(book): Allows a user to return a book they have borrowed.
  • view_borrowed_books(): Displays a list of all the books borrowed by the user.

Library Class

The Library class is the core of the system. It manages both the books and the users. This class is responsible for adding books to the library, registering new users, searching for books, and handling the borrowing and returning of books.

Explanation:

  • add_book(book): Adds a book to the library’s collection.
  • register_user(user): Registers a new user to the system, ensuring that no duplicate user IDs exist.
  • search_book_by_title(title): Searches for books in the library by their title.
  • list_books(): Displays all books in the library.
  • add_new_book(): Allows adding a new book to the library by taking user input (book ID, title, author, quantity).

Main Function

The main function acts as the entry point of the program, where the library system is initialized, books and users are added, and a menu-driven interface allows interaction with the system.

Complete Code

Output:

Welcome to the Library Management System

1. View all books
2. Add books
3. Search for a book by title
4. Borrow a book
5. Return a book
6. View borrowed books
7. Add new User
8. Exit

Enter your choice: 7

Enter user id: 3

Enter user's name: Prajjwal

New User added Successfully !!


Welcome to the Library Management System

1. View all books
2. Add books
3. Search for a book by title
4. Borrow a book
5. Return a book
6. View borrowed books
7. Add new User
8. Exit

Enter your choice: 4

Enter your user ID: 1

Enter the book ID to borrow: 2

Geek_1 has borrowed 'The Hobbit'

Welcome to the Library Management System

1. View all books
2. Add books
3. Search for a book by title
4. Borrow a book
5. Return a book
6. View borrowed books
7. Add new User
8. Exit

Enter your choice: 1

Books in the Library:

ID: 1, Title: Harry Potter and the Philosopher's Stone, Author: J.K. Rowling, Available Quantity: 5

ID: 2, Title: The Hobbit, Author: J.R.R. Tolkien, Available Quantity: 2

ID: 3, Title: 1984, Author: George Orwell, Available Quantity: 2

Welcome to the Library Management System

1. View all books
2. Add books
3. Search for a book by title
4. Borrow a book
5. Return a book
6. View borrowed books
7. Add new User
8. Exit

Enter your choice:

Comment
Article Tags: