This is a RESTful API for a simple library management system built with FastAPI and Python OOP. It allows you to:
- Register books
- List all or available books
- Lend books to customers
- Return borrowed books
Made for studying OOP and REST API development on Python.
library_api/
│
├── main.py ← FastAPI entry point
├── models/
│ ├── __init__.py
│ ├── book.py
│ ├── customer.py
│ └── inventory.py
├── schemas/
│ ├── __init__.py
│ └── book.py ← Pydantic models for API
├── api/
│ ├── __init__.py
│ └── v1/
│ ├── __init__.py
│ └── endpoints/
│ ├── books.py
│ └── customers.py
├── core/
│ └── config.py ← Optional: settings
└── requirements.txt
| Endpoint | Method | Description |
|---|---|---|
POST /books/ |
Create a new book | |
GET /books/ |
List all books (?available=true/false) |
|
POST /books/{book_id}/borrow |
Lend book to customer | |
POST /books/{book_id}/return |
Return a borrowed book |
- FastAPI – Modern, fast web framework
- Pydantic – Data validation and settings
- Uvicorn – ASGI server
- Python 3.8+
- Clone the project
git clone https://github.com/guustavomc/Library-Management-Application
cd library-api- Create virtual environment (optional)
python -m venv venv
source venv/bin/activate # Linux/Mac
# venv\Scripts\activate # Windows- Install dependencies
pip install -r requirements.txt- Run the API
uvicorn main:app --reloadServer starts at: http://127.0.0.1:8000
Interactive Docs
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
- Create a Book
curl -X POST "http://127.0.0.1:8000/books/" \
-H "Content-Type: application/json" \
-d '{
"name": "1984",
"author": "George Orwell",
"pages": 328,
"price": 19.99
}'- List Available Books
curl "http://127.0.0.1:8000/books/?available=true"- Borrow a Book
curl -X POST "http://127.0.0.1:8000/books/abc123/borrow?customer_id=1&customer_name=Alice"- Return a Book
bashcurl -X POST "http://127.0.0.1:8000/books/abc123/return"Sample Data (Pre-loaded)
python"LORD OF THE RINGS" by J.R.R. Tolkien – 1000 pages – $50
"THE HOBBIT" by J.R.R. Tolkien – 500 pages – $30- SQLite/PostgreSQL with SQLAlchemy
- Customer CRUD API
- JWT Authentication
- Docker Support
- Unit Tests (pytest)