Skip to content

Releases: one-ccs/easy_fastapi

v1.0.0

Choose a tag to compare

@github-actions github-actions released this 06 Jul 15:08

easy_fastapi 1.0.0 — 分包重构 + 扩展化架构 + 脚手架 CLI

将原单体项目重构为双包 monorepo(uv workspace):

  • easy_fastapi:运行时库,扩展化 FastAPI 框架
  • easy_fastapi_cli:脚手架 CLI,一键生成 FastAPI 项目

核心架构

  • Extension 协议(config_model + init_app)+ ExtensionContext(provide/require)
  • EasyFastAPI 应用装配器(config → section → init_app + app.state 挂载)
  • 运行时可校验协议:Persistence / PasswordHasher / DbSession / AuthUser / ModelIntrospector
  • 配置系统:YAML 加载 + env overlay(EFA_ 前缀)+ 嵌套段 + 进程级缓存

ORM 扩展(tortoise / sqlalchemy / sqlmodel)

  • 各 ORM 独立 Extension(init_app + lifespan + session_factory)
  • build_uri 按 ORM×dialect URL 规则(Tortoise 两斜杠 vs SQLAlchemy 三斜杠)
  • ExtendedCRUD / Pagination / ModelIntrospector 通用能力
  • 删除框架内建 Repository/User 模型,改由扩展 provide 注入

其他扩展

  • auth:AuthExtension 类化 + TokenService(JWT access/refresh)+ OAuth2PasswordBearer + scope_match(any/all)
  • migration:aerich(tortoise) / alembic(sqlalchemy/sqlmodel) 分派
  • redis:RedisExtension + RedisPersistence(disabled 回退)
  • static:StaticExtension + 配置化挂载
  • i18n:core/i18n.py(contextvars + gettext)+ I18nExtension + Accept-Language 中间件 + 内嵌 msgfmt + CLI 插件

脚手架 CLI(efa)

  • create:交互向导(questionary)/ 全参数模式 → 选项校验(铁律 A/B/C)→ manifest → 落盘
  • run / db(init|migrate|upgrade|sync) / gen(introspector 驱动 CRUD 生成)
  • Fragment + Manifest 数据模型 + Renderer(Jinja2 StrictUndefined)
  • venv_bridge 转发层 + CLI 插件协议与发现注册器

前端模板(fullstack 模式)

  • pnpm workspace + admin 应用(Vue3 + Element Plus + vue-query + Pinia + vue-i18n)
  • api-sdk 包(@hey-api/openapi-ts 生成)

工程化

  • uv 管理依赖(非 pip)+ hatchling 构建 + .mo 构建钩子
  • 1349 测试全绿 + ruff lint
  • GitHub Actions:CI(lint + pytest 多版本矩阵)+ tag 触发 PyPI 发包(Trusted Publisher)

Full Changelog: v0.13.1...v1.0.0

0.13.1

Choose a tag to compare

@one-ccs one-ccs released this 13 Feb 06:35
  1. 修改文档
  2. 捕获 modify 业务逻辑 IntegrityError 异常

0.13.0

Choose a tag to compare

@one-ccs one-ccs released this 07 Feb 08:52

使用 FastAPI 依赖,实现基于 JWT 的 EasyAuthentication 用户身份验证扩展模块

示例:

from fastapi import FastAPI
from easy_fastapi.authentication import EasyAuthentication

app = FastAPI()
auth = EasyAuthentication(app)

@app.post('/logout')
@auth.require(require_refresh=True)
def logout():
    pass

@app.get('/user')
@auth.require
def user():
    return {'message': 'Hello, user!'}

@app.get('/admin')
@auth.require({'admin'})
def admin():
    return {'message': 'Hello, admin!'}

0.12.2

Choose a tag to compare

@one-ccs one-ccs released this 14 Jan 09:43
  1. 修复刷新令牌配置错误的问题
  2. 修复脚手架代码生成器导入错误

0.12.1

Choose a tag to compare

@one-ccs one-ccs released this 14 Jan 05:38
  1. 更新依赖
  2. 移除 persistence 条件导入
  3. 修改 token_type 为首字母大写
  4. 修改配置
  5. 完善测试

0.12.0 脚手架

Choose a tag to compare

@one-ccs one-ccs released this 13 Jan 09:59

重构代码逻辑,使用命令行初始化完整项目

部署

  1. 安装 pip install easy_fastapi
  2. 初始化 ​easy_fastapi init
  3. 切换工作目录 cd <项目名称>/backend
  4. 启动项目 easy_fastapi run --reload
  5. enjoy

开发

注:所有命令均在 <项目名称>/backend 目录中执行

  1. 修改 backend/app/easy_fastapi.yaml 中相关配置
  2. 添加或修改 backend.app.models 中的模型
  3. 运行 easy_fastapi gen 命令,使用代码生成器生成基本业务代码
  4. 创建数据库
  5. 初始化 Aerich 配置 easy_fastapi db init
  6. 初始化数据库 easy_fastapi db init-db