# fastapi-tutorial **Repository Path**: caijianwei01/fastapi-tutorial ## Basic Information - **Project Name**: fastapi-tutorial - **Description**: FastAPI核心知识点练习 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2021-07-07 - **Last Updated**: 2023-02-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # FastAPI框架 --- ## 一、环境创建 ### 1.1、创建虚拟环境(默认使用系统的版本,也可以指定版本) 1. 进入项目根目录下,创建虚拟环境执行命令:virtualenv venv(虚拟环境名称) 2. 进入目录:cd venv/Scripts, 激活虚拟环境:activate.bat 文件路径最前面显示(venv),那么虚拟环境就激活成功了 3. 更新pip: python.exe -m pip install --upgrade pip 4. 切换到根目录:cd ../../, 安装所有需要的包:pip install -r requirements.txt ### 1.2、pip常用命令使用 * 导出虚拟环境安装包:pip freeze > requirements.txt * 在其它虚拟环境安装requirements.txt文件中的包: pip install -r requirements.txt ### 1.3、安装包 安装所有的可选依赖及对应功能,当前所使用的fastapi最新版本0.66 `pip install fastapi[all]` 官方文档支持的类型:[https://pydantic-docs.helpmanual.io/usage/types/](https://pydantic-docs.helpmanual.io/usage/types/) Pycharm可以安装Pydantic插件 File -> settings -> Plugins 选择Marketplace 输入 Pydantic进行搜索安装 ## 二、需要额外安装的包 没有安装所有依赖,使用以下功能,需要额外安装包 - 邮箱格式检查EmailStr:`pip install pydantic[email]` - 表单数据处理Form:`pip install python-multipart` - 生成和校验 JWT 令牌:`pip install python-jose[cryptography]` - 哈希并校验密码:`pip install passlib[bcrypt]` - 邮件发送:`pip install emails` ## 三、SQLAlchemy教程 - 1、SQLAlchemy的基本操作大全 http://www.taodudu.cc/news/show-175725.html - 2、Python3+SQLAlchemy+Sqlite3实现ORM教程 https://www.cnblogs.com/jiangxiaobo/p/12350561.html - 3、SQLAlchemy基础知识 Autoflush和Autocommit https://zhuanlan.zhihu.com/p/48994990