Purpose & When-To-Use
Trigger conditions:
- Starting a new Python project requiring modern tooling
- Migrating legacy Python projects to contemporary best practices
- Standardizing tooling across multiple Python projects
- Setting up CI/CD pipelines with proper quality gates
- Onboarding developers to Python development workflows
Not for:
- Django/Flask-specific project templates (use framework CLIs)
- Jupyter notebook environments (use JupyterLab/conda)
- Simple scripts without dependencies or testing needs
Pre-Checks
Time normalization:
- Compute
NOW_ET using NIST/time.gov semantics (America/New_York, ISO-8601)
- Use
NOW_ET for all citation access dates
Input validation:
project_type must be one of: library, application, cli, data-pipeline
dependency_manager must be one of: poetry, pipenv, pip-tools
python_version must be one of: 3.9, 3.10, 3.11, 3.12 (string format)
project_name must be valid Python package name (lowercase, hyphens allowed)
Source freshness:
Procedure
T1: Basic Project Structure (≤2k tokens)
Fast path for common cases:
Directory Layout Generation
Core pyproject.toml Generation
- Project metadata (name, version, description, authors)
- Python version constraint (from
python_version input)
- Basic tool configuration placeholders
- License and repository links
Basic .gitignore
- Python-specific ignores (pycache, *.pyc, .pytest_cache, .mypy_cache)
- Environment files (.env, .venv)
- Build artifacts (dist/, build/, *.egg-info)
Decision: If only basic scaffolding needed → STOP at T1; otherwise proceed to T2.
T2: Full Tooling Setup (≤6k tokens)
Extended configuration with all tools:
Dependency Manager Configuration
Poetry (pyproject.toml) accessed 2025-10-26T02:31:27-04:00
[tool.poetry]
name = "project-name"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
[tool.poetry.dependencies]
python = "^3.11"
[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
pytest-cov = "^4.1.0"
mypy = "^1.5.0"
ruff = "^0.1.0"
black = "^23.9.0"
pipenv (Pipfile) accessed 2025-10-26T02:31:27-04:00
- Generate Pipfile with dev/prod separation
- Configure pipenv scripts for common tasks
pip-tools (requirements.in) accessed 2025-10-26T02:31:27-04:00
- Create requirements.in and requirements-dev.in
- Add Makefile targets for pip-compile
Testing Configuration (pytest) accessed 2025-10-26T02:31:27-04:00
[tool.pytest.ini_options]
minversion = "7.0"
addopts = "-ra -q --strict-markers --cov=src"
testpaths = ["tests"]
pythonpath = ["src"]
markers = [
"slow: marks tests as slow",
"integration: marks tests as integration tests",
]
Type Checking (mypy) accessed 2025-10-26T02:31:27-04:00
[tool.mypy]
python_version = "3.11"
strict = true
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
Linting and Formatting
Ruff (all-in-one linter/formatter) accessed 2025-10-26T02:31:27-04:00
[tool.ruff]
target-version = "py311"
line-length = 100
select = ["E", "F", "I", "N", "W", "UP"]
ignore = ["E501"]
Black (code formatter) accessed 2025-10-26T02:31:27-04:00
[tool.black]
line-length = 100
target-version = ['py311']
Pre-commit Hooks accessed 2025-10-26T02:31:27-04:00
- Generate
.pre-commit-config.yaml
- Include: ruff, black, mypy, pytest
- Add trailing-whitespace, end-of-file-fixer
Makefile for Common Commands
.PHONY: test lint format typecheck install
install:
poetry install
test:
pytest
lint:
ruff check .
format:
black .
ruff check --fix .
typecheck:
mypy src
T3: Packaging and Distribution (≤12k tokens)
Deep configuration for publishable packages:
PyPI Publishing Setup accessed 2025-10-26T02:31:27-04:00
- Configure
[tool.poetry.build-system] or [build-system]
- Add classifiers and keywords for PyPI
- Set up MANIFEST.in for non-Python files
- Configure package data inclusion
Versioning Strategy accessed 2025-10-26T02:31:27-04:00
- Poetry:
poetry version integration
- Semantic versioning enforcement
- Git tag automation via Makefile/CI
Wheel Building Configuration accessed 2025-10-26T02:31:27-04:00
- Universal vs platform-specific wheels
- Namespace package handling
- C extension compilation (if applicable)
Entry Points and Scripts (for CLI projects)
[tool.poetry.scripts]
my-cli = "project_name.cli:main"
GitHub Actions CI/CD
- Matrix testing across Python versions
- Coverage reporting (codecov/coveralls)
- Automated PyPI publishing on tag push
- Security scanning (bandit, safety)
Documentation Setup
- Sphinx configuration for library projects
- MkDocs configuration for application projects
- Docstring style enforcement (pydocstyle)
Decision Rules
Dependency Manager Selection:
- Poetry: Best for libraries and packages destined for PyPI (default recommendation)
- pipenv: Good for applications with deployment focus (Heroku, Docker)
- pip-tools: Minimal overhead, best for simple projects or constrained environments
Project Type Structure:
- library: src-layout with
src/package_name/, includes py.typed, strict mypy
- application: flat layout with
package_name/, relaxed typing, focus on integration tests
- cli: src-layout with entry points, includes shell completion, argparse/click/typer
- data-pipeline: flat layout, includes Jupyter support, pandas/numpy stubs
Abort Conditions:
- Invalid
project_name (contains uppercase, special chars) → error "Invalid package name"
- Unsupported
python_version → error "Python version must be 3.9+"
- Conflicting configuration requests → error with suggested alternatives
Tool Version Selection:
- Use latest stable versions as of
NOW_ET
- For libraries: pin dev dependencies, use caret ranges for runtime deps
- For applications: pin all dependencies for reproducibility
Output Contract
Schema (JSON):
{
"project_name": "string",
"project_type": "library | application | cli | data-pipeline",
"python_version": "string",
"dependency_manager": "poetry | pipenv | pip-tools",
"structure": {
"directories": ["string"],
"files": {
"path/to/file": "file content (string)"
}
},
"commands": {
"install": "string",
"test": "string",
"lint": "string",
"format": "string",
"publish": "string (optional)"
},
"next_steps": ["string"],
"timestamp": "ISO-8601 string (NOW_ET)"
}
Required Fields:
project_name, project_type, python_version, dependency_manager, structure, commands, next_steps, timestamp
File Contents:
- All generated files must be syntactically valid (TOML/YAML/Makefile)
- Include inline comments explaining non-obvious configuration choices
- Reference official documentation in comments
Examples
Quick Start: Python Library (35 lines)
# examples/library_example.py
from dataclasses import dataclass
from datetime import datetime
@dataclass(frozen=True)
class AnalysisResult:
length: int
word_count: int
analyzed_at: datetime
class TextAnalyzer:
def __init__(self) -> None:
self._history: list[str] = []
def analyze(self, text: str) -> AnalysisResult:
if not text or not text.strip():
raise ValueError("Text cannot be empty")
self._history.append(text)
word_count = len(text.split())
return AnalysisResult(len(text), word_count, datetime.utcnow())
def get_history(self) -> tuple[str, ...]:
return tuple(self._history)
Additional Examples:
- CLI Tool:
examples/cli_example.py (32 lines) - Click framework, file I/O, error handling
- FastAPI:
examples/api_example.py (38 lines) - Pydantic models, async endpoints
Template Resources (see resources/)
- pyproject.toml:
pyproject-library.toml / pyproject-cli.toml / pyproject-api.toml
- Testing:
example_test.py - pytest with fixtures and parametrize
- Pre-commit:
pre-commit-config.yaml - ruff, black, mypy hooks
Quality Gates
Token Budgets:
- T1: ≤2k tokens (basic structure + core pyproject.toml)
- T2: ≤6k tokens (full tooling: pytest, mypy, ruff, pre-commit, Makefile)
- T3: ≤12k tokens (packaging, versioning, CI/CD, documentation)
Safety:
- No credential generation or storage
- .gitignore always includes .env and credential files
- pre-commit hooks check for secrets (detect-secrets)
Auditability:
- All tool configurations cite official documentation
- Version constraints are explicit (no floating versions in examples)
- Generated files include generation timestamp and tool versions
Determinism:
- Same inputs → identical file structure and configuration
- Tool versions pinned to major.minor (e.g., "^1.5" for mypy)
- No randomness in file generation
Performance:
- T1 generation: <1 second
- T2 generation: <3 seconds (includes all configs)
- T3 generation: <5 seconds (includes CI/CD templates)
Resources
Official Documentation (accessed 2025-10-26T02:31:27-04:00):
- Poetry Documentation - Dependency management and packaging
- pytest Documentation - Testing framework
- mypy Documentation - Static type checking
- Ruff Documentation - Fast Python linter
- Python Packaging User Guide - Official packaging guide
- Black Documentation - Code formatter
- pre-commit Documentation - Git hook framework
Tool Configurations:
/resources/pyproject-templates/ - Complete pyproject.toml templates by project type
/resources/pre-commit-configs/ - Pre-commit configurations for different tool combinations
/resources/makefile-templates/ - Makefile templates for poetry/pipenv/pip-tools
Best Practices:
Community Resources:
1---2name: python-tooling-specialist3description: Generate Python project scaffolding with Poetry/pipenv, pytest configuration, type hints (mypy), linting (ruff/black), and packaging (setuptools/flit).4license: MIT5---67## Purpose & When-To-Use89**Trigger conditions:**10- Starting a new Python project requiring modern tooling11- Migrating legacy Python projects to contemporary best practices12- Standardizing tooling across multiple Python projects13- Setting up CI/CD pipelines with proper quality gates14- Onboarding developers to Python development workflows1516**Not for:**17- Django/Flask-specific project templates (use framework CLIs)18- Jupyter notebook environments (use JupyterLab/conda)19- Simple scripts without dependencies or testing needs2021---2223## Pre-Checks2425**Time normalization:**26- Compute `NOW_ET` using NIST/time.gov semantics (America/New_York, ISO-8601)27- Use `NOW_ET` for all citation access dates2829**Input validation:**30- `project_type` must be one of: library, application, cli, data-pipeline31- `dependency_manager` must be one of: poetry, pipenv, pip-tools32- `python_version` must be one of: 3.9, 3.10, 3.11, 3.12 (string format)33- `project_name` must be valid Python package name (lowercase, hyphens allowed)3435**Source freshness:**36- Poetry docs must be accessible [accessed 2025-10-26T02:31:27-04:00](https://python-poetry.org/docs/)37- pytest docs must be accessible [accessed 2025-10-26T02:31:27-04:00](https://docs.pytest.org/)38- mypy docs must be accessible [accessed 2025-10-26T02:31:27-04:00](https://mypy.readthedocs.io/)39- Ruff docs must be accessible [accessed 2025-10-26T02:31:27-04:00](https://docs.astral.sh/ruff/)4041---4243## Procedure4445### T1: Basic Project Structure (≤2k tokens)4647**Fast path for common cases:**48491. **Directory Layout Generation**50 - Create standard Python project structure:51 ```52 project_name/53 src/project_name/ # for library/cli54 __init__.py55 py.typed # PEP 561 marker56 project_name/ # for application/data-pipeline57 __init__.py58 tests/59 __init__.py60 conftest.py61 docs/62 .gitignore63 README.md64 pyproject.toml65 ```66672. **Core pyproject.toml Generation**68 - Project metadata (name, version, description, authors)69 - Python version constraint (from `python_version` input)70 - Basic tool configuration placeholders71 - License and repository links72733. **Basic .gitignore**74 - Python-specific ignores (__pycache__, *.pyc, .pytest_cache, .mypy_cache)75 - Environment files (.env, .venv)76 - Build artifacts (dist/, build/, *.egg-info)7778**Decision:** If only basic scaffolding needed → STOP at T1; otherwise proceed to T2.7980---8182### T2: Full Tooling Setup (≤6k tokens)8384**Extended configuration with all tools:**85861. **Dependency Manager Configuration**8788 **Poetry (pyproject.toml)** [accessed 2025-10-26T02:31:27-04:00](https://python-poetry.org/docs/pyproject/)89 ```toml90 [tool.poetry]91 name = "project-name"92 version = "0.1.0"93 description = ""94 authors = ["Your Name <you@example.com>"]9596 [tool.poetry.dependencies]97 python = "^3.11"9899 [tool.poetry.group.dev.dependencies]100 pytest = "^7.4.0"101 pytest-cov = "^4.1.0"102 mypy = "^1.5.0"103 ruff = "^0.1.0"104 black = "^23.9.0"105 ```106107 **pipenv (Pipfile)** [accessed 2025-10-26T02:31:27-04:00](https://pipenv.pypa.io/en/latest/)108 - Generate Pipfile with dev/prod separation109 - Configure pipenv scripts for common tasks110111 **pip-tools (requirements.in)** [accessed 2025-10-26T02:31:27-04:00](https://pip-tools.readthedocs.io/)112 - Create requirements.in and requirements-dev.in113 - Add Makefile targets for pip-compile1141152. **Testing Configuration (pytest)** [accessed 2025-10-26T02:31:27-04:00](https://docs.pytest.org/en/7.4.x/reference/customize.html)116 ```toml117 [tool.pytest.ini_options]118 minversion = "7.0"119 addopts = "-ra -q --strict-markers --cov=src"120 testpaths = ["tests"]121 pythonpath = ["src"]122 markers = [123 "slow: marks tests as slow",124 "integration: marks tests as integration tests",125 ]126 ```1271283. **Type Checking (mypy)** [accessed 2025-10-26T02:31:27-04:00](https://mypy.readthedocs.io/en/stable/config_file.html)129 ```toml130 [tool.mypy]131 python_version = "3.11"132 strict = true133 warn_return_any = true134 warn_unused_configs = true135 disallow_untyped_defs = true136 ```1371384. **Linting and Formatting**139140 **Ruff (all-in-one linter/formatter)** [accessed 2025-10-26T02:31:27-04:00](https://docs.astral.sh/ruff/configuration/)141 ```toml142 [tool.ruff]143 target-version = "py311"144 line-length = 100145 select = ["E", "F", "I", "N", "W", "UP"]146 ignore = ["E501"]147 ```148149 **Black (code formatter)** [accessed 2025-10-26T02:31:27-04:00](https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html)150 ```toml151 [tool.black]152 line-length = 100153 target-version = ['py311']154 ```1551565. **Pre-commit Hooks** [accessed 2025-10-26T02:31:27-04:00](https://pre-commit.com/#plugins)157 - Generate `.pre-commit-config.yaml`158 - Include: ruff, black, mypy, pytest159 - Add trailing-whitespace, end-of-file-fixer1601616. **Makefile for Common Commands**162 ```makefile163 .PHONY: test lint format typecheck install164165 install:166 poetry install167168 test:169 pytest170171 lint:172 ruff check .173174 format:175 black .176 ruff check --fix .177178 typecheck:179 mypy src180 ```181182---183184### T3: Packaging and Distribution (≤12k tokens)185186**Deep configuration for publishable packages:**1871881. **PyPI Publishing Setup** [accessed 2025-10-26T02:31:27-04:00](https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/)189 - Configure `[tool.poetry.build-system]` or `[build-system]`190 - Add classifiers and keywords for PyPI191 - Set up MANIFEST.in for non-Python files192 - Configure package data inclusion1931942. **Versioning Strategy** [accessed 2025-10-26T02:31:27-04:00](https://python-poetry.org/docs/cli/#version)195 - Poetry: `poetry version` integration196 - Semantic versioning enforcement197 - Git tag automation via Makefile/CI1981993. **Wheel Building Configuration** [accessed 2025-10-26T02:31:27-04:00](https://packaging.python.org/en/latest/specifications/binary-distribution-format/)200 - Universal vs platform-specific wheels201 - Namespace package handling202 - C extension compilation (if applicable)2032044. **Entry Points and Scripts** (for CLI projects)205 ```toml206 [tool.poetry.scripts]207 my-cli = "project_name.cli:main"208 ```2092105. **GitHub Actions CI/CD**211 - Matrix testing across Python versions212 - Coverage reporting (codecov/coveralls)213 - Automated PyPI publishing on tag push214 - Security scanning (bandit, safety)2152166. **Documentation Setup**217 - Sphinx configuration for library projects218 - MkDocs configuration for application projects219 - Docstring style enforcement (pydocstyle)220221---222223## Decision Rules224225**Dependency Manager Selection:**226- **Poetry:** Best for libraries and packages destined for PyPI (default recommendation)227- **pipenv:** Good for applications with deployment focus (Heroku, Docker)228- **pip-tools:** Minimal overhead, best for simple projects or constrained environments229230**Project Type Structure:**231- **library:** src-layout with `src/package_name/`, includes py.typed, strict mypy232- **application:** flat layout with `package_name/`, relaxed typing, focus on integration tests233- **cli:** src-layout with entry points, includes shell completion, argparse/click/typer234- **data-pipeline:** flat layout, includes Jupyter support, pandas/numpy stubs235236**Abort Conditions:**237- Invalid `project_name` (contains uppercase, special chars) → error "Invalid package name"238- Unsupported `python_version` → error "Python version must be 3.9+"239- Conflicting configuration requests → error with suggested alternatives240241**Tool Version Selection:**242- Use latest stable versions as of `NOW_ET`243- For libraries: pin dev dependencies, use caret ranges for runtime deps244- For applications: pin all dependencies for reproducibility245246---247248## Output Contract249250**Schema (JSON):**251252```json253{254 "project_name": "string",255 "project_type": "library | application | cli | data-pipeline",256 "python_version": "string",257 "dependency_manager": "poetry | pipenv | pip-tools",258 "structure": {259 "directories": ["string"],260 "files": {261 "path/to/file": "file content (string)"262 }263 },264 "commands": {265 "install": "string",266 "test": "string",267 "lint": "string",268 "format": "string",269 "publish": "string (optional)"270 },271 "next_steps": ["string"],272 "timestamp": "ISO-8601 string (NOW_ET)"273}274```275276**Required Fields:**277- `project_name`, `project_type`, `python_version`, `dependency_manager`, `structure`, `commands`, `next_steps`, `timestamp`278279**File Contents:**280- All generated files must be syntactically valid (TOML/YAML/Makefile)281- Include inline comments explaining non-obvious configuration choices282- Reference official documentation in comments283284---285286## Examples287288**Quick Start: Python Library** (35 lines)289290```python291# examples/library_example.py292from dataclasses import dataclass293from datetime import datetime294295@dataclass(frozen=True)296class AnalysisResult:297 length: int298 word_count: int299 analyzed_at: datetime300301class TextAnalyzer:302 def __init__(self) -> None:303 self._history: list[str] = []304305 def analyze(self, text: str) -> AnalysisResult:306 if not text or not text.strip():307 raise ValueError("Text cannot be empty")308 self._history.append(text)309 word_count = len(text.split())310 return AnalysisResult(len(text), word_count, datetime.utcnow())311312 def get_history(self) -> tuple[str, ...]:313 return tuple(self._history)314```315316**Additional Examples:**317- **CLI Tool**: `examples/cli_example.py` (32 lines) - Click framework, file I/O, error handling318- **FastAPI**: `examples/api_example.py` (38 lines) - Pydantic models, async endpoints319320**Template Resources** (see `resources/`)321- pyproject.toml: `pyproject-library.toml` / `pyproject-cli.toml` / `pyproject-api.toml`322- Testing: `example_test.py` - pytest with fixtures and parametrize323- Pre-commit: `pre-commit-config.yaml` - ruff, black, mypy hooks324325---326327## Quality Gates328329**Token Budgets:**330- **T1:** ≤2k tokens (basic structure + core pyproject.toml)331- **T2:** ≤6k tokens (full tooling: pytest, mypy, ruff, pre-commit, Makefile)332- **T3:** ≤12k tokens (packaging, versioning, CI/CD, documentation)333334**Safety:**335- No credential generation or storage336- .gitignore always includes .env and credential files337- pre-commit hooks check for secrets (detect-secrets)338339**Auditability:**340- All tool configurations cite official documentation341- Version constraints are explicit (no floating versions in examples)342- Generated files include generation timestamp and tool versions343344**Determinism:**345- Same inputs → identical file structure and configuration346- Tool versions pinned to major.minor (e.g., "^1.5" for mypy)347- No randomness in file generation348349**Performance:**350- T1 generation: <1 second351- T2 generation: <3 seconds (includes all configs)352- T3 generation: <5 seconds (includes CI/CD templates)353354---355356## Resources357358**Official Documentation (accessed 2025-10-26T02:31:27-04:00):**3591. [Poetry Documentation](https://python-poetry.org/docs/) - Dependency management and packaging3602. [pytest Documentation](https://docs.pytest.org/) - Testing framework3613. [mypy Documentation](https://mypy.readthedocs.io/) - Static type checking3624. [Ruff Documentation](https://docs.astral.sh/ruff/) - Fast Python linter3635. [Python Packaging User Guide](https://packaging.python.org/) - Official packaging guide3646. [Black Documentation](https://black.readthedocs.io/) - Code formatter3657. [pre-commit Documentation](https://pre-commit.com/) - Git hook framework366367**Tool Configurations:**368- `/resources/pyproject-templates/` - Complete pyproject.toml templates by project type369- `/resources/pre-commit-configs/` - Pre-commit configurations for different tool combinations370- `/resources/makefile-templates/` - Makefile templates for poetry/pipenv/pip-tools371372**Best Practices:**373- [Python Application Layouts](https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/) - src vs flat layout374- [PEP 517](https://peps.python.org/pep-0517/) - Build system interface375- [PEP 518](https://peps.python.org/pep-0518/) - pyproject.toml specification376- [PEP 621](https://peps.python.org/pep-0621/) - Project metadata in pyproject.toml377378**Community Resources:**379- [Hypermodern Python](https://cjolowicz.github.io/posts/hypermodern-python-01-setup/) - Modern tooling guide380- [Real Python Packaging Guide](https://realpython.com/pypi-publish-python-package/) - PyPI publishing tutorial