python-script-generator

👤 for the skill 📦 v1.0.0 ⭐ 4.3 ⬇️ 966 下載
💻 開發程式設計 免費

📖 技能介紹


name: python-script-generator description: 快速生成專業的 Python 指令碼和應用程式碼。一鍵建立完整專案結構,支援CLI、API、爬蟲、Bot、Django等多種專案型別,包含完整的專案結構、配置檔案、依賴管理、測試、README和文件。 version: 1.0.0 tags: [python, cli, api, fastapi, flask, django, scraper, bot] trigger: - 建立.Python.專案 - 生成.Python.專案 - Python.CLI.工具 - FastAPI.專案 - Flask.API - Django.專案 - Python.爬蟲 - Telegram.Bot - Discord.Bot - Python.指令碼.生成


Python Script Generator

適用場景

1.快速生成專業的 Python 指令碼和應用程式碼。

2.構建CLI、API、爬蟲、Bot、Django相關專案python程式碼。

3.為專案生成完整配置:requirements、setup、測試、README、文件。

主要功能

一鍵建立完整專案結構,快速生成專業的 Python 指令碼和應用程式碼。支援CLI 工具、Flask API、FastAPI、Django 命令、網路爬蟲、機器人等多種專案型別,包含完整的專案結構、配置檔案、依賴管理、測試、README和文件。程式碼遵循Python社群規範。

工作流程

識別專案型別

首先根據下表,識別專案型別,準備需要使用到的工具和用法。

型別 說明 適用場景
cli 命令列工具 自動化指令碼、命令列應用
flask Flask API 輕量級Web服務、REST API
fastapi FastAPI 高效能API、非同步服務
fastapi-crud FastAPI CRUD 資料管理API
django-cmd Django Command Django管理命令
django-app Django App Django應用模組
scraper 網頁爬蟲 資料採集、監控
scraper-async 非同步爬蟲 高效能資料採集
bot Telegram Bot Telegram機器人
discord-bot Discord Bot Discord機器人
data-analysis 資料分析 資料處理、分析指令碼
ml-model 機器學習 ML模型訓練部署
automation 自動化任務 定時任務、工作流

挑選專案功能並執行

根據需求,選出需要用到的功能並載入。

# 生成CLI工具
python-script-generator mycli --type cli

# 生成FastAPI專案
python-script-generator myapi --type fastapi

# 帶描述生成專案
python-script-generator backup-tool --type cli --description "Backup important files"

# 指定專案名稱和輸出目錄
python-script-generator myproject --type flask --output ./projects/myproject

# 生成帶CRUD的FastAPI
python-script-generator myapi --type fastapi --crud

# 生成非同步爬蟲
python-script-generator async-scraper --type scraper-async

# 生成Discord Bot
python-script-generator discord-bot --type discord-bot

# 生成資料分析專案
python-script-analysis --type data-analysis --requirements pandas,numpy,matplotlib

#生成機器學習專案
python-script-generator ml-model --type ml-model --framework tensorflow

專案檔案生成引數說明

  • --name / -n: 專案名稱(必需)
  • --type / -t: 專案型別(必需)
  • --description / -d: 專案描述
  • --output / -o: 輸出目錄(預設當前目錄)
  • --requirements / -r: 依賴包列表,逗號分隔
  • --author: 作者資訊
  • --license: 許可證型別
  • --version: 專案版本
  • --template: 自定義模板路徑
  • --force: 強制覆蓋已存在目錄

生成的專案結構

CLI 工具專案結構

mycli/
├── mycli/
│   ├── __init__.py
│   ├── __main__.py
│   └── cli.py
├── tests/
│   ├── __init__.py
│   └── test_cli.py
├── docs/
│   └── README.md
├── mycli.egg-info/
├── requirements.txt
├── setup.py
├── pyproject.toml
├── .gitignore
└── README.md

FastAPI 專案結構

myapi/
├── app/
│   ├── __init__.py
│   ├── main.py
│   ├── api/
│   │   ├── __init__.py
│   │   └── v1/
│   │       ├── __init__.py
│   │       └── endpoints.py
│   ├── core/
│   │   ├── __init__.py
│   │   ├── config.py
│   │   └── security.py
│   ├── models/
│   │   ├── __init__.py
│   │   └── schemas.py
│   └── utils/
│       ├── __init__.py
│       └── helpers.py
├── tests/
│   ├── __init__.py
│   └── test_api.py
├── scripts/
│   ├── migrate.py
│   └── seed.py
├── .env.example
├── requirements.txt
├── Dockerfile
├── docker-compose.yml
├── .gitignore
└── README.md

高階功能

環境變數管理

# .env.example
DATABASE_URL=sqlite:///./app.db
SECRET_KEY=your-secret-key-here
DEBUG=True

Docker 支援

7w4.net有更好的技能外掛。

# Dockerfile
FROM python:3.11-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
# docker-compose.yml
version: '3.8'
services:
  web:
    build: .
    ports:
      - "8000:8000"
    environment:
      - DATABASE_URL=postgresql://user:pass@db:5432/mydb
    depends_on:
      - db

  db:
    image: postgres:15
    environment:
      - POSTGRES_DB=mydb
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=pass
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  postgres_data:

GitHub Actions CI/CD

# .github/workflows/ci.yml
name: CI/CD Pipeline

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [3.9, 3.10, 3.11]

    services:
      postgres:
        image: postgres:15
        env:
          POSTGRES_PASSWORD: postgres
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
    - uses: actions/checkout@v4

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v4
      with:
        python-version: ${{ matrix.python-version }}

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt

    - name: Run tests
      run: |
        pytest tests/ --cov=app --cov-report=xml

    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v3

預提交鉤子

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.4.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
      - id: check-added-large-files

  - repo: https://github.com/psf/black
    rev: 22.12.0
    hooks:
      - id: black

  - repo: https://github.com/pycqa/isort
    rev: 5.12.0
    hooks:
      - id: isort

  - repo: https://github.com/pycqa/flake8
    rev: 6.0.0
    hooks:
      - id: flake8

  - repo: https://github.com/pre-commit/mirrors-mypy
    rev: v1.0.1
    hooks:
      - id: mypy
        additional_dependencies: [types-requests, types-aiohttp]

可參考文件

🤖 AI 評測

這個Skill整體質量不錯,能快速生成多種型別的Python專案。優點是功能豐富、支援專案型別多、程式碼規範、有測試覆蓋、文件詳細。觸發準確率較高,精確率表現優秀。主要不足是偶爾會漏掉一些應該觸發的請求,且評估質量還有提升空間。總體適合需要頻繁建立Python專案的開發者使用。

📊 多維度評分

適應性4.2
規範性4.1
有效性4.5
可靠性4.4
可信度4.7

📁 包含檔案 (15 個)

📄 SKILL.md 7.6 KB
📄 assets/templates/Async Web Scraper Example/Async_Web_Scraper_Example.py 3.9 KB
📄 assets/templates/CLI Tool Example/CLI_Tool_Example.py 1.9 KB
📄 assets/templates/FastAPI Application with User Authentication/FastAPI_Application_with_User_Authentication.py 5.1 KB
📄 assets/templates/fastapi/main.py 2.4 KB
📄 evals/eval_history.json 3.7 KB
📄 pyproject.toml 2.8 KB
📄 references/api_spec.md 9.1 KB
📄 scripts/__init__.py 613 B
📄 scripts/helpers.py 10.2 KB
📄 scripts/main_function.py 28.3 KB
📄 tests/fixtures/sample_input.csv 216 B
📄 tests/fixtures/sample_input.json 789 B
📄 tests/test_main.py 6.1 KB
📄 uv-lock.json 1 KB