This project is a Smart Library System built with FastAPI and PostgreSQL. It provides APIs for managing users, books, and loans. The application uses uvicorn as the ASGI server.
- User Management: Add, update, delete, and retrieve user information.
- Book Management: Add, update, delete, and retrieve book details.
- Loan Management: Manage book loans, including issuing and returning books.
- Database: PostgreSQL is used for data storage.
- FastAPI: High-performance API framework for building RESTful APIs.
- Uvicorn: Lightning-fast ASGI server for running the application.
- Python 3.8+
- PostgreSQL
- pip (Python package manager)
- Clone the repository:
git clone https://github.com/your-username/fastapi-postgres-smart-library.git
cd fastapi-postgres-smart-library- Install
uvpackage manager globally if not already installed:
pip install uv- Configure the database:
- Create a PostgreSQL database.
- Update the
DATABASE_URLin the.envfile with your database credentials.
- Install project dependencies using
uv:
uv install- Run database migrations:
uv db upgrade- Start the application:
uv run fastapi devGET /users/: Retrieve all users.POST /users/: Create a new user.GET /users/{user_id}/: Retrieve a specific user.PUT /users/{user_id}/: Update a user.DELETE /users/{user_id}/: Delete a user.
GET /books/: Retrieve all books.POST /books/: Add a new book.GET /books/{book_id}/: Retrieve a specific book.PUT /books/{book_id}/: Update a book.DELETE /books/{book_id}/: Delete a book.
GET /loans/: Retrieve all loans.POST /loans/: Issue a new loan.PUT /loans/{loan_id}/: Return a loan.
Create a .env file in the root directory with the following variables:
DATABASE_URL=postgresql://username:password@localhost/dbnameRun the test suite using pytest:
pytestThis project is licensed under the MIT License. See the LICENSE file for details.