semvec/pypi-packages huggingface dataset:
pgcr-auth 0.1.1
一个通用web权限框架，能够适配FastAPI等异步框架，也能够适配Flask等非异步框架
License: MIT
Requires Python: >=3.7,<4.0

# pgcr_auth
一个通用web权限框架，能够适配FastAPI等异步框架，也能够适配Flask等非异步框架

## 快速入门
### 基本使用
```python
from fastapi import FastAPI, Request
from pgcr_auth import *
from pgcr_fastapi_orm import *

db = Db("sqlite")
DATABASE_URL = db.database_url
SECRET = "SECRET"
metadata = db.metadata
database = db.database


class UserModel(UserModel):  # 必须要重写用户模型，指定数据库连接
    class Meta:
        tablename = "users"
        metadata = metadata
        database = database


engine = db.engine
metadata.create_all(engine)  # 创建数据库表
user_db = OrmarUserDatabase(UserDB, UserModel)  # 创建用户db对象

app = FastAPI()
app = register_auth(app, SECRET, user_db)
app.state.database = database


@app.on_event("startup")
async def startup() -> None:
    database_ = app.state.database
    if not database_.is_connected:
        await database_.connect()


@app.on_event("shutdown")
async def shutdown() -> None:
    database_ = app.state.database
    if database_.is_connected:
        await database_.disconnect()


if __name__ == '__main__':
    import uvicorn

    uvicorn.run("example:app", reload=True)
```