open-shield-python 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. open_shield_python-0.1.0/.agent/rules.md +19 -0
  2. open_shield_python-0.1.0/.agent/skills/python-packaging/SKILL.md +36 -0
  3. open_shield_python-0.1.0/.agent/skills/python-packaging/resources/implementation-playbook.md +405 -0
  4. open_shield_python-0.1.0/.agent/skills/python-pro/SKILL.md +155 -0
  5. open_shield_python-0.1.0/.agent/skills/python-testing-patterns/SKILL.md +37 -0
  6. open_shield_python-0.1.0/.agent/skills/python-testing-patterns/resources/implementation-playbook.md +639 -0
  7. open_shield_python-0.1.0/.agent/skills/solid_architecture/SKILL.md +176 -0
  8. open_shield_python-0.1.0/.agent/skills/solid_architecture/examples/before_after_refactor.py +245 -0
  9. open_shield_python-0.1.0/.agent/skills/solid_architecture/examples/clean_architecture_layout.md +111 -0
  10. open_shield_python-0.1.0/.agent/skills/solid_architecture/examples/dip_ports_adapters.py +188 -0
  11. open_shield_python-0.1.0/.agent/skills/solid_architecture/resources/code_review_checklist.md +82 -0
  12. open_shield_python-0.1.0/.agent/workflows/safe-commit.md +27 -0
  13. open_shield_python-0.1.0/.github/workflows/ci.yml +31 -0
  14. open_shield_python-0.1.0/.gitignore +139 -0
  15. open_shield_python-0.1.0/CHANGELOG.md +13 -0
  16. open_shield_python-0.1.0/CONTRIBUTING.md +51 -0
  17. open_shield_python-0.1.0/LICENSE +21 -0
  18. open_shield_python-0.1.0/None +0 -0
  19. open_shield_python-0.1.0/PKG-INFO +130 -0
  20. open_shield_python-0.1.0/README.md +103 -0
  21. open_shield_python-0.1.0/docs/architecture/system-overview.md +19 -0
  22. open_shield_python-0.1.0/docs/design/overview.md +7 -0
  23. open_shield_python-0.1.0/docs/implementation/guidelines.md +12 -0
  24. open_shield_python-0.1.0/docs/planning/README.md +28 -0
  25. open_shield_python-0.1.0/docs/planning/backlog.md +7 -0
  26. open_shield_python-0.1.0/docs/planning/decisions/0000-template.md +25 -0
  27. open_shield_python-0.1.0/docs/planning/decisions/001-clean-architecture.md +29 -0
  28. open_shield_python-0.1.0/docs/planning/decisions/002-modern-tooling.md +29 -0
  29. open_shield_python-0.1.0/docs/planning/decisions/003-pydantic-usage.md +29 -0
  30. open_shield_python-0.1.0/docs/planning/phases/phase-0-init.md +21 -0
  31. open_shield_python-0.1.0/docs/planning/phases/phase-1-core.md +19 -0
  32. open_shield_python-0.1.0/docs/planning/phases/phase-2-authz.md +19 -0
  33. open_shield_python-0.1.0/docs/planning/phases/phase-3-integration.md +17 -0
  34. open_shield_python-0.1.0/docs/planning/phases/phase-4-logto-integration.md +73 -0
  35. open_shield_python-0.1.0/docs/planning/phases/phase-5-publish.md +21 -0
  36. open_shield_python-0.1.0/docs/planning/roadmap.md +19 -0
  37. open_shield_python-0.1.0/docs/planning/specs.md +357 -0
  38. open_shield_python-0.1.0/docs/planning/tasks.md +31 -0
  39. open_shield_python-0.1.0/docs/planning/tech-debt.md +7 -0
  40. open_shield_python-0.1.0/main.py +6 -0
  41. open_shield_python-0.1.0/pyproject.toml +75 -0
  42. open_shield_python-0.1.0/scripts/verify.sh +17 -0
  43. open_shield_python-0.1.0/src/open_shield/adapters/__init__.py +5 -0
  44. open_shield_python-0.1.0/src/open_shield/adapters/config.py +26 -0
  45. open_shield_python-0.1.0/src/open_shield/adapters/key_provider.py +109 -0
  46. open_shield_python-0.1.0/src/open_shield/adapters/token_validator.py +75 -0
  47. open_shield_python-0.1.0/src/open_shield/api/__init__.py +3 -0
  48. open_shield_python-0.1.0/src/open_shield/api/fastapi/__init__.py +4 -0
  49. open_shield_python-0.1.0/src/open_shield/api/fastapi/dependencies.py +47 -0
  50. open_shield_python-0.1.0/src/open_shield/api/fastapi/middleware.py +85 -0
  51. open_shield_python-0.1.0/src/open_shield/domain/__init__.py +18 -0
  52. open_shield_python-0.1.0/src/open_shield/domain/entities.py +59 -0
  53. open_shield_python-0.1.0/src/open_shield/domain/exceptions.py +40 -0
  54. open_shield_python-0.1.0/src/open_shield/domain/ports/__init__.py +4 -0
  55. open_shield_python-0.1.0/src/open_shield/domain/ports/key_provider.py +32 -0
  56. open_shield_python-0.1.0/src/open_shield/domain/ports/token_validator.py +38 -0
  57. open_shield_python-0.1.0/src/open_shield/domain/services/__init__.py +4 -0
  58. open_shield_python-0.1.0/src/open_shield/domain/services/authorization_service.py +45 -0
  59. open_shield_python-0.1.0/src/open_shield/domain/services/token_service.py +83 -0
  60. open_shield_python-0.1.0/tests/integration/adapters/test_key_provider.py +70 -0
  61. open_shield_python-0.1.0/tests/integration/adapters/test_token_validator.py +76 -0
  62. open_shield_python-0.1.0/tests/integration/api/test_fastapi.py +128 -0
  63. open_shield_python-0.1.0/tests/integration/auth_flow/test_logto_integration.py +72 -0
  64. open_shield_python-0.1.0/tests/integration/conftest.py +119 -0
  65. open_shield_python-0.1.0/tests/integration/infrastructure/docker-compose.logto.yml +34 -0
  66. open_shield_python-0.1.0/tests/integration/infrastructure/setup_logto.py +101 -0
  67. open_shield_python-0.1.0/tests/unit/adapters/test_config.py +35 -0
  68. open_shield_python-0.1.0/tests/unit/domain/test_authorization_service.py +38 -0
  69. open_shield_python-0.1.0/tests/unit/domain/test_token_service.py +80 -0
@@ -0,0 +1,19 @@
1
+ # Agent Rules for Open Shield
2
+
3
+ These rules apply to any AI agent working on this codebase.
4
+
5
+ ## 🛡️ Critical Workflows
6
+
7
+ 1. **Verify Before Push**:
8
+ - You MUST run `./scripts/verify.sh` or use the `/safe-commit` workflow before pushing any code to `main` or `staging`.
9
+ - If verification fails, **DO NOT** push. Fix the errors first.
10
+
11
+ 2. **Clean Architecture**:
12
+ - Respect the dependency rule: `Domain` <- `Adapters` <- `App/API`.
13
+ - Domain entities/ports must NOT import from adapters or external frameworks (except generic types).
14
+
15
+ 3. **Conventional Commits**:
16
+ - Use strict conventional commits (`feat:`, `fix:`, `chore:`, `refactor:`, `docs:`).
17
+
18
+ 4. **Self-Correction**:
19
+ - If a tool fails (e.g., `ruff` finds errors), attempt to fix it automatically using the tool's suggestions (e.g., `ruff check --fix`) before asking the user, unless the fix is ambiguous.
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: python-packaging
3
+ description: Create distributable Python packages with proper project structure, setup.py/pyproject.toml, and publishing to PyPI. Use when packaging Python libraries, creating CLI tools, or distributing Python code.
4
+ ---
5
+
6
+ # Python Packaging
7
+
8
+ Comprehensive guide to creating, structuring, and distributing Python packages using modern packaging tools, pyproject.toml, and publishing to PyPI.
9
+
10
+ ## Use this skill when
11
+
12
+ - Creating Python libraries for distribution
13
+ - Building command-line tools with entry points
14
+ - Publishing packages to PyPI or private repositories
15
+ - Setting up Python project structure
16
+ - Creating installable packages with dependencies
17
+ - Building wheels and source distributions
18
+ - Versioning and releasing Python packages
19
+ - Creating namespace packages
20
+ - Implementing package metadata and classifiers
21
+
22
+ ## Do not use this skill when
23
+
24
+ - The task is unrelated to python packaging
25
+ - You need a different domain or tool outside this scope
26
+
27
+ ## Instructions
28
+
29
+ - Clarify goals, constraints, and required inputs.
30
+ - Apply relevant best practices and validate outcomes.
31
+ - Provide actionable steps and verification.
32
+ - If detailed examples are required, open `resources/implementation-playbook.md`.
33
+
34
+ ## Resources
35
+
36
+ - `resources/implementation-playbook.md` for detailed patterns and examples.
@@ -0,0 +1,405 @@
1
+ # Python Packaging Implementation Playbook
2
+ This file contains detailed patterns, checklists, and code samples referenced by the skill.
3
+
4
+ # Python Packaging
5
+ Comprehensive guide to creating, structuring, and distributing Python packages using modern packaging tools, pyproject.toml, and publishing to PyPI.
6
+
7
+ ### 1. Package Structure
8
+ - **Source layout**: `src/package_name/` (recommended)
9
+ - **Flat layout**: `package_name/` (simpler but less flexible)
10
+ - **Package metadata**: pyproject.toml, setup.py, or setup.cfg
11
+ - **Distribution formats**: wheel (.whl) and source distribution (.tar.gz)
12
+
13
+ ### 2. Modern Packaging Standards
14
+ - **PEP 517/518**: Build system requirements
15
+ - **PEP 621**: Metadata in pyproject.toml
16
+ - **PEP 660**: Editable installs
17
+ - **pyproject.toml**: Single source of configuration
18
+
19
+ ### 3. Build Backends
20
+ - **setuptools**: Traditional, widely used
21
+ - **hatchling**: Modern, opinionated
22
+ - **flit**: Lightweight, for pure Python
23
+ - **poetry**: Dependency management + packaging
24
+
25
+ ### 4. Distribution
26
+ - **PyPI**: Python Package Index (public)
27
+ - **TestPyPI**: Testing before production
28
+ - **Private repositories**: JFrog, AWS CodeArtifact, etc.
29
+
30
+ ### Minimal Package Structure
31
+ ```
32
+ my-package/
33
+ ├── pyproject.toml
34
+ ├── README.md
35
+ ├── LICENSE
36
+ ├── src/
37
+ │ └── my_package/
38
+ │ ├── __init__.py
39
+ │ └── module.py
40
+ └── tests/
41
+ └── test_module.py
42
+ ```
43
+
44
+ ### Minimal pyproject.toml
45
+ ```toml
46
+ [build-system]
47
+ requires = ["setuptools>=61.0"]
48
+ build-backend = "setuptools.build_meta"
49
+
50
+ [project]
51
+ name = "my-package"
52
+ version = "0.1.0"
53
+ description = "A short description"
54
+ authors = [{name = "Your Name", email = "you@example.com"}]
55
+ readme = "README.md"
56
+ requires-python = ">=3.8"
57
+ dependencies = [
58
+ "requests>=2.28.0",
59
+ ]
60
+
61
+ [project.optional-dependencies]
62
+ dev = [
63
+ "pytest>=7.0",
64
+ "black>=22.0",
65
+ ]
66
+ ```
67
+
68
+ ### Pattern 1: Source Layout (Recommended)
69
+ ```
70
+ my-package/
71
+ ├── pyproject.toml
72
+ ├── README.md
73
+ ├── LICENSE
74
+ ├── .gitignore
75
+ ├── src/
76
+ │ └── my_package/
77
+ │ ├── __init__.py
78
+ │ ├── core.py
79
+ │ ├── utils.py
80
+ │ └── py.typed # For type hints
81
+ ├── tests/
82
+ │ ├── __init__.py
83
+ │ ├── test_core.py
84
+ │ └── test_utils.py
85
+ └── docs/
86
+ └── index.md
87
+ ```
88
+
89
+ **Advantages:**
90
+ - Prevents accidentally importing from source
91
+ - Cleaner test imports
92
+ - Better isolation
93
+
94
+ **pyproject.toml for source layout:**
95
+ ```toml
96
+ [tool.setuptools.packages.find]
97
+ where = ["src"]
98
+ ```
99
+
100
+ ### Pattern 2: Flat Layout
101
+ ```
102
+ my-package/
103
+ ├── pyproject.toml
104
+ ├── README.md
105
+ ├── my_package/
106
+ │ ├── __init__.py
107
+ │ └── module.py
108
+ └── tests/
109
+ └── test_module.py
110
+ ```
111
+
112
+ **Simpler but:**
113
+ - Can import package without installing
114
+ - Less professional for libraries
115
+
116
+ ### Pattern 3: Multi-Package Project
117
+ ```
118
+ project/
119
+ ├── pyproject.toml
120
+ ├── packages/
121
+ │ ├── package-a/
122
+ │ │ └── src/
123
+ │ │ └── package_a/
124
+ │ └── package-b/
125
+ │ └── src/
126
+ │ └── package_b/
127
+ └── tests/
128
+ ```
129
+
130
+ ### Pattern 4: Full-Featured pyproject.toml
131
+ ```toml
132
+ [build-system]
133
+ requires = ["setuptools>=61.0", "wheel"]
134
+ build-backend = "setuptools.build_meta"
135
+
136
+ [project]
137
+ name = "my-awesome-package"
138
+ version = "1.0.0"
139
+ description = "An awesome Python package"
140
+ readme = "README.md"
141
+ requires-python = ">=3.8"
142
+ license = {text = "MIT"}
143
+ authors = [
144
+ {name = "Your Name", email = "you@example.com"},
145
+ ]
146
+ maintainers = [
147
+ {name = "Maintainer Name", email = "maintainer@example.com"},
148
+ ]
149
+ keywords = ["example", "package", "awesome"]
150
+ classifiers = [
151
+ "Development Status :: 4 - Beta",
152
+ "Intended Audience :: Developers",
153
+ "License :: OSI Approved :: MIT License",
154
+ "Programming Language :: Python :: 3",
155
+ "Programming Language :: Python :: 3.8",
156
+ "Programming Language :: Python :: 3.9",
157
+ "Programming Language :: Python :: 3.10",
158
+ "Programming Language :: Python :: 3.11",
159
+ "Programming Language :: Python :: 3.12",
160
+ ]
161
+
162
+ dependencies = [
163
+ "requests>=2.28.0,<3.0.0",
164
+ "click>=8.0.0",
165
+ "pydantic>=2.0.0",
166
+ ]
167
+
168
+ [project.optional-dependencies]
169
+ dev = [
170
+ "pytest>=7.0.0",
171
+ "pytest-cov>=4.0.0",
172
+ "black>=23.0.0",
173
+ "ruff>=0.1.0",
174
+ "mypy>=1.0.0",
175
+ ]
176
+ docs = [
177
+ "sphinx>=5.0.0",
178
+ "sphinx-rtd-theme>=1.0.0",
179
+ ]
180
+ all = [
181
+ "my-awesome-package[dev,docs]",
182
+ ]
183
+
184
+ [project.urls]
185
+ Homepage = "https://github.com/username/my-awesome-package"
186
+ Documentation = "https://my-awesome-package.readthedocs.io"
187
+ Repository = "https://github.com/username/my-awesome-package"
188
+ "Bug Tracker" = "https://github.com/username/my-awesome-package/issues"
189
+ Changelog = "https://github.com/username/my-awesome-package/blob/main/CHANGELOG.md"
190
+
191
+ [project.scripts]
192
+ my-cli = "my_package.cli:main"
193
+ awesome-tool = "my_package.tools:run"
194
+
195
+ [project.entry-points."my_package.plugins"]
196
+ plugin1 = "my_package.plugins:plugin1"
197
+
198
+ [tool.setuptools]
199
+ package-dir = {"" = "src"}
200
+ zip-safe = false
201
+
202
+ [tool.setuptools.packages.find]
203
+ where = ["src"]
204
+ include = ["my_package*"]
205
+ exclude = ["tests*"]
206
+
207
+ [tool.setuptools.package-data]
208
+ my_package = ["py.typed", "*.pyi", "data/*.json"]
209
+
210
+ # Black configuration
211
+ [tool.black]
212
+ line-length = 100
213
+ target-version = ["py38", "py39", "py310", "py311"]
214
+ include = '\.pyi?$'
215
+
216
+ # Ruff configuration
217
+ [tool.ruff]
218
+ line-length = 100
219
+ target-version = "py38"
220
+
221
+ [tool.ruff.lint]
222
+ select = ["E", "F", "I", "N", "W", "UP"]
223
+
224
+ # MyPy configuration
225
+ [tool.mypy]
226
+ python_version = "3.8"
227
+ warn_return_any = true
228
+ warn_unused_configs = true
229
+ disallow_untyped_defs = true
230
+
231
+ # Pytest configuration
232
+ [tool.pytest.ini_options]
233
+ testpaths = ["tests"]
234
+ python_files = ["test_*.py"]
235
+ addopts = "-v --cov=my_package --cov-report=term-missing"
236
+
237
+ # Coverage configuration
238
+ [tool.coverage.run]
239
+ source = ["src"]
240
+ omit = ["*/tests/*"]
241
+
242
+ [tool.coverage.report]
243
+ exclude_lines = [
244
+ "pragma: no cover",
245
+ "def __repr__",
246
+ "raise AssertionError",
247
+ "raise NotImplementedError",
248
+ ]
249
+ ```
250
+
251
+ ### Pattern 5: Dynamic Versioning
252
+ ```toml
253
+ [build-system]
254
+ requires = ["setuptools>=61.0", "setuptools-scm>=8.0"]
255
+ build-backend = "setuptools.build_meta"
256
+
257
+ [project]
258
+ name = "my-package"
259
+ dynamic = ["version"]
260
+ description = "Package with dynamic version"
261
+
262
+ [tool.setuptools.dynamic]
263
+ version = {attr = "my_package.__version__"}
264
+
265
+ # Or use setuptools-scm for git-based versioning
266
+ [tool.setuptools_scm]
267
+ write_to = "src/my_package/_version.py"
268
+ ```
269
+
270
+ **In __init__.py:**
271
+ ```python
272
+ # src/my_package/__init__.py
273
+ __version__ = "1.0.0"
274
+
275
+ # Or with setuptools-scm
276
+ from importlib.metadata import version
277
+ __version__ = version("my-package")
278
+ ```
279
+
280
+ ### Pattern 8: Build Package Locally
281
+ ```bash
282
+ # Install build tools
283
+ pip install build twine
284
+
285
+ # Build distribution
286
+ python -m build
287
+
288
+ # This creates:
289
+ # dist/
290
+ # my-package-1.0.0.tar.gz (source distribution)
291
+ # my_package-1.0.0-py3-none-any.whl (wheel)
292
+
293
+ # Check the distribution
294
+ twine check dist/*
295
+ ```
296
+
297
+ ### Pattern 9: Publishing to PyPI
298
+ ```bash
299
+ # Install publishing tools
300
+ pip install twine
301
+
302
+ # Test on TestPyPI first
303
+ twine upload --repository testpypi dist/*
304
+
305
+ # Install from TestPyPI to test
306
+ pip install --index-url https://test.pypi.org/simple/ my-package
307
+
308
+ # If all good, publish to PyPI
309
+ twine upload dist/*
310
+ ```
311
+
312
+ **Using API tokens (recommended):**
313
+ ```bash
314
+ # Create ~/.pypirc
315
+ [distutils]
316
+ index-servers =
317
+ pypi
318
+ testpypi
319
+
320
+ [pypi]
321
+ username = __token__
322
+ password = pypi-...your-token...
323
+
324
+ [testpypi]
325
+ username = __token__
326
+ password = pypi-...your-test-token...
327
+ ```
328
+
329
+ ### Pattern 10: Automated Publishing with GitHub Actions
330
+ ```yaml
331
+ # .github/workflows/publish.yml
332
+ name: Publish to PyPI
333
+
334
+ on:
335
+ release:
336
+ types: [created]
337
+
338
+ jobs:
339
+ publish:
340
+ runs-on: ubuntu-latest
341
+
342
+ steps:
343
+ - uses: actions/checkout@v3
344
+
345
+ - name: Set up Python
346
+ uses: actions/setup-python@v4
347
+ with:
348
+ python-version: "3.11"
349
+
350
+ - name: Install dependencies
351
+ run: |
352
+ pip install build twine
353
+
354
+ - name: Build package
355
+ run: python -m build
356
+
357
+ - name: Check package
358
+ run: twine check dist/*
359
+
360
+ - name: Publish to PyPI
361
+ env:
362
+ TWINE_USERNAME: __token__
363
+ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
364
+ run: twine upload dist/*
365
+ ```
366
+
367
+ ### Pattern 19: Multi-Architecture Wheels
368
+ ```yaml
369
+ # .github/workflows/wheels.yml
370
+ name: Build wheels
371
+
372
+ on: [push, pull_request]
373
+
374
+ jobs:
375
+ build_wheels:
376
+ name: Build wheels on ${{ matrix.os }}
377
+ runs-on: ${{ matrix.os }}
378
+ strategy:
379
+ matrix:
380
+ os: [ubuntu-latest, windows-latest, macos-latest]
381
+
382
+ steps:
383
+ - uses: actions/checkout@v3
384
+
385
+ - name: Build wheels
386
+ uses: pypa/cibuildwheel@v2.16.2
387
+
388
+ - uses: actions/upload-artifact@v3
389
+ with:
390
+ path: ./wheelhouse/*.whl
391
+ ```
392
+
393
+ ### Pattern 20: Private Package Index
394
+ ```bash
395
+ # Install from private index
396
+ pip install my-package --index-url https://private.pypi.org/simple/
397
+
398
+ # Or add to pip.conf
399
+ [global]
400
+ index-url = https://private.pypi.org/simple/
401
+ extra-index-url = https://pypi.org/simple/
402
+
403
+ # Upload to private index
404
+ twine upload --repository-url https://private.pypi.org/ dist/*
405
+ ```
@@ -0,0 +1,155 @@
1
+ ---
2
+ name: python-pro
3
+ description: Master Python 3.12+ with modern features, async programming,
4
+ performance optimization, and production-ready practices. Expert in the latest
5
+ Python ecosystem including uv, ruff, pydantic, and FastAPI. Use PROACTIVELY
6
+ for Python development, optimization, or advanced Python patterns.
7
+ metadata:
8
+ model: opus
9
+ ---
10
+ You are a Python expert specializing in modern Python 3.12+ development with cutting-edge tools and practices from the 2024/2025 ecosystem.
11
+
12
+ ## Use this skill when
13
+ - Writing or reviewing Python 3.12+ codebases
14
+ - Implementing async workflows or performance optimizations
15
+ - Designing production-ready Python services or tooling
16
+
17
+ ## Do not use this skill when
18
+ - You need guidance for a non-Python stack
19
+ - You only need basic syntax tutoring
20
+ - You cannot modify Python runtime or dependencies
21
+
22
+ ## Instructions
23
+ 1. Confirm runtime, dependencies, and performance targets.
24
+ 2. Choose patterns (async, typing, tooling) that match requirements.
25
+ 3. Implement and test with modern tooling.
26
+ 4. Profile and tune for latency, memory, and correctness.
27
+
28
+ ## Purpose
29
+ Expert Python developer mastering Python 3.12+ features, modern tooling, and production-ready development practices. Deep knowledge of the current Python ecosystem including package management with uv, code quality with ruff, and building high-performance applications with async patterns.
30
+
31
+ ## Capabilities
32
+
33
+ ### Modern Python Features
34
+ - Python 3.12+ features including improved error messages, performance optimizations, and type system enhancements
35
+ - Advanced async/await patterns with asyncio, aiohttp, and trio
36
+ - Context managers and the `with` statement for resource management
37
+ - Dataclasses, Pydantic models, and modern data validation
38
+ - Pattern matching (structural pattern matching) and match statements
39
+ - Type hints, generics, and Protocol typing for robust type safety
40
+ - Descriptors, metaclasses, and advanced object-oriented patterns
41
+ - Generator expressions, itertools, and memory-efficient data processing
42
+
43
+ ### Modern Tooling & Development Environment
44
+ - Package management with uv (2024's fastest Python package manager)
45
+ - Code formatting and linting with ruff (replacing black, isort, flake8)
46
+ - Static type checking with mypy and pyright
47
+ - Project configuration with pyproject.toml (modern standard)
48
+ - Virtual environment management with venv, pipenv, or uv
49
+ - Pre-commit hooks for code quality automation
50
+ - Modern Python packaging and distribution practices
51
+ - Dependency management and lock files
52
+
53
+ ### Testing & Quality Assurance
54
+ - Comprehensive testing with pytest and pytest plugins
55
+ - Property-based testing with Hypothesis
56
+ - Test fixtures, factories, and mock objects
57
+ - Coverage analysis with pytest-cov and coverage.py
58
+ - Performance testing and benchmarking with pytest-benchmark
59
+ - Integration testing and test databases
60
+ - Continuous integration with GitHub Actions
61
+ - Code quality metrics and static analysis
62
+
63
+ ### Performance & Optimization
64
+ - Profiling with cProfile, py-spy, and memory_profiler
65
+ - Performance optimization techniques and bottleneck identification
66
+ - Async programming for I/O-bound operations
67
+ - Multiprocessing and concurrent.futures for CPU-bound tasks
68
+ - Memory optimization and garbage collection understanding
69
+ - Caching strategies with functools.lru_cache and external caches
70
+ - Database optimization with SQLAlchemy and async ORMs
71
+ - NumPy, Pandas optimization for data processing
72
+
73
+ ### Web Development & APIs
74
+ - FastAPI for high-performance APIs with automatic documentation
75
+ - Django for full-featured web applications
76
+ - Flask for lightweight web services
77
+ - Pydantic for data validation and serialization
78
+ - SQLAlchemy 2.0+ with async support
79
+ - Background task processing with Celery and Redis
80
+ - WebSocket support with FastAPI and Django Channels
81
+ - Authentication and authorization patterns
82
+
83
+ ### Data Science & Machine Learning
84
+ - NumPy and Pandas for data manipulation and analysis
85
+ - Matplotlib, Seaborn, and Plotly for data visualization
86
+ - Scikit-learn for machine learning workflows
87
+ - Jupyter notebooks and IPython for interactive development
88
+ - Data pipeline design and ETL processes
89
+ - Integration with modern ML libraries (PyTorch, TensorFlow)
90
+ - Data validation and quality assurance
91
+ - Performance optimization for large datasets
92
+
93
+ ### DevOps & Production Deployment
94
+ - Docker containerization and multi-stage builds
95
+ - Kubernetes deployment and scaling strategies
96
+ - Cloud deployment (AWS, GCP, Azure) with Python services
97
+ - Monitoring and logging with structured logging and APM tools
98
+ - Configuration management and environment variables
99
+ - Security best practices and vulnerability scanning
100
+ - CI/CD pipelines and automated testing
101
+ - Performance monitoring and alerting
102
+
103
+ ### Advanced Python Patterns
104
+ - Design patterns implementation (Singleton, Factory, Observer, etc.)
105
+ - SOLID principles in Python development
106
+ - Dependency injection and inversion of control
107
+ - Event-driven architecture and messaging patterns
108
+ - Functional programming concepts and tools
109
+ - Advanced decorators and context managers
110
+ - Metaprogramming and dynamic code generation
111
+ - Plugin architectures and extensible systems
112
+
113
+ ## Behavioral Traits
114
+ - Follows PEP 8 and modern Python idioms consistently
115
+ - Prioritizes code readability and maintainability
116
+ - Uses type hints throughout for better code documentation
117
+ - Implements comprehensive error handling with custom exceptions
118
+ - Writes extensive tests with high coverage (>90%)
119
+ - Leverages Python's standard library before external dependencies
120
+ - Focuses on performance optimization when needed
121
+ - Documents code thoroughly with docstrings and examples
122
+ - Stays current with latest Python releases and ecosystem changes
123
+ - Emphasizes security and best practices in production code
124
+
125
+ ## Knowledge Base
126
+ - Python 3.12+ language features and performance improvements
127
+ - Modern Python tooling ecosystem (uv, ruff, pyright)
128
+ - Current web framework best practices (FastAPI, Django 5.x)
129
+ - Async programming patterns and asyncio ecosystem
130
+ - Data science and machine learning Python stack
131
+ - Modern deployment and containerization strategies
132
+ - Python packaging and distribution best practices
133
+ - Security considerations and vulnerability prevention
134
+ - Performance profiling and optimization techniques
135
+ - Testing strategies and quality assurance practices
136
+
137
+ ## Response Approach
138
+ 1. **Analyze requirements** for modern Python best practices
139
+ 2. **Suggest current tools and patterns** from the 2024/2025 ecosystem
140
+ 3. **Provide production-ready code** with proper error handling and type hints
141
+ 4. **Include comprehensive tests** with pytest and appropriate fixtures
142
+ 5. **Consider performance implications** and suggest optimizations
143
+ 6. **Document security considerations** and best practices
144
+ 7. **Recommend modern tooling** for development workflow
145
+ 8. **Include deployment strategies** when applicable
146
+
147
+ ## Example Interactions
148
+ - "Help me migrate from pip to uv for package management"
149
+ - "Optimize this Python code for better async performance"
150
+ - "Design a FastAPI application with proper error handling and validation"
151
+ - "Set up a modern Python project with ruff, mypy, and pytest"
152
+ - "Implement a high-performance data processing pipeline"
153
+ - "Create a production-ready Dockerfile for a Python application"
154
+ - "Design a scalable background task system with Celery"
155
+ - "Implement modern authentication patterns in FastAPI"
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: python-testing-patterns
3
+ description: Implement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development. Use when writing Python tests, setting up test suites, or implementing testing best practices.
4
+ ---
5
+
6
+ # Python Testing Patterns
7
+
8
+ Comprehensive guide to implementing robust testing strategies in Python using pytest, fixtures, mocking, parameterization, and test-driven development practices.
9
+
10
+ ## Use this skill when
11
+
12
+ - Writing unit tests for Python code
13
+ - Setting up test suites and test infrastructure
14
+ - Implementing test-driven development (TDD)
15
+ - Creating integration tests for APIs and services
16
+ - Mocking external dependencies and services
17
+ - Testing async code and concurrent operations
18
+ - Setting up continuous testing in CI/CD
19
+ - Implementing property-based testing
20
+ - Testing database operations
21
+ - Debugging failing tests
22
+
23
+ ## Do not use this skill when
24
+
25
+ - The task is unrelated to python testing patterns
26
+ - You need a different domain or tool outside this scope
27
+
28
+ ## Instructions
29
+
30
+ - Clarify goals, constraints, and required inputs.
31
+ - Apply relevant best practices and validate outcomes.
32
+ - Provide actionable steps and verification.
33
+ - If detailed examples are required, open `resources/implementation-playbook.md`.
34
+
35
+ ## Resources
36
+
37
+ - `resources/implementation-playbook.md` for detailed patterns and examples.