English | 简体中文
This is a base project of the FastAPI framework, in production
It‘s purpose is to allow you to develop your project directly with it as your base project
Support python3.10 and above
- FastAPI
- Pydantic
- SQLAlchemy
- Alembic
- MySQL
- Redis
- APScheduler
- Docker
git clone https://github.com/wu-clan/fastapi_best_architecture.git-
Install dependencies
pip install -r requirements.txt
-
Create a database
fba, choose utf8mb4 encode -
Install and start Redis
-
create a
.envfile in thebackend/app/directorycd backend/app/ touch .env -
Copy
.env.exampleto.envand viewbackend/app/core/conf.py, update database configuration information -
Perform a database migration alembic
cd backend/app/ # Generate the migration file alembic revision --autogenerate # Perform the migration alembic upgrade head
-
Execute the
backend/app/main.pyfile startup service -
Browser access: http://127.0.0.1:8000/v1/docs
-
Run the one-click start command in the directory where the
docker-compose.ymlfile is locateddocker-compose up -d --build
-
Wait for the command to finish automatically
-
Browser access: http://127.0.0.1:8000/v1/docs
Execute the backend/app/init_test_data.py file
Perform tests via pytest
Tip: Before the test starts, please execute init the test data first, also, the fastapi service needs to be started
-
First, go to the app directory
cd backend/app/ -
Execute the test command
pytest -vs --disable-warnings