A simple yet powerful library management system built with Python, FastAPI, and a web interface.
This is a 3-stage library management system:
- Stage 1: Command line application with OOP
- Stage 2: API integration with Open Library
- Stage 3: FastAPI web service with HTML interface
- Add, remove, search books
- Automatic book info from ISBN using Open Library API
- Member management and book borrowing
- Different book types:
Book,EBook,AudioBook - REST API with FastAPI
- Simple web interface
- JSON data storage
- Complete tests with pytest
project/
├── main.py # Command line app
├── api.py # FastAPI web service
├── book.py # Book classes
├── library.py # Library management
├── member.py # Member class
├── member_manager.py # Member management
├── web_interface.html # Web interface
├── test_library.py # Library tests
├── test_api.py # API tests
├── requirements.txt # Dependencies
├── library.json # Book data
└── members.json # Member data
- Clone the project:
git clone <your-repo-url>
cd library-management-system- Install dependencies:
pip install -r requirements.txtpython main.pyChoose from menu:
- Add Book (manual or by ISBN)
- Remove Book
- List Books
- Search Book
- Add Member
- List Members
- Borrow Book
- Return Book
uvicorn api:app --reloadThen visit:
- API docs: http://127.0.0.1:8000/docs
- Health check: http://127.0.0.1:8000/health
- Start the API server first
- Open
web_interface.htmlin your browser
| Method | URL | Description | Example |
|---|---|---|---|
| GET | /books |
Get all books | - |
| POST | /books |
Add book by ISBN | {"isbn": "9780743273565"} |
| GET | /books/{isbn} |
Get one book | - |
| DELETE | /books/{isbn} |
Delete book | - |
| GET | /health |
Check if API works | - |
Get all books:
curl http://127.0.0.1:8000/booksAdd book by ISBN:
curl -X POST http://127.0.0.1:8000/books \
-H "Content-Type: application/json" \
-d '{"isbn":"9780743273565"}'Delete book:
curl -X DELETE http://127.0.0.1:8000/books/9780743273565Run all tests:
pytest -vRun specific tests:
pytest test_library.py -v # Library tests
pytest test_api.py -v # API testsRegular Book:
Book(title="1984", author="George Orwell", isbn="9780451524935")EBook:
EBook(title="Digital Book", author="Author", isbn="123", file_format="PDF")AudioBook:
AudioBook(title="Audio Story", author="Author", isbn="456", duration=180)httpx- For API calls to Open Libraryfastapi- Web frameworkuvicorn- ASGI serverpytest- Testing frameworkpydantic- Data validation
- Books stored in
library.json - Members stored in
members.json - Uses JSON format for easy reading
Uses Open Library API to get book info by ISBN:
- URL:
https://openlibrary.org/isbn/{isbn}.json - Gets title and author automatically
- Handles errors when book not found
- Network errors when API is down
- Invalid ISBN numbers
- Duplicate books
- Books not found
- Borrowed books cannot be deleted
- View all books in a table
- Add new books by ISBN
- Delete books with confirmation
- Responsive design
- Real-time updates
- Error messages for user
Stage 1 Files:
book.py- Book classes with OOPlibrary.py- Library managementmain.py- Command line interface
Stage 2 Additions:
- API integration in
library.py - Error handling for network calls
- Tests for API functionality
Stage 3 Additions:
api.py- FastAPI web serviceweb_interface.html- Web frontend- API tests and documentation
Tests cover:
- Book creation and methods
- Library operations (add, remove, find)
- API integration with mocking
- FastAPI endpoints
- Error conditions
- Data persistence
- SQLite database instead of JSON
- User authentication
- Book recommendations
- Email notifications
- Mobile app
- Docker containerization

