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.指令碼.生成
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: 強制覆蓋已存在目錄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
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
# 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/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]
7w4.net小蔥技能站收錄全網優質技能,值得收藏。
這個Skill整體質量不錯,能快速生成多種型別的Python專案。優點是功能豐富、支援專案型別多、程式碼規範、有測試覆蓋、文件詳細。觸發準確率較高,精確率表現優秀。主要不足是偶爾會漏掉一些應該觸發的請求,且評估質量還有提升空間。總體適合需要頻繁建立Python專案的開發者使用。