Skip to content

guustavomc/Library-Management-Application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

Library API – FastAPI Project

Overview

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.

Project Structure

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

Features

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

Tech Stack

  • FastAPI – Modern, fast web framework
  • Pydantic – Data validation and settings
  • Uvicorn – ASGI server
  • Python 3.8+

Installation

  1. Clone the project
git clone https://github.com/guustavomc/Library-Management-Application
cd library-api
  1. Create virtual environment (optional)
python -m venv venv
source venv/bin/activate  # Linux/Mac
# venv\Scripts\activate  # Windows
  1. Install dependencies
pip install -r requirements.txt
  1. Run the API
uvicorn main:app --reload

Server starts at: http://127.0.0.1:8000

Interactive Docs

API Usage Examples

  1. 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
  }'
  1. List Available Books
curl "http://127.0.0.1:8000/books/?available=true"
  1. Borrow a Book
curl -X POST "http://127.0.0.1:8000/books/abc123/borrow?customer_id=1&customer_name=Alice"
  1. 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

Next Steps (Future Improvements)

  • SQLite/PostgreSQL with SQLAlchemy
  • Customer CRUD API
  • JWT Authentication
  • Docker Support
  • Unit Tests (pytest)

About

Library Management Application developed for Python study

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages