AgentSkillsCN

mastering-python-skill

现代Python辅导课程,从语言基础到高级生产级编程模式一应俱全。当被要求“编写Python代码”、“解释Python概念”、“搭建Python项目”、“配置Poetry或PDM”、“编写pytest测试”、“创建FastAPI端点”、“运行uvicorn服务器”、“配置Alembic迁移”、“设置日志记录”、“用pandas处理数据”或“调试Python错误”时,可使用此技能。可通过“Python最佳实践”、“类型提示”、“异步Python”、“打包”、“虚拟环境”、“Pydantic校验”、“依赖注入”、“SQLAlchemy模型”等触发。

SKILL.md
--- frontmatter
name: mastering-python-skill
description: Modern Python coaching covering language foundations through advanced production patterns. Use when asked to "write Python code", "explain Python concepts", "set up a Python project", "configure Poetry or PDM", "write pytest tests", "create a FastAPI endpoint", "run uvicorn server", "configure alembic migrations", "set up logging", "process data with pandas", or "debug Python errors". Triggers on "Python best practices", "type hints", "async Python", "packaging", "virtual environments", "Pydantic validation", "dependency injection", "SQLAlchemy models".
allowed-tools:
  - Read
  - Write
  - Bash
  - Edit
metadata:
  version: 2.1.0
  domains:
    - python
    - testing
    - packaging
    - web-development
    - async
    - security

Mastering Python Skill

Production-ready Python patterns with runnable code examples.

Contents


Workflow

Phase 1: Setup

  1. Verify Python version

    bash
    python --version  # Require 3.10+, prefer 3.12+
    
  2. Create and activate virtual environment

    bash
    python -m venv .venv && source .venv/bin/activate
    
  3. Install dependencies

    bash
    poetry install  # or: pip install -r requirements.txt
    

Phase 2: Develop

  1. Reference appropriate patterns:

  2. Follow project structure from project-structure.md

Phase 3: Validate

  1. Run quality checks

    bash
    ruff check . && ruff format --check .
    mypy src/
    
  2. Run tests with coverage

    bash
    pytest -v --cov=src --cov-report=term-missing
    

Phase 4: Deploy

  1. Build and verify package

    bash
    python -m build && twine check dist/*
    
  2. Deploy per docker-deployment.md or ci-cd-pipelines.md

Pre-Completion Checklist:

code
- [ ] All tests pass
- [ ] mypy reports no errors
- [ ] ruff check clean
- [ ] Coverage ≥80%
- [ ] No security warnings in dependencies

Reference Files

CategoryFilesKey Topics
Foundationssyntax-essentials, type-systems, project-structure, code-qualityVariables, type hints, generics, src layout, ruff, mypy
Patternsasync-programming, error-handling, decorators, context-managers, generatorsasync/await, exceptions, Result type, with statements, yield
Testingpytest-essentials, mocking-strategies, property-testingFixtures, parametrize, unittest.mock, Hypothesis
Web APIsfastapi-patterns, pydantic-validation, database-accessDependencies, middleware, validators, SQLAlchemy async
Packagingpoetry-workflow, pyproject-config, docker-deploymentLock files, PEP 621, multi-stage builds
Productionci-cd-pipelines, monitoring, securityGitHub Actions, OpenTelemetry, OWASP, JWT

See TOC.md for detailed topic lookup.


Sample CLI Tools

Runnable examples demonstrating production patterns:

ToolDemonstratesReference
async_fetcher.pyAsync HTTP, rate limiting, error handlingasync-programming.md
config_loader.pyPydantic settings, .env files, validationpydantic-validation.md
db_cli.pySQLAlchemy async CRUD, repository patterndatabase-access.md
code_validator.pyRun→check→fix with ruff and mypycode-quality.md
bash
# Test examples
python sample-cli/async_fetcher.py https://httpbin.org/get
python sample-cli/config_loader.py --show-env
python sample-cli/db_cli.py init --sample-data && python sample-cli/db_cli.py list
python sample-cli/code_validator.py src/

When NOT to Use

  • Non-Python languages: Use language-specific skills
  • ML/AI model internals: Use PyTorch/TensorFlow skills
  • Cloud infrastructure: Use AWS/GCP skills for infra (this covers code)
  • Legacy Python 2: Focus is Python 3.10+