# fastapi-demo **Repository Path**: focnal/fastapi-demo ## Basic Information - **Project Name**: fastapi-demo - **Description**: fastapi常用CRUD示例备忘 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-07-15 - **Last Updated**: 2024-07-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Fastapi Demo 一个用于提供常用的CRUD操作的fastapi程序示例 ## 搭建环境 测试环境为`python 3.11.7` 建议在`venv`或者`conda`虚拟环境下使用 venv: ``` shell python -m venv ./venv ``` 安装依赖: ``` shell pip install fastapi uvicorn sqlalchemy aiomysql redis jinja2 ``` 如果官方源太慢, 你也可以在命令末尾加上`-i https://pypi.tuna.tsinghua.edu.cn/simple`参数来临时使用清华pypi镜像 ## 运行 请先激活虚拟环境, 以venv为示例 Bash 或 Zsh: ``` bash source ./venv/bin/activate ``` 或者简写为: ```bash . ./venv/bin/activate ``` Fish: ``` fish source bin/activate.fish ``` 在Windows中, 通过venv创建的虚拟环境激活执行文件不是放在`bin`中而是`Scripts`文件夹中 CMD: ``` cmd venv\Scripts\activate ``` Powershell: ``` powershell .\venv\Scripts\Activate.ps1 ``` ### 直接使用`python`命令行运行 参数可以在`main.py`中修改 ``` shell python ./main.py ``` ### 使用`uvicorn`运行 ``` shell uvicorn main:app --host 0.0.0.0 --port 9080 ```