Skip to content

arafatDU/fastapi-postgres-smart-library

Repository files navigation

FastAPI Postgres Smart Library System

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.

Features

  • 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.

Prerequisites

  • Python 3.8+
  • PostgreSQL
  • pip (Python package manager)

Installation

  1. Clone the repository:
git clone https://github.com/your-username/fastapi-postgres-smart-library.git
cd fastapi-postgres-smart-library
  1. Install uv package manager globally if not already installed:
pip install uv
  1. Configure the database:
  • Create a PostgreSQL database.
  • Update the DATABASE_URL in the .env file with your database credentials.
  1. Install project dependencies using uv:
uv install
  1. Run database migrations:
uv db upgrade
  1. Start the application:
uv run fastapi dev

API Endpoints

Users

  • GET /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.

Books

  • 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.

Loans

  • GET /loans/: Retrieve all loans.
  • POST /loans/: Issue a new loan.
  • PUT /loans/{loan_id}/: Return a loan.

Environment Variables

Create a .env file in the root directory with the following variables:

DATABASE_URL=postgresql://username:password@localhost/dbname

Running Tests

Run the test suite using pytest:

pytest

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

About

A Smart Library System, Monolithic to Microservices achitecture implementation with FastAPI and Postgres

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors