GithubHelp home page GithubHelp logo

bryannahabwe / fastapi_alchemy_auditing_demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dannielshalev/fastapi_alchemy_auditing_demo

0.0 0.0 0.0 5 KB

demo fastapi application with audit log writing postgrres DB

Python 100.00%

fastapi_alchemy_auditing_demo's Introduction

FastAPI SQLAlchemy Auditing Demo

This repository demonstrates a FastAPI application integrated with SQLAlchemy for database operations and includes auditing functionality to store request and response details.

Features

  • SQLAlchemy Integration: Utilizes SQLAlchemy for database operations, providing an efficient and scalable approach to interact with the database.

  • Middleware for Auditing: Implements FastAPI middleware to capture and store auditing information in the database for each incoming request.

Project Structure

The project is organized into the following modules and functions:

Modules

  1. database.py: Manages the database connection and includes the SQLAlchemy logic for interacting with the database.

  2. modules.py: Defines the database schema, including an example Audit table for storing auditing information.

Functions

  1. get_db: A FastAPI dependency that creates a new SQLAlchemy SessionLocal for each request and closes it once the request is completed.

  2. db_session_middleware: Middleware function executed for each request, capturing details both before and after the endpoint function is executed. It includes logic to store auditing information.

  3. store_audit: Function responsible for storing auditing information in the database.

How to Run

  1. Clone this repository:

    git clone https://github.com/dannielshalev/fastapi_alchemy_auditing_demo.git
    cd fastapi_alchemy_auditing_demo
    
  2. create virtualenv

virtualenv -v python3.x venv
  1. Install requierments.txt:
pip install -r requierments.txt

  1. Run app:
uvicorn main:app --reload --host 0.0.0.0 --port 8000

Installing and configure postgress section

install

sudo apt install postgresql

Configure

# go to os default posgress user
sudo su postgres

# enter DB

psql


#### create user
create user your-user with encrypted password 'your-password';

# grant perrmisions 
grant ALL ON DATABASE postgres to your-user ;

exit

fastapi_alchemy_auditing_demo's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.