This project implements a Flask REST API to manage a book library. It includes features for adding, listing available books, borrowing/returning books, searching, and viewing overdue books.
-
CRUD Operations:
- Create new book listings (POST /books).
- Retrieve available books (GET /books).
- Update book status (borrowed/returned) (PUT /books/).
- Delete book entries (DELETE /books/).
-
Search Functionality:
- Search books by title, author, or publication year (GET /search).
-
Overdue Book Tracking:
- Retrieve a list of overdue books (GET /overdue)
* app.py: Contains the core Flask application logic and API routes.
* models.py: Defines the Book model representing book data.
* library_management.py: Houses library logic (adding, borrowing, returning, etc.).
* search.py: Encapsulates the search functions.
* test_api.py: For testing
List Available Books:
GET http://127.0.0.1:5000/books
Add a New Book:
POST http://127.0.0.1:5000/books
Content-Type: application/json
{
"title": "New Book Title",
"author": "Book Author",
"isbn": "978-1234567890",
"publication_year": 2023
}
Search Books:
GET http://127.0.0.1:5000/search?title=Pride
GET http://127.0.0.1:5000/search?author=Austen
GET http://127.0.0.1:5000/search?year=1960
Book Status Management:
# Update existing book details
PUT http://127.0.0.1:5000/books/978-1234567890
Content-Type: application/json
{
"title": "The Hobbit (Revised Edition)",
"publication_year": 1951
}
# Mark a book as borrowed
PUT http://127.0.0.1:5000/books/978-0141439518?action=borrow
# Mark a book as returned
PUT http://127.0.0.1:5000/books/978-0547928227?action=return
# Get overdue books
GET http://127.0.0.1:5000/overdue
- Python 3.x
- Flask ( pip install flask)
- For persistent storage, you'll need a database (such as SQLite, PostgreSQL, or MySQL) and a corresponding ORM (like SQLAlchemy) to interact with it.
- Clone the repository:
https://github.com/ariz565/Book-Library-System.git
- Create Virtual Environment
python -m venv env source env/bin/activate # Linux/macOS env\Scripts\activate # Windows
- Install dependencies:
pip install -r requirements.txt
- Run the application
python app.py flask --app app run flask run
This will start the Flask development server. Access the API through your browser or a tool like Postman (usually at http://127.0.0.1:5000/)
Unit Testing:
pip install pytest
Open terminal run the command : pytest
Notes: The current implementation uses placeholder data. Consider database integration. The overdue books feature assumes due date tracking logic .