# fastapi-study:开箱即用的异步FastApi模板 **Repository Path**: ai-code-studio/fastapi-study ## Basic Information - **Project Name**: fastapi-study:开箱即用的异步FastApi模板 - **Description**: 开箱即用的异步FastApi模板,包含:数据库使用sqlalchemy的异步方法、数据库迁移、用户注册、登陆、Token验证等功能 - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2024-04-11 - **Last Updated**: 2024-04-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # **FastApi** asynchronous templates out of the box ### introduced #### This is a FastApi asynchronous templates out of the box, based on FastApi and SQLAlchemy asynchronous API projects, integrating common dependencies and configurations for rapid development. This template is only for learning and communication. The actual use should be developed according to the needs. #### Projects written using this template: https://gitee.com/Ghyan/0207-2024 ## 1、project structure ```markdown |----.cache\ # Python compile cache | |----v\ | | |----cache\ | | | |----lastfailed |----alembic\ # Database Migration Directory | |----versions\ | | |----64ac9a7455db_uuid.py | | |----b88837b0e2ba_uuid.py | |----env.py | |----README | |----script.py.mako |----api\ # Api routing directory | |----users\ | | |----user.py |----db\ # database directory | |----__init__.py | |----crud.py # database operations | |----database.py # Database Connection | |----models.py # Data model | |----run.py # Database migration script | |----schema.py # Data Table Structure |----static\ # Static file directory | |----css\ | |----js\ | |----favicon.png |----test\ # Unit Test Catalog | |----__init__.py | |----test_users.py |----utils\ # Tools/Dependency Catalog | |----jwt_token.py # JWT Token Generation and Decryption Tools |----alembic.ini # Alembic configuration file |----app.py # Application startup file |----main.py # Application entry file |----README.md # Project Description Document |----requirements.txt # Project Dependency List ``` ## 2、environment configuration installation dependency ```python python>=3.10 # Update pip version (must update) pip install --upgrade pip # installation dependency pip install -r requirements.txt ``` create database(mysql) ```mysql # Enter in the terminal mysql mysql -uyou_name -pyou_password 例:mysql -uroot -p123456 # Creating database CREATE DATABASE database_name DEFAULT CHARSET utf8 COLLATE utf8_general_ci; 例:CREATE DATABASE fastapi DEFAULT CHARSET utf8 COLLATE utf8_general_ci; ``` migration database(generation table) ```cmd # Modify your database connection information in db/database.py file # Modify your database connection information in the alembic.ini file (line 63) # First, enter the following command on the terminal. You can write your own notes here for "init" alembic revision --autogenerate -m "init" # Continue to input alembic upgrade head ``` ## 3、run ```python python3 app.py # The default port is 8000, which can be modified in the app.py file # Testing with API tools, such as Postman # User Registration Routing http://127.0.0.1:8000/user/register # User login routing http://127.0.0.1:8000/user/login # User update message routing http://127.0.0.1:8000/user/update # User logout routing (delete user) http://127.0.0.1:8000/user/delete # Query all user information routes http://127.0.0.1:8000/user/select_all # Verify token routing http://127.0.0.1:8000/user/token ``` *to be continued......*