Git Product home page Git Product logo

fastapi_sqlalchemy_mysql's Introduction

FastAPI Project Demo

声明:此仓库仅做为 FastAPI 入门级参考, 开箱即用, 所有接口采用 restful 风格

📢 2022 年 10 月 29 日, 更新提醒:

  • 我想覆盖以前所有的提交, 这是一个让我难以决定的事实, 因为在所有功能的提交说明中, 有很多让 人们误解的东西, 对于关注提交信息的人来讲, 存在很多误导性, 并且我是一个高度强迫症患者, 我没有 理由拒绝此次决定
  • 将升级一些核心库: fastapi, pydantic, sqlalchemy... 为了保持兼容性, 你可能必须同步 仓库状态来保持他们的全局可用性
  • 对以前复刻,点星和下载的人们说声抱歉, 如果你直接使用它作为了基础开发环境, 那可能会对你造成 不必要的困扰, 我也不建议将它直接作为你的基础开发环境, 但是作为入门参考, 它应该会给你一些启发, 并且这也是此仓库的主要目的

🏁 我将在后面的空闲时间对现有维护分支进行逐一更新, 这可能是一个漫长的过程, 在分支完成更新前, 它的原有分支提交不会被覆盖, 仍然可以从中获取部分参考, 但作为旧的内容, 我个人不提倡; 在所有现有 维护分支更新完毕后, 考虑将它们以发版的形式作为初始标记, 预计年前完成🙏

分支说明

异步:

async -> master

fastapi + sqlalchemy + alembic + aiomysql + aioredis

📢: 含 redis 邮箱验证码登录

async -> async-APScheduler

fastapi + sqlalchemy + alembic + aiomysql + aioredis + APScheduler

📢: 在 master 分支基础上扩展, 加入 APScheduler 定时任务
✨: 删除了邮箱验证码登录, 新增了图片验证码登录
❗:很遗憾,此分支已停止维护,仅作为异步图形验证码登陆保留

async -> async-CRUDBase

fastapi + sqlalchemy + alembic + aiomysql + aioredis + APScheduler

📢: 在 master 分支基础上扩展,对普通 CRUD 操作进行封装,加入 APScheduler 定时任务

async -> async-Plus

fastapi + sqlalchemy + alembic + aiomysql + aioredis + APScheduler + pycasbin

📢: 在 async-CRUDBase 分支基础上扩展,加入 RBAC 鉴权

同步:

sync -> sync

fastapi + sqlalchemy + alembic + pymysql + redis

📢: 含 redis 图片验证码登录

sync -> sync-CRUDBase

fastapi + sqlalchemy + alembic + pymysql + redis + APScheduler

📢: 在 sync 分支基础上扩展,对普通 CRUD 操作进行封装,加入 APScheduler 定时任务

sync -> sync-Plus

fastapi + sqlalchemy + alembic + pymysql + redis + APScheduler + pycasbin

📢: 在 sync-CRUDBase 分支基础上扩展,加入 RBAC 鉴权

下载:

1. 克隆仓库

#全部分支:
git clone https://gitee.com/wu_cl/fastapi_sqlalchemy_mysql.git

#指定分支:
git clone -b 分支名 https://gitee.com/wu_cl/fastapi_sqlalchemy_mysql.git

2. 使用 CLI

跳转 Gitee

跳转 GitHub

安装使用:

⚠️: 此过程请格外注意端口占用情况, 特别是 8000, 3306, 6379...

1:传统

  1. 安装依赖

    pip install -r requirements.txt
  2. 创建数据库 fsm, 选择 utf8mb4 编码

  3. 查看 backend/app/core/conf.py 配置文件, 检查并修改数据库配置信息

  4. 执行数据库迁移 alembic

    cd backend/app/
    
    # 生成迁移文件
    alembic revision --autogenerate
    
    # 执行迁移
    alembic upgrade head
  5. 安装启动 redis

  6. 查看 backend/app/core/conf.py 配置文件, 检查并修改 redis 配置信息

  7. 执行 backend/app/main.py 文件启动服务

  8. 浏览器访问: http://127.0.0.1:8000/v1/docs


2:docker

  1. 在 docker-compose.yml 文件所在目录下执行一键启动命令

    docker-compose up -d --build
  2. 等待命令自动执行完成

  3. 浏览器访问: http://127.0.0.1:8000/v1/docs

初始化测试数据

执行 backend/app/init_test_data.py 文件

目录结构

结构树基本大致相同,详情请查看源代码

├── backend
│   └── app
│       ├── alembic
│       ├── api
│       │   └── v1
│       ├── common
│       ├── core
│       ├── crud
│       ├── database
│       ├── middleware
│       ├── models
│       ├── schemas
|       |—— static
│       ├── test
│       └── utils
├── LICENSE
├── README.md
└── requirements.txt

fastapi_sqlalchemy_mysql's People

Contributors

wu-clan avatar

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.