This repository is myself FastAPI Template.
Help me improve development efficiency and learn English.
我的英文很差,有些地方还是会写中文的!
- SQLalchemy
- Docker support
- Friendly folder structure
- Vue3 support
- Use
loguru
to replaceuvicorn
default logging. - Support Oauth2 login.
use black as Python formater
pip install black
⚠ Modules uniformly use absolute /ˈæb.sə.luːt/
imports.
like from app.routers import HelloWorld
- app // Project root path
- routers // 路由 like vue components use 大写
- __init__.py
- index.py // handle `/` router
- user.py // handle `user` router
- database // database create/update/read/delete SQLAlchemy
- __init__.py
- model.py // database model 数据库模型
- curd.py // 数据库增改查删
- connect.py // 连接
- schemas /ˈskiː.mə/ n.图解.模式 // api response BaseModel API 数据模型
- __init__.py
- base.py
- user.py
- utils // 储存一些 helper funtion
- custom_log.py // custom loguru
- register // 储存一些注册到 APP 相关的东西
- __init__.py
- router.py // 路由
- middleware.py // 中间件
- exception.py // 异常
- cors.py // 跨域
- __init__.py // app 包入口
- main.py // 入口文件
- config.py // 配置
- logs // 日志文件夹
- pyproject.toml // 项目规范
- requirements.txt // 依赖
- Dockerfile
- README.md
python -m venv ./venv
# Open Powershell Limited
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# Activate
.\venv\Scripts\Activate.ps1
# update pip version
python -m pip install --upgrade pip
# install require model
pip install --upgrade -r requirements.txt --index-url=https://pypi.org/simple
uvicorn app.main:app --port 8000 --reload
or:
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
- FastAPI best practices https://github.com/zhanymkanov/fastapi-best-practices
- FastAPI offical document https://fastapi.tiangolo.com/
- Best Dockerfile: https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker
- 相似的项目,最棒的模仿 https://github.com/zxiaosi/vue3-fastapi/
- FastAPI with Async SQLAlchemy: https://github.com/rhoboro/async-fastapi-sqlalchemy/blob/main/app/db.py
- FastAPI SQLalchemy packaging 封装 https://stribny.name/blog/fastapi-asyncalchemy/
- FastAPI-TGDiceAPI myself: https://github.com/WhaleFell/FastAPI-TGDiceAPI
- code format black: https://muzing.top/posts/a29e4743/