Metadata-Version: 2.1
Name: fastbase
Version: 0.4.0
Summary: 
Home-page: https://github.com/enchance/fastbase.git
License: MIT
Keywords: firebase,fastapi,sqlmodel,authentication,api,rest
Author: enchance
Author-email: enchance@gmail.com
Requires-Python: >=3.11,<4.0
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Database
Classifier: Topic :: Database :: Database Engines/Servers
Classifier: Topic :: Internet
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Typing :: Typed
Requires-Dist: arrow (>=1.3.0,<2.0.0)
Requires-Dist: fastapi (>=0.104.1,<0.105.0)
Requires-Dist: firebase-admin (>=6.3.0,<7.0.0)
Requires-Dist: icecream (>=2.1.3,<3.0.0)
Requires-Dist: pydantic (>=1.9.0,<2.0.0)
Requires-Dist: redis-om (>=0.2.1,<0.3.0)
Requires-Dist: sqlmodel (>=0.0.12,<0.0.13)
Project-URL: Repository, https://github.com/enchance/fastbase.git
Description-Content-Type: text/markdown

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

```bash
pip install fastbase
```

or
```bash
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.
1. Insert this token in your `Authorization` header (`Bearer <idtoken>`) when hitting restricted APIs.  
1. 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.

```python
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

```python
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')
```
