Skip to main content

快速创建基于FastAPI的后端项目的脚手架工具

Project description

脚手架工具使用说明

scaffold.py 是一个用于快速创建基于FastAPI-Backend-Template的新项目的脚手架工具。

使用方法

基本用法

最简单的用法是直接运行脚本,使用默认配置:

python scaffold.py my-project

这将在当前目录下创建一个名为 my-project 的新项目。

命令行选项

脚手架工具支持以下命令行选项:

usage: scaffold.py [-h] [--db-user DB_USER] [--db-password DB_PASSWORD] [--db-name DB_NAME]
                  [--db-host DB_HOST] [--db-port DB_PORT] [--skip-venv] [--output-dir OUTPUT_DIR]
                  [project_name]

FastAPI Backend Template 脚手架工具

位置参数:
  project_name          项目名称 (默认: fastapi-backend)

可选参数:
  -h, --help            显示帮助信息并退出
  --db-user DB_USER     数据库用户名 (默认: root)
  --db-password DB_PASSWORD
                        数据库密码 (默认: password)
  --db-name DB_NAME     数据库名称 (默认: 项目名称转换为下划线形式)
  --db-host DB_HOST     数据库主机 (默认: localhost)
  --db-port DB_PORT     数据库端口 (默认: 3306)
  --skip-venv           跳过创建虚拟环境和安装依赖
  --output-dir OUTPUT_DIR
                        输出目录 (默认: 当前目录下以项目名称命名的文件夹)

示例

  1. 创建自定义数据库配置的项目:
python scaffold.py my-project --db-user myuser --db-password mypass --db-name custom_db
  1. 指定输出目录:
python scaffold.py --output-dir /path/to/projects/my-project
  1. 跳过虚拟环境创建:
python scaffold.py my-project --skip-venv

脚手架工具功能

脚手架工具执行以下操作:

  1. 复制模板文件到新的项目目录
  2. 更新项目名称和相关配置
  3. 创建包含随机生成密钥的.env配置文件
  4. 生成README.md文件
  5. 创建虚拟环境并安装依赖(除非指定--skip-venv)

项目结构

创建的项目具有以下结构:

my-project/
├── .env                # 环境变量配置
├── README.md           # 项目文档
├── backend/            # 后端代码
│   ├── app.py          # 应用入口点
│   ├── requirements.txt# 依赖列表
│   └── src/            # 源代码
│       ├── api/        # API路由与控制器
│       ├── config/     # 配置
│       ├── models/     # 数据模型
│       ├── repository/ # 数据库交互
│       ├── securities/ # 安全相关
│       └── utilities/  # 工具函数
└── venv/               # 虚拟环境 (如果未指定--skip-venv)

使用创建的项目

  1. 进入项目目录:

    cd my-project
    
  2. 激活虚拟环境:

    # Windows
    venv\Scripts\activate
    
    # Linux/Mac
    source venv/bin/activate
    
  3. 启动服务:

    cd backend
    python app.py
    
  4. 访问API文档:http://localhost:8000/docs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_backend_template-0.1.3.tar.gz (48.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_backend_template-0.1.3-py3-none-any.whl (68.0 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_backend_template-0.1.3.tar.gz.

File metadata

File hashes

Hashes for fastapi_backend_template-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7248f997ba322a1e2ea06ea0a9f0aee085ee2c48d2e95d22ade216eb78939881
MD5 2b5cf5beca4793e47eed7e0035d5c5b9
BLAKE2b-256 f9c233fc617a03b3534c748387527f922eee75b53d531a392c51d4de296cd6d4

See more details on using hashes here.

File details

Details for the file fastapi_backend_template-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_backend_template-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 765afc6c09bb5161980dd13244d3418948a603c88fb55a2f179511a15aced146
MD5 5b38fb118d5ccfdddda4176f88436b8c
BLAKE2b-256 d08a50c563c02eab02248b0c7529799e6ca9dd123c48328f2e98abf1c4f1aa78

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page