Giter VIP home page Giter VIP logo

fastbase's Introduction

Fastbase

DEV MESSAGE: Fastbase is currently still in development and in its current state is unfit for production. Check back again for updates.

Role-based Access Contral (RBAC) via Firebase idtoken authententication using FastAPI and SQLModel.

Documentation: https://enchance.github.io/fastbase/class/fastbase/

Installation

pip install fastbase

or

poetry add fastbase

Overview

Fastbase assumes a headless setup using a frontend such as React, Angular, etc.

  • API Endpoints: Managed by FastAPI
  • Authentication: Managed by Firebase Auth
  • Authorization: Managed by Fastbase
  • Database ORM: SQLModel

Fastbase process

  1. Authentication happens in the frontend (JS) using the official Firebase JS package. An idtoken will be generated if successful.
  2. Insert this token in your Authorization header (Bearer <idtoken>) when hitting restricted APIs.
  3. Upon reaching the server the idtoken is verified.

Endpoints

To follow

Dependencies

To follow

Sample Code

models.py

Your required User model. Optional models include TaxonomyMod and OptionMod which should be extended if you want to use them. Add any additional fields you need.

from fastbase.models import UserMod, TaxonomyMod, OptionMod 

# Required
class User(UserMod, table=True):
    __tablename__ = 'auth_user'
    # Add any fields and methods you need

    
# Optional
class Taxonomy(TaxonomyMod, table=True):
   __tablename__ = 'app_taxonomy'
   # Add any fields and methods you need


# Optional
class Option(OptionMod, table=True):
   __tablename__ = 'app_option'
   # Add any fields and methods you need

main.py

Initialize Fastbase

from sqlalchemy.ext.asyncio import create_async_engine
from fastapi import FastAPI
from fastbase import Fastbase
from contextlib import asynccontextmanager

from .models import User

# .env file
DATABASE_URL = 'postgresql+asyncpg://user:password@localhost:5432/dbname'

# DB engine
engine = create_async_engine(DATABASE_URL, echo=True, pool_size=10)

@asynccontextmanager
async def lifespan(_: FastAPI):
   """Insert in lifespan events on start: https://fastapi.tiangolo.com/advanced/events/"""
   fbase = Fastbase()
   fbase.initialize(engine=engine, user_model=User)
   print('RUNNING')
   yield
   print('STOPPED')

fastbase's People

Contributors

enchance avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

piehtvh

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.