You will build a simple Library Management System API using FastAPI. This API will allow users to:
- Create books in the library.
- Read book details by ID or list all books.
- Update book information.
- Delete books from the library.
This project will help you understand:
- How to set up a FastAPI project.
- How to define API endpoints.
- How to work with a database (SQLite with SQLAlchemy).
- How to handle request validation with Pydantic.
- Install dependencies:
FastAPI
,Uvicorn
,SQLAlchemy
,Pydantic
,SQLite
. - Set up a virtual environment (optional but recommended).
- Initialize a FastAPI project structure.
- Use SQLAlchemy to create a
Book
table with:id
(int, primary key)title
(str)author
(str)published_year
(int)isbn
(str, unique)
- POST /books/ → Add a new book.
- GET /books/ → Get all books.
- GET /books/{book_id} → Get book details by ID.
- PUT /books/{book_id} → Update book details.
- DELETE /books/{book_id} → Remove a book from the library.
- Use SQLAlchemy ORM to interact with SQLite.
- Create a session for handling database operations.
- Use Pydantic models for input validation.
- Handle errors (e.g., book not found, invalid data).
- Use Swagger UI (FastAPI provides it by default).
- Test using Postman or
curl
.
- Add authentication (JWT).
- Implement pagination and filtering.
- Deploy the API using Render, Railway, or Docker.
- A GitHub repository with a structured FastAPI project.
- A
README.md
with setup instructions. - A working API with CRUD operations.