一键导入
tech-stack-python
Provides Python-specific build commands, test commands, ORM guidance, framework patterns, and reference file paths for workflow skills.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Provides Python-specific build commands, test commands, ORM guidance, framework patterns, and reference file paths for workflow skills.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Corrective batch of multiple small independent fixes (apply review findings, several/multiple fixes across >3 files, no new contract or architecture) — broader than fix, lighter than implement.
One-time repo setup that detects tech stack, audits the codebase, pulls coding guidelines, and generates a project-specific CLAUDE.md
Full feature implementation loop orchestrating planning, batching, verification, and review skills
Use when the task is a new feature, breaking change, multi-file change, or any work where approval should happen before coding begins.
Use to create, update, and read durable workflow state under .mtk/workflows/ so orchestration survives compaction, crash, and session handoff.
Use after a spec is approved and before multi-file implementation begins, to break work into verifiable batches with checkpoints.
| name | tech-stack-python |
| description | Provides Python-specific build commands, test commands, ORM guidance, framework patterns, and reference file paths for workflow skills. |
| license | MIT |
| compatibility | ["claude-code","codex"] |
| trigger | tech-stack-context |
| skip_when | never-skip-when-active-stack |
| type | tech-stack |
| user-invocable | false |
This tech stack skill provides Python-specific context for the generic workflow skills (spec-driven-development, incremental-implementation, test-driven-development) and for review agents. It is loaded when .claude/tech-stack contains python.
Loaded automatically by commands and skills when the active tech stack is python. Not invoked directly.
Python is interpreted, so there's no separate compile step. Use type checking and tests as your verification gates.
mypy . or pyright (whichever the project uses)pytest <path/to/module> or pytest -k <pattern>pytestruff format <path> (or black <path> if the project uses black). The PostToolUse hook is wired through hooks/format-on-edit.sh, which extracts tool_input.file_path from stdin JSON. Do NOT use $CLAUDE_FILE — it is not a Claude Code env var.ruff check <path> (or flake8 / pylint per project)If the project uses tox, the full test command is tox. If Poetry: poetry run pytest. If a Makefile or justfile exists, prefer the project-defined targets (make test, just test).
How setup-bootstrap detects this stack in a repository:
| Marker | Confidence |
|---|---|
pyproject.toml | High |
setup.py or setup.cfg | High |
requirements.txt | Medium |
Pipfile or poetry.lock | High |
.python-version | Low (supplemental) |
Detection command:
find . -maxdepth 2 \( -name "pyproject.toml" -o -name "setup.py" -o -name "requirements.txt" -o -name "Pipfile" \) 2>/dev/null | head -3
SQLAlchemy rules (when SQLAlchemy is detected):
select() (SQLAlchemy 2.0 style) over the legacy Query API.expire_on_commit=False or detached sessions to avoid unnecessary lazy-load round trips.joinedload or selectinload explicitly. Implicit lazy loading is a common N+1 source.with session.begin(): or explicit transaction boundaries for writes.Session.execute(select(...)) returning DTOs, not full ORM objects, when you only need projection.Django ORM rules (when Django is detected):
select_related (foreign keys) and prefetch_related (many-to-many, reverse foreign) to avoid N+1.transaction.atomic()..values() or .values_list() for read-only projections..all() without filters in production paths — pagination required.Test provider rules:
testcontainers-python or a real test database when database semantics matter.--keepdb or pytest-django with a real Postgres test database for integration suites.Reference: .claude/references/python/sqlalchemy-checklist.md
FastAPI (when detected):
Depends() for dependency injection (DB sessions, auth, settings)./api/v1/....Django (when detected):
request.POST access in business logic.Reference: .claude/references/python/fastapi-patterns.md
pytest parametrize for edge cases.TestClient or Django Client / DRF APIClient.conftest.py) for shared setup. Prefer factory_boy or pytest-factoryboy for test data.Path: .claude/references/python/coding-guidelines.md
Source: To be authored when the team starts its first Python project. The placeholder file lists the structure to follow. PEP 8 + ruff defaults are a reasonable starting point.
Key conventions to start with (until guidelines are written):
ruff format or blackfrom x import *)snake_case for variables/functions, PascalCase for classes, SCREAMING_SNAKE for constants.format() or % formattingpathlib.Path over os.path for new codeSee .claude/references/python/analyzer-config.md for recommended ruff rules and mypy strict settings.
Lint with analyzer capture:
ruff check --output-format json . | hooks/parse-build-diagnostics.sh --format ruff > .mtk/analyzer-output.json
See docs/recommended-tooling/python.md for MCP servers, plugins, and editor integrations that noticeably improve Claude Code productivity on Python projects — notably context7 (current framework docs), Pyright/basedpyright LSP, and Ruff LSP. Paired with the stack-agnostic docs/recommended-tooling/shared.md. setup-bootstrap prints both during onboarding; install is manual.
These files are loaded by commands and review agents when the active stack is python:
.claude/references/python/coding-guidelines.md — Python style guide (placeholder until written).claude/references/python/sqlalchemy-checklist.md — SQLAlchemy review and implementation checklist.claude/references/python/fastapi-patterns.md — FastAPI/Django patterns.claude/references/python/testing-supplement.md — pytest patterns, fixtures, mocking.claude/references/python/performance-supplement.md — async, connection pooling, profiling.claude/references/python/analyzer-config.md — recommended ruff rules and mypy strict settingsdocs/recommended-tooling/python.md — Recommended MCPs / plugins / editor integrations for PythonMerge these into the project's .claude/settings.json during setup-bootstrap:
Bash(python:*)Bash(python3:*)Bash(pytest:*)Bash(mypy:*)Bash(ruff:*)Bash(black:*)Bash(poetry:*)Bash(pip:*)Bash(tox:*)Read(**/.env.production)Read(**/secrets.yaml)Edit|Writebash $CLAUDE_PLUGIN_ROOT/hooks/format-on-edit.shThe matcher field accepts a regex on tool name only — Write(*.py) is NOT valid Claude Code syntax and will silently never fire. File-extension dispatch happens inside format-on-edit.sh.
# Wired via PostToolUse hook (see Settings Additions above):
bash $CLAUDE_PLUGIN_ROOT/hooks/format-on-edit.sh
# Manual invocation:
ruff format <file> && ruff check --fix <file> # or black <file>
The wrapper picks ruff → black based on what's installed. Failures log to stderr but never block the edit.
Conditional, tool-keyed items for the generated pre-commit-review-list.md.
setup-bootstrap selects items whose trigger tool was detected in the scan,
adds the three stack-agnostic always-include items, and caps the list at 10.
select_related/prefetch_related, transaction.atomicThese bash commands are used by setup-audit.md when auditing a Python repository.
Before planning the install of any PyPI package not already in requirements.txt / pyproject.toml — especially one recommended by an AI assistant, blog post, or research brief — verify it exists and is the real package (criterion 0 of .claude/references/dependency-intake-checklist.md):
pip index versions <pkg>
A package not found, or one whose name closely resembles a popular package with different scope (typosquat signal), is an immediate block. planning-and-task-breakdown tags an unverified AI-recommended package [ASSUMED] and inserts a checkpoint:human-verify step before any install.
# Project metadata
find . -maxdepth 2 \( -name "pyproject.toml" -o -name "setup.py" -o -name "setup.cfg" \) 2>/dev/null
find . -maxdepth 2 \( -name "requirements*.txt" -o -name "Pipfile" -o -name "poetry.lock" \) 2>/dev/null
# Python version
cat .python-version 2>/dev/null
grep -E "python_requires|python =" pyproject.toml setup.py setup.cfg 2>/dev/null | head -5
# Top-level packages
find . -maxdepth 3 -name "__init__.py" -not -path "*/.venv/*" -not -path "*/venv/*" -not -path "*/site-packages/*" | head -20
# Folder structure
find . -type d -maxdepth 3 -not -path "*/.venv/*" -not -path "*/venv/*" -not -path "*/__pycache__/*" -not -path "*/.git/*" -not -path "*/node_modules/*" | sort
# Web framework
grep -rl "from fastapi\|import fastapi" --include="*.py" | head -10
grep -rl "from django\|django.urls\|django.db.models" --include="*.py" | head -10
grep -rl "from flask\|import flask" --include="*.py" | head -10
# ORM
grep -rl "from sqlalchemy\|sqlalchemy.orm\|sqlalchemy.ext" --include="*.py" | head -10
grep -rl "models.Model\|django.db" --include="*.py" | head -10
# Validation
grep -rl "from pydantic\|BaseModel\|pydantic.Field" --include="*.py" | head -10
grep -rl "marshmallow\|Schema" --include="*.py" | head -10
# Async
grep -rl "async def\|await\|asyncio" --include="*.py" | head -10
# Type checking
find . \( -name "mypy.ini" -o -name "pyrightconfig.json" \) 2>/dev/null
grep -E "mypy|pyright" pyproject.toml setup.cfg 2>/dev/null | head -5
# SQLAlchemy patterns
grep -rl "declarative_base\|DeclarativeBase\|Mapped\[" --include="*.py" | head -5
grep -rl "session.execute\|session.query\|select(" --include="*.py" | head -5
# Migrations
find . -name "alembic.ini" 2>/dev/null
find . -path "*/migrations/*" -name "*.py" -not -path "*/.venv/*" | head -10
# Django ORM patterns
grep -rl "select_related\|prefetch_related" --include="*.py" | head -5
grep -rl "transaction.atomic" --include="*.py" | head -5
# N+1 risks
grep -rn "lazy=" --include="*.py" | head -5
# Connection management
grep -rn "create_engine\|sessionmaker\|SessionLocal" --include="*.py" | head -5
# AWS / cloud SDKs
grep -rl "import boto3\|from boto3" --include="*.py" | head -10
# Lambda handlers
grep -rl "def lambda_handler\|def handler" --include="*.py" | head -5
# Docker
find . \( -name "Dockerfile" -o -name "docker-compose*" -o -name ".dockerignore" \)
# IaC
find . \( -name "*.tf" -o -name "serverless.yml" -o -name "cdk.json" \) 2>/dev/null | head -10
# Messaging
grep -rl "celery\|kafka\|rabbitmq\|redis" --include="*.py" | head -10
# Secrets
grep -rl "boto3.client('secretsmanager')\|hvac\|os.environ" --include="*.py" | head -5
# Sample router/view files
find . \( -name "*router*.py" -o -name "*views*.py" \) -not -path "*/.venv/*" | head -10
find . -name "*handler*.py" -not -path "*/.venv/*" -not -path "*test*" | head -10
# Sample model files
find . \( -name "models.py" -o -name "*model*.py" \) -not -path "*/.venv/*" -not -path "*test*" | head -10
# Test framework
grep -rl "import pytest\|from pytest" --include="*.py" | head -5
grep -rh "pytest\|tox" pyproject.toml setup.cfg requirements*.txt 2>/dev/null | sort -u
# Test organization
find . -path "*test*" -name "*.py" -not -path "*/.venv/*" -not -path "*/__pycache__/*" | head -20
# Fixtures
find . -name "conftest.py" -not -path "*/.venv/*" | head -10
# Mocking
grep -rl "from unittest.mock\|import mock\|pytest_mock\|monkeypatch" --include="*.py" | head -5
# Test data factories
grep -rl "factory_boy\|FactoryBoy\|pytest_factoryboy" --include="*.py" | head -5
# Test database
grep -rl "testcontainers\|pytest-django\|pytest-postgresql" --include="*.py" | head -5
# Settings / config
grep -rl "from pydantic_settings\|BaseSettings\|os.environ.get" --include="*.py" | head -10
find . \( -name "settings.py" -o -name "config.py" -o -name ".env.example" \) -not -path "*/.venv/*" | head -10
# Logging
grep -rl "import logging\|getLogger\|loguru\|structlog" --include="*.py" | head -10
.claude/tech-stack contains python## Reference Files