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---5
6# Mastering Python Skill
7
8Production-ready Python patterns with runnable code examples.
9
10## Contents
11
12- [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)
17
18---
19
20## Workflow
21
22### Phase 1: Setup
23
241. Verify Python version
25 ```bash
26 python --version # Require 3.10+, prefer 3.12+
27 ```
28
292. Create and activate virtual environment
30 ```bash
31 python -m venv .venv && source .venv/bin/activate
32 ```
33
343. Install dependencies
35 ```bash
36 poetry install # or: pip install -r requirements.txt
37 ```
38
39### Phase 2: Develop
40
414. 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)
46
475. Follow project structure from [project-structure.md](references/foundations/project-structure.md)
48
49### Phase 3: Validate
50
516. Run quality checks
52 ```bash
53 ruff check . && ruff format --check .
54 mypy src/
55 ```
56
577. Run tests with coverage
58 ```bash
59 pytest -v --cov=src --cov-report=term-missing
60 ```
61
62### Phase 4: Deploy
63
648. Build and verify package
65 ```bash
66 python -m build && twine check dist/*
67 ```
68
699. Deploy per [docker-deployment.md](references/packaging/docker-deployment.md) or [ci-cd-pipelines.md](references/production/ci-cd-pipelines.md)
70
71**Pre-Completion Checklist:**
72```
73- [ ] All tests pass
74- [ ] mypy reports no errors
75- [ ] ruff check clean
76- [ ] Coverage ≥80%
77- [ ] No security warnings in dependencies
78```
79
80---
81
82## Reference Files
83
84| 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 |
92
93See [TOC.md](TOC.md) for detailed topic lookup.
94
95---
96
97## Sample CLI Tools
98
99Runnable examples demonstrating production patterns:
100
101| 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) |
107
108```bash
109# Test examples
110python sample-cli/async_fetcher.py https://httpbin.org/get
111python sample-cli/config_loader.py --show-env
112python sample-cli/db_cli.py init --sample-data && python sample-cli/db_cli.py list
113python sample-cli/code_validator.py src/
114```
115
116---
117
118## When NOT to Use
119
120- **Non-Python languages**: Use language-specific skills
121- **ML/AI model internals**: Use PyTorch/TensorFlow skills
122- **Cloud infrastructure**: Use AWS/GCP skills for infra (this covers code)
123- **Legacy Python 2**: Focus is Python 3.10+