Python Library Management System Project with source code

Last updated Jul 26, 2021

In this tutorial, we are going to learn Python library management system project with simple and easy code. This python Library system implemented data storage in MySQL Database. This Database contains the different tables to maintain the data about the library. This Library Management project has different features like

 

Features of Library Management System Project

Add Books: With this feature we can add Books in LMS system with book details like Title,Author, Publisher, Price, Number of books...>

Add Member: With this Add Member feature we can add Member details Member Name, Mobile Number, Email Address, Class Name and address of the Member

Update Book : Update the previous entered Book details

Update Member : Update the Member details

Issue Book: This will record the details on the Book issued to whom. This Feature stores the details of Book ID, Member ID , Issue Date, Return Date and Fine if anything is pending from the student/member

Return Book : Update the Book Transactions on returned by the member

Search Menu: Search The Books which are available in the System

Report Menu: Return the Reports based on Books, Publisher, Member search

Special Menu

 

This LMS project store the data in database, this Project created a MySQL database with name "library"

This Database has 3 tables to store and retrieve the data about the LMS system.

 

To implement python Library Management project used below modules

MySql Connector : This module is used to connect mysql database to fetch/add data into database

DateTime : To set date and get current date and update the details on the tables

 

Build a Library System with MySQL in Python

                                        
            
import mysql.connector
from datetime import date
            

 

Add Book

                                        
            
def add_book():
  conn = mysql.connector.connect(
       host='localhost', database='library', user='root', password='')
  cursor = conn.cursor()

  title = raw_input('Enter Book Title :')
  author = raw_input('Enter Book Author : ')
  publisher = raw_input('Enter Book Publisher : ')
  pages = raw_input('Enter Book Pages : ')
  price = raw_input('Enter Book Price : ')
  edition = raw_input('Enter Book Edition : ')
  copies  = int(raw_input('Enter copies : '))
  sql = 'insert into book(title,author,price,pages,publisher,edition,status) values ( "' + \
       title + '","' + author+'",'+price+','+pages+',"'+publisher+'","'+edition+'","available");'
   #sql2 = 'insert into transaction(dot,qty,type) values ("'+str(today)+'",'+qty+',"purchase");'
  #print(sql)
  for _ in range(0,copies):
    cursor.execute(sql)
  conn.close()
  print('\n\nNew Book added successfully')
  wait = raw_input('\n\n\n Press any key to continue....')
            

 

Add Member

                                        
            
def add_member():
  conn = mysql.connector.connect(
      host='localhost', database='library', user='root', password='')
  cursor = conn.cursor()

  name = raw_input('Enter Member Name :')
  clas = raw_input('Enter Member Class & Section : ')
  address = raw_input('Enter Member Address : ')
  phone = raw_input('Enter Member Phone  : ')
  email = raw_input('Enter Member Email  : ')
  
 
  sql = 'insert into member(name,class,address,phone,email) values ( "' + \
      name + '","' + clas+'","'+address+'","'+phone + \
        '","'+email+'");'
  #sql2 = 'insert into transaction(dot,qty,type) values ("'+str(today)+'",'+qty+',"purchase");'
  #print(sql)
  
  cursor.execute(sql)
  conn.close()
  print('\n\nNew Member added successfully')
  wait = raw_input('\n\n\n Press any key to continue....')
            

 

Update Book

                                        
            
def modify_book():
    conn = mysql.connector.connect(
        host='localhost', database='library', user='root', password='')
    cursor = conn.cursor()
    clear()
    print('Modify BOOK Details Screen ')
    print('-'*120)
    print('\n1. Book Title')
    print('\n2. Book Author')
    print('\n3. Book Publisher')
    print('\n4. Book Pages')
    print('\n5. Book Price')
    print('\n6. Book Edition')
    print('\n\n')
    choice = int(raw_input('Enter your choice :'))
    field = ''
    if choice == 1:
        field = 'title'
    if choice == 2:
        field = 'author'
    if choice == 3:
        field = 'publisher'
    if choice == 4:
        field = 'pages'
    if choice == 5:
        field = 'price'
    book_id = raw_input('Enter Book ID :')
    value = raw_input('Enter new value :')
    if field =='pages' or field == 'price':
        sql = 'update book set ' + field + ' = '+value+' where id = '+book_id+';'
    else:
        sql = 'update book set ' + field + ' = "'+value+'" where id = '+book_id+';'
    #print(sql)
    cursor.execute(sql)
    print('\n\n\nBook details Updated.....')
    conn.close()
    wait = raw_input('\n\n\n Press any key to continue....')
            

 

Update Member

                                        
            
def modify_member():
    conn = mysql.connector.connect(
        host='localhost', database='library', user='root', password='')
    cursor = conn.cursor()
    clear()
    print('Modify Memeber Information Screen ')
    print('-'*120)
    print('\n1. Name')
    print('\n2. Class')
    print('\n3. address')
    print('\n4. Phone')
    print('\n5. Emaile')
    print('\n\n')
    choice = int(raw_input('Enter your choice :'))
    field =''
    if choice == 1:
        field ='name'
    if choice == 2:
        field = 'class'
    if choice ==3:
        field ='address'
    if choice == 4:
        field = 'phone'
    if choice == 5:
        field = 'email'
    mem_id =raw_input('Enter member ID :')
    value = raw_input('Enter new value :')
    sql = 'update member set '+ field +' = "'+value+'" where id = '+mem_id+';'
    #print(sql)
    cursor.execute(sql)
    print('Member details Updated.....')
    conn.close()
    wait = raw_input('\n\n\n Press any key to continue....')

            

 

Issue Book

                                        
            
def issue_book():
    conn = mysql.connector.connect(
      host='localhost', database='library', user='root', password='')
    cursor = conn.cursor()

    clear()
    print('\n BOOK ISSUE SCREEN ')
    print('-'*120)
    book_id = raw_input('Enter Book  ID : ')
    mem_id  = raw_input('Enter Member ID :')
   
    
    result = book_status(book_id)
    result1 = mem_issue_status(mem_id)
    #print(result1)
    today = date.today()
    if len(result1) == 0:
      if result == 'available':
          sql = 'insert into transaction(b_id, m_id, doi) values('+book_id+','+mem_id+',"'+str(today)+'");'
          sql_book = 'update book set status="issue" where id ='+book_id + ';'
          cursor.execute(sql)
          cursor.execute(sql_book)
          print('\n\n\n Book issued successfully')
      else:
          print('\n\nBook is not available for ISSUE... Current status :',result1)
    else:
      if len(result1)<1:
        sql = 'insert into transaction(b_id, m_id, doi) values(' + \
             book_id+','+mem_id+',"'+str(today)+'");'
        sql_book = 'update book set status="issue" where id ='+book_id + ';'
        #print(len(result))
        cursor.execute(sql)
        cursor.execute(sql_book)
        print('\n\n\n Book issued successfully')
      else:
        print('\n\nMember already have book from the Library')
      #print(result)

    conn.close()
    wait = raw_input('\n\n\n Press any key to continue....')
            

 

Return Book

                                        
            
def return_book():
    conn = mysql.connector.connect(
        host='localhost', database='library', user='root', password='')
    cursor = conn.cursor()
    global fine_per_day
    clear()
    print('\n BOOK RETURN SCREEN ')
    print('-'*120)
    book_id = raw_input('Enter Book  ID : ')
    mem_id = raw_input('Enter Member ID :')
    today =date.today()
    result = book_issue_status(book_id,mem_id)
    if result==None:
       print('Book was not issued...Check Book Id and Member ID again..')
    else:
       sql='update book set status ="available" where id ='+book_id +';'
       din = (today - result[3]).days
       fine = din * fine_per_day    #  fine per data
       sql1 = 'update transaction set dor ="'+str(today)+'" , fine='+str(fine)+' where b_id='+book_id +' and m_id='+mem_id+' and dor is NULL;' 
       
       cursor.execute(sql)
       cursor.execute(sql1)
       print('\n\nBook returned successfully')
    conn.close()
    wait = raw_input('\n\n\n Press any key to continue....')
            

 

Search Book

                                        
            
def search_book(field):
    conn = mysql.connector.connect(
        host='localhost', database='library', user='root', password='')
    cursor = conn.cursor()

    clear()
    print('\n BOOK SEARCH SCREEN ')
    print('-'*120)
    msg ='Enter '+ field +' Value :'
    title = raw_input(msg)
    sql ='select * from book where '+ field + ' like "%'+ title+'%"'
    cursor.execute(sql)
    records = cursor.fetchall()
    clear()
    print('Search Result for :',field,' :' ,title)
    print('-'*120)
    for record in records:
      print(record)
    conn.close()
    wait = raw_input('\n\n\n Press any key to continue....')
            

 

Reports

                                        
            
def reprot_book_list():
    conn = mysql.connector.connect(
        host='localhost', database='library', user='root', password='')
    cursor = conn.cursor()

    clear()
    print('\n REPORT - BOOK TITLES ')
    print('-'*120)
    sql ='select * from book'
    cursor.execute(sql)
    records = cursor.fetchall()
    for record in records:
       print(record)
    conn.close()
    wait = raw_input('\n\n\nPress any key to continue.....')
            

 

 

MySQL database Tables

                                        
Library Management Project

 

Sample Output for the Add Book

                                        
            

L I B R A R Y    M E N U

            

1.  Add Books

            

2.  Add Member

            

3.  Modify Book Information

            

4.  Modify Student Information

            

5.  Issue Book

            

6.  Return Book

            

7.  Search Menu

            

8.  Report Menu

            

9.  Special Menu

            

0.  Close application

            

 

            

Enter your choice ...: 1
            Enter Book Title :Python
            Enter Book Author : Benten
            Enter Book Publisher : RRpublishers
            Enter Book Pages : 120
            Enter Book Price : 300
            Enter Book Edition : 1
            Enter copies : 2

            


            New Book added successfully

            

 

 

How to Run Library Management System Project

        
  • Unzip and Extract files into Local server(XAMPP/LAMPP) or Remote server
  •     
  • Run Server
  •     
  • Create Database and import tables into created database
  •     
  • Update Database connection by enter user name, password for the database access
  •     
  • Run Python script on your IDE

 

Frequently Asked Questions About Python Library Management Projects

What is a Python Library Management System?

A Python Library Management System is a sophisticated software application designed to automate and streamline library operations using Python programming. This comprehensive system helps libraries manage books, members, borrowing processes, inventory tracking, and other critical library functions through robust and efficient code.

 

Why Choose Python for a Library Management System Project?

Python is an ideal programming language for library management systems due to several key advantages:

  • Extensive library support with modules like SQLite, Tkinter, and pandas
  • Easy-to-read and maintain code structure
  • Powerful database integration capabilities
  • Rich set of frameworks for building user interfaces
  • Excellent data handling and manipulation features

 

What are the Core Features of a Python Library Management System?

A comprehensive Python Library Management System typically includes:

  • Book inventory management
  • Member registration and tracking
  • Borrowing and return process automation
  • Search functionality for books
  • Fine calculation for overdue books
  • Detailed reporting and analytics
  • User authentication and access control

 

How Can Beginners Start a Python Library Management Project?

Beginners can approach a library management project through these steps:

  1. Learn fundamental Python programming concepts
  2. Understand database management with SQLite or MySQL
  3. Study GUI development using Tkinter or PyQt
  4. Break down the project into smaller, manageable modules
  5. Start with basic functionality and progressively add complex features
  6. Practice version control using Git
  7. Seek feedback and continuously improve the project

 

What Database Options Work Best with Python Library Management Systems?

Several database options complement Python library management projects:

  • SQLite: Lightweight, file-based database perfect for small to medium projects
  • MySQL: Robust, scalable database for larger library systems
  • PostgreSQL: Advanced open-source database with complex query support
  • MongoDB: NoSQL database offering flexible data storage

 

Which Python Libraries and Frameworks Are Useful for Library Management Projects?

Recommended Python libraries and frameworks include:

  • Tkinter: For creating graphical user interfaces
  • SQLAlchemy: Powerful ORM for database interactions
  • Pandas: Data manipulation and analysis
  • PyQt: Advanced GUI development
  • Django/Flask: Web framework options for online library management systems

 

What Skills Can Developers Gain from a Library Management System Project?

Developing a library management system helps programmers enhance:

  • Object-oriented programming skills
  • Database management techniques
  • User interface design
  • Error handling and validation
  • Project architecture and design patterns
  • Version control and collaborative development

 

How Complex Can a Python Library Management System Be?

Python library management systems can range from simple console-based applications to complex web and desktop applications with:

  • Multilevel user roles
  • Advanced search algorithms
  • Machine learning-based book recommendations
  • Real-time inventory tracking
  • Integration with external library networks

 

Are There Open-Source Python Library Management System Examples?

Several open-source Python library management system projects are available on platforms like GitHub, providing excellent learning resources:

  • Simple console-based systems
  • Desktop applications with Tkinter
  • Web-based systems using Django or Flask
  • Advanced systems with multiple features and integrations

 

What Career Opportunities Exist After Developing a Library Management System?

Creating a robust library management system can open doors to:

  • Software development roles
  • Database management positions
  • Python programming careers
  • Project management opportunities
  • Specialized roles in library technology

Conclusion

Python Library Management Systems represent an excellent opportunity for programmers to develop practical, real-world applications while enhancing their coding skills. Whether you're a beginner or an experienced developer, these projects offer valuable learning experiences and potential career advancements

Related

Python Notepad Editor Project

Python GUI Application- Contact Book Project

Python Online Job Portal Project Source Code

Library Management System Project in C++

 

Tags: Source Code, Python Project, Beginner Projects, Academic Projects

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

8004 Views