11 Star 72 Fork 21

FastAPI Practices/fastapi_sqlalchemy_mysql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

FastAPI SQLAlchemy MySQL

本地开发

  • Python 3.10+
  • Mysql 8.0+
  • Redis 推荐最新稳定版
  1. 安装依赖项

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

  3. 安装启动 Redis

  4. 进入 backend 目录

    cd backend
    
  5. 创建一个 .env 文件

    touch .env
    cp .env.example .env
    
  6. 按需修改配置文件 core/conf.py.env

  7. 数据库迁移 alembic

    # 生成迁移文件
    alembic revision --autogenerate
    
    # 执行迁移
    alembic upgrade head
    
  8. 启动 fastapi 服务

    # 帮助
    fastapi --help
    
    # 开发模式
    fastapi dev main.py
    
  9. 浏览器访问: http://127.0.0.1:8000/docs


Docker

  1. 进入 docker-compose.yml 文件所在目录,创建环境变量文件 .env

    cd deploy/docker-compose/
    
    cp .env.server ../../backend/.env
    
  2. 执行一键启动命令

    # 根据情况使用 sudo
    docker-compose up -d --build
    
  3. 等待命令自动完成

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

赞助

如果此项目能够帮助到你,你可以赞助作者一些咖啡豆表示鼓励: Sponsor

许可证

本项目根据 MIT 许可证的条款进行许可

MIT License Copyright (c) 2025 wu-clan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

fastapi + pydantic-v2 + sqlalchemy 2.0 + alembic + mysql + redis 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/fastapi-practices/fastapi_sqlalchemy_mysql.git
git@gitee.com:fastapi-practices/fastapi_sqlalchemy_mysql.git
fastapi-practices
fastapi_sqlalchemy_mysql
fastapi_sqlalchemy_mysql
master

搜索帮助