fastbase


Namefastbase JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/enchance/fastbase.git
Summary
upload_time2023-12-29 12:51:31
maintainer
docs_urlNone
authorenchance
requires_python>=3.11,<4.0
licenseMIT
keywords firebase fastapi sqlmodel authentication api rest
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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')
```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/enchance/fastbase.git",
    "name": "fastbase",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11,<4.0",
    "maintainer_email": "",
    "keywords": "firebase,fastapi,sqlmodel,authentication,api,rest",
    "author": "enchance",
    "author_email": "enchance@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/40/07/c62fe6c949b60dc111779a33f3d3cfbb2aec6ad06dfb9e42c6a2d624cb5d/fastbase-0.4.0.tar.gz",
    "platform": null,
    "description": "Fastbase\n=============\n\n**DEV MESSAGE: Fastbase is currently still in development and in its current state is unfit for production. Check \nback again for updates.**\n\nRole-based Access Contral (RBAC) via Firebase `idtoken` authententication using FastAPI and SQLModel.\n\nDocumentation: https://enchance.github.io/fastbase/class/fastbase/\n\n\nInstallation\n-----------\n\n```bash\npip install fastbase\n```\n\nor\n```bash\npoetry add fastbase\n```\n\n\nOverview\n----------------\n\nFastbase assumes a headless setup using a frontend such as React, Angular, etc.\n\n- **API Endpoints:** Managed by FastAPI\n- **Authentication:** Managed by Firebase Auth\n- **Authorization:** Managed by Fastbase\n- **Database ORM:** SQLModel\n\n### Fastbase process\n\n1. Authentication happens in the frontend (JS) using the official Firebase JS package. An `idtoken` will be \n   generated if successful.\n1. Insert this token in your `Authorization` header (`Bearer <idtoken>`) when hitting restricted APIs.  \n1. Upon reaching the server the `idtoken` is verified.\n\n\nEndpoints\n-----------------------------------------\nTo follow\n\n\nDependencies\n-----------------------------------------\nTo follow\n\n\nSample Code\n-----------------------------------------\n\n### models.py\nYour required `User` model. Optional models include `TaxonomyMod` and `OptionMod` which should be extended if you want \nto use them. Add any additional fields you need.\n\n```python\nfrom fastbase.models import UserMod, TaxonomyMod, OptionMod \n\n# Required\nclass User(UserMod, table=True):\n    __tablename__ = 'auth_user'\n    # Add any fields and methods you need\n\n    \n# Optional\nclass Taxonomy(TaxonomyMod, table=True):\n   __tablename__ = 'app_taxonomy'\n   # Add any fields and methods you need\n\n\n# Optional\nclass Option(OptionMod, table=True):\n   __tablename__ = 'app_option'\n   # Add any fields and methods you need\n```\n\n### main.py\nInitialize Fastbase\n\n```python\nfrom sqlalchemy.ext.asyncio import create_async_engine\nfrom fastapi import FastAPI\nfrom fastbase import Fastbase\nfrom contextlib import asynccontextmanager\n\nfrom .models import User\n\n# .env file\nDATABASE_URL = 'postgresql+asyncpg://user:password@localhost:5432/dbname'\n\n# DB engine\nengine = create_async_engine(DATABASE_URL, echo=True, pool_size=10)\n\n@asynccontextmanager\nasync def lifespan(_: FastAPI):\n   \"\"\"Insert in lifespan events on start: https://fastapi.tiangolo.com/advanced/events/\"\"\"\n   fbase = Fastbase()\n   fbase.initialize(engine=engine, user_model=User)\n   print('RUNNING')\n   yield\n   print('STOPPED')\n```",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "",
    "version": "0.4.0",
    "project_urls": {
        "Homepage": "https://github.com/enchance/fastbase.git",
        "Repository": "https://github.com/enchance/fastbase.git"
    },
    "split_keywords": [
        "firebase",
        "fastapi",
        "sqlmodel",
        "authentication",
        "api",
        "rest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "849608c2fb90a2df83ac388c20bebcd9baf9ca31fb7017458e2dd97f9f058042",
                "md5": "6b4766cd5f800934a18d5b616c076777",
                "sha256": "7208cc24cfc80a0cc2bd140ec8a00ed705f2db2497ab75e62301c4ef4775e54b"
            },
            "downloads": -1,
            "filename": "fastbase-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6b4766cd5f800934a18d5b616c076777",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11,<4.0",
            "size": 12955,
            "upload_time": "2023-12-29T12:51:29",
            "upload_time_iso_8601": "2023-12-29T12:51:29.588901Z",
            "url": "https://files.pythonhosted.org/packages/84/96/08c2fb90a2df83ac388c20bebcd9baf9ca31fb7017458e2dd97f9f058042/fastbase-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4007c62fe6c949b60dc111779a33f3d3cfbb2aec6ad06dfb9e42c6a2d624cb5d",
                "md5": "0753af0083f32876e9dab98caccbbde1",
                "sha256": "c8ca010947613bda21d10fde68a1b4916b421d137b4d36a8133677cb180660b9"
            },
            "downloads": -1,
            "filename": "fastbase-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0753af0083f32876e9dab98caccbbde1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11,<4.0",
            "size": 10430,
            "upload_time": "2023-12-29T12:51:31",
            "upload_time_iso_8601": "2023-12-29T12:51:31.628445Z",
            "url": "https://files.pythonhosted.org/packages/40/07/c62fe6c949b60dc111779a33f3d3cfbb2aec6ad06dfb9e42c6a2d624cb5d/fastbase-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-29 12:51:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "enchance",
    "github_project": "fastbase",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "fastbase"
}
        
Elapsed time: 0.17854s