1---2name: mastering-python-skill3description: 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".4---56# Mastering Python Skill78Production-ready Python patterns with runnable code examples.910## Contents1112- [Workflow](#workflow)13- [Reference Files](#reference-files)14- [Sample CLI Tools](#sample-cli-tools)15- [When NOT to Use](#when-not-to-use)16- [Full Table of Contents](TOC.md)1718---1920## Workflow2122### Phase 1: Setup23241. Verify Python version25 ```bash26 python --version # Require 3.10+, prefer 3.12+27 ```28292. Create and activate virtual environment30 ```bash31 python -m venv .venv && source .venv/bin/activate32 ```33343. Install dependencies35 ```bash36 poetry install # or: pip install -r requirements.txt37 ```3839### Phase 2: Develop40414. Reference appropriate patterns:42 - Types → [type-systems.md](references/foundations/type-systems.md)43 - Async → [async-programming.md](references/patterns/async-programming.md)44 - APIs → [fastapi-patterns.md](references/web-apis/fastapi-patterns.md)45 - DB → [database-access.md](references/web-apis/database-access.md)46475. Follow project structure from [project-structure.md](references/foundations/project-structure.md)4849### Phase 3: Validate50516. Run quality checks52 ```bash53 ruff check . && ruff format --check .54 mypy src/55 ```56577. Run tests with coverage58 ```bash59 pytest -v --cov=src --cov-report=term-missing60 ```6162### Phase 4: Deploy63648. Build and verify package65 ```bash66 python -m build && twine check dist/*67 ```68699. Deploy per [docker-deployment.md](references/packaging/docker-deployment.md) or [ci-cd-pipelines.md](references/production/ci-cd-pipelines.md)7071**Pre-Completion Checklist:**72```73- [ ] All tests pass74- [ ] mypy reports no errors75- [ ] ruff check clean76- [ ] Coverage ≥80%77- [ ] No security warnings in dependencies78```7980---8182## Reference Files8384| Category | Files | Key Topics |85|----------|-------|------------|86| **Foundations** | [syntax-essentials](references/foundations/syntax-essentials.md), [type-systems](references/foundations/type-systems.md), [project-structure](references/foundations/project-structure.md), [code-quality](references/foundations/code-quality.md) | Variables, type hints, generics, src layout, ruff, mypy |87| **Patterns** | [async-programming](references/patterns/async-programming.md), [error-handling](references/patterns/error-handling.md), [decorators](references/patterns/decorators.md), [context-managers](references/patterns/context-managers.md), [generators](references/patterns/generators.md) | async/await, exceptions, Result type, with statements, yield |88| **Testing** | [pytest-essentials](references/testing/pytest-essentials.md), [mocking-strategies](references/testing/mocking-strategies.md), [property-testing](references/testing/property-testing.md) | Fixtures, parametrize, unittest.mock, Hypothesis |89| **Web APIs** | [fastapi-patterns](references/web-apis/fastapi-patterns.md), [pydantic-validation](references/web-apis/pydantic-validation.md), [database-access](references/web-apis/database-access.md) | Dependencies, middleware, validators, SQLAlchemy async |90| **Packaging** | [poetry-workflow](references/packaging/poetry-workflow.md), [pyproject-config](references/packaging/pyproject-config.md), [docker-deployment](references/packaging/docker-deployment.md) | Lock files, PEP 621, multi-stage builds |91| **Production** | [ci-cd-pipelines](references/production/ci-cd-pipelines.md), [monitoring](references/production/monitoring.md), [security](references/production/security.md) | GitHub Actions, OpenTelemetry, OWASP, JWT |9293See [TOC.md](TOC.md) for detailed topic lookup.9495---9697## Sample CLI Tools9899Runnable examples demonstrating production patterns:100101| Tool | Demonstrates | Reference |102|------|-------------|-----------|103| [async_fetcher.py](sample-cli/async_fetcher.py) | Async HTTP, rate limiting, error handling | [async-programming.md](references/patterns/async-programming.md) |104| [config_loader.py](sample-cli/config_loader.py) | Pydantic settings, .env files, validation | [pydantic-validation.md](references/web-apis/pydantic-validation.md) |105| [db_cli.py](sample-cli/db_cli.py) | SQLAlchemy async CRUD, repository pattern | [database-access.md](references/web-apis/database-access.md) |106| [code_validator.py](sample-cli/code_validator.py) | Run→check→fix with ruff and mypy | [code-quality.md](references/foundations/code-quality.md) |107108```bash109# Test examples110python sample-cli/async_fetcher.py https://httpbin.org/get111python sample-cli/config_loader.py --show-env112python sample-cli/db_cli.py init --sample-data && python sample-cli/db_cli.py list113python sample-cli/code_validator.py src/114```115116---117118## When NOT to Use119120- **Non-Python languages**: Use language-specific skills121- **ML/AI model internals**: Use PyTorch/TensorFlow skills122- **Cloud infrastructure**: Use AWS/GCP skills for infra (this covers code)123- **Legacy Python 2**: Focus is Python 3.10+