Python(CLAUDE-MD-Python)
Python-based projects
Claude Code Configuration for Python Projects
๐จ CRITICAL: PYTHON PARALLEL EXECUTION PATTERNS
MANDATORY RULE: Python projects require virtual environment coordination with pip/conda parallel operations.
๐จ CRITICAL: CONCURRENT EXECUTION FOR ALL PYTHON OPERATIONS
ABSOLUTE RULE: ALL Python operations MUST be concurrent/parallel in a single message:
๐ด MANDATORY CONCURRENT PATTERNS FOR PYTHON:
- Virtual Environment: ALWAYS batch ALL venv/conda setup in ONE message
- Package Management: ALWAYS batch ALL pip install commands together
- Django/FastAPI Operations: ALWAYS batch ALL framework commands
- Testing: ALWAYS run ALL test suites in parallel (pytest, unittest)
- Data Science: ALWAYS batch ALL Jupyter/pandas operations
โก PYTHON GOLDEN RULE: "1 MESSAGE = ALL PYTHON ECOSYSTEM OPERATIONS"
Examples of CORRECT Python concurrent execution:
# โ
CORRECT: Everything in ONE message
[Single Message]:
- TodoWrite { todos: [10+ todos with all Python tasks] }
- Task("You are Python architect. Coordinate via hooks for Django design...")
- Task("You are Data scientist. Coordinate via hooks for ML pipelines...")
- Task("You are DevOps engineer. Coordinate via hooks for deployment...")
- Bash("python -m venv venv")
- Bash("source venv/bin/activate && pip install django djangorestframework")
- Bash("source venv/bin/activate && pip install pytest black flake8 poetry")
- Write("requirements.txt", requirementsContent)
- Write("manage.py", djangoManage)
- Write("settings.py", djangoSettings)
- Write("models.py", djangoModels)
- Write("views.py", djangoViews)
- Write("tests/test_api.py", testContent)
- Write("pyproject.toml", poetryConfig)
๐ฏ PYTHON-SPECIFIC SWARM PATTERNS
๐ Virtual Environment Coordination
Environment Setup Strategy:
# Always batch environment setup
python -m venv venv
source venv/bin/activate # Linux/Mac
# OR
venv\Scripts\activate # Windows
pip install --upgrade pip setuptools wheel
pip install -r requirements.txt
pip install -e . # Install package in development mode
Parallel Development Setup:
# โ
CORRECT: All setup in ONE message
[BatchTool]:
- Bash("python -m venv venv")
- Bash("source venv/bin/activate && pip install django fastapi sqlalchemy")
- Bash("source venv/bin/activate && pip install pytest black flake8 mypy")
- Write("requirements.txt", productionDeps)
- Write("requirements-dev.txt", devDependencies)
- Write("setup.py", packageSetup)
- Write("pyproject.toml", modernConfig)
- Write(".env.example", envTemplate)
- Bash("source venv/bin/activate && python manage.py migrate")
๐๏ธ Python Agent Specialization
Agent Types for Python Projects:
- Django/FastAPI Agent - Web framework, REST APIs, database ORM
- Data Science Agent - Pandas, NumPy, Scikit-learn, Jupyter
- ML/AI Agent - TensorFlow, PyTorch, model training
- Testing Agent - Pytest, unittest, integration testing
- DevOps Agent - Docker, Gunicorn, deployment automation
- Quality Agent - Black, Flake8, MyPy, pre-commit hooks
๐ Django Framework Coordination
Django Project Setup:
# Django swarm initialization
[BatchTool]:
- Bash("django-admin startproject myproject")
- Bash("cd myproject && python manage.py startapp users")
- Bash("cd myproject && python manage.py startapp api")
- Write("myproject/settings.py", djangoSettings)
- Write("users/models.py", userModels)
- Write("api/serializers.py", drf_serializers)
- Write("api/views.py", drf_views)
- Write("api/urls.py", apiUrls)
- Bash("cd myproject && python manage.py makemigrations")
- Bash("cd myproject && python manage.py migrate")
โก FastAPI Framework Coordination
FastAPI Development Pattern:
# FastAPI swarm setup
[BatchTool]:
- Write("main.py", fastapiMain)
- Write("models.py", sqlalchemyModels)
- Write("schemas.py", pydanticSchemas)
- Write("database.py", databaseConfig)
- Write("routers/users.py", userRoutes)
- Write("routers/auth.py", authRoutes)
- Bash("pip install fastapi uvicorn sqlalchemy alembic")
- Bash("alembic init alembic")
- Bash("uvicorn main:app --reload --port 8000")
๐งช PYTHON TESTING COORDINATION
๐ฌ Pytest Testing Strategy
Parallel Testing Setup:
# Test coordination pattern
[BatchTool]:
- Write("tests/conftest.py", pytestConfig)
- Write("tests/test_models.py", modelTests)
- Write("tests/test_views.py", viewTests)
- Write("tests/test_integration.py", integrationTests)
- Write("pytest.ini", pytestSettings)
- Bash("pytest tests/ -v --cov=src --cov-report=html")
- Bash("pytest tests/integration/ --tb=short")
- Bash("pytest tests/unit/ --parallel")
๐ Data Science Testing
Data Science Test Coordination:
[BatchTool]:
- Write("tests/test_data_processing.py", dataTests)
- Write("tests/test_model_training.py", mlTests)
- Write("tests/fixtures/sample_data.csv", testData)
- Bash("pytest tests/test_data_*.py --tb=line")
- Bash("python -m pytest --nbval notebooks/")
๐ DATA SCIENCE SWARM PATTERNS
๐ค Machine Learning Coordination
ML Pipeline Setup:
# ML development batch
[BatchTool]:
- Write("src/data/preprocessing.py", dataPreprocessing)
- Write("src/models/train.py", modelTraining)
- Write("src/models/evaluate.py", modelEvaluation)
- Write("src/utils/feature_engineering.py", featureUtils)
- Write("notebooks/exploratory_analysis.ipynb", eda_notebook)
- Bash("pip install pandas numpy scikit-learn matplotlib seaborn")
- Bash("pip install jupyter ipykernel jupyterlab")
- Bash("python src/models/train.py --config config/model_config.yaml")
๐ Data Analysis Coordination
Data Analysis Swarm:
[BatchTool]:
- Write("src/analysis/data_loader.py", dataLoader)
- Write("src/analysis/statistical_analysis.py", statsAnalysis)
- Write("src/visualization/plots.py", plotGeneration)
- Write("requirements-data.txt", dataRequirements)
- Bash("pip install pandas numpy scipy matplotlib plotly streamlit")
- Bash("jupyter lab --port 8888 --no-browser")
๐ง PYTHON BUILD TOOLS COORDINATION
๐ฆ Poetry Package Management
Poetry Coordination Pattern:
# Poetry project setup
[BatchTool]:
- Bash("poetry init --no-interaction")
- Bash("poetry add django fastapi sqlalchemy")
- Bash("poetry add --group dev pytest black flake8 mypy")
- Write("pyproject.toml", poetryConfig)
- Write("poetry.lock", lockFile)
- Bash("poetry install")
- Bash("poetry run python manage.py runserver")
๐ฏ Modern Python Packaging
Modern Packaging Coordination:
# Modern Python project setup
[BatchTool]:
- Write("pyproject.toml", modernPyprojectToml)
- Write("src/mypackage/__init__.py", packageInit)
- Write("src/mypackage/main.py", mainModule)
- Write("README.md", packageReadme)
- Write("CHANGELOG.md", changelog)
- Bash("pip install build twine")
- Bash("python -m build")
- Bash("twine check dist/*")
๐ PYTHON SECURITY BEST PRACTICES
๐ก๏ธ Security Coordination Patterns
Security Implementation Batch:
[BatchTool]:
- Write("src/security/authentication.py", authSecurity)
- Write("src/security/validation.py", inputValidation)
- Write("src/security/encryption.py", dataEncryption)
- Bash("pip install cryptography pyjwt python-decouple")
- Bash("pip install bandit safety")
- Bash("bandit -r src/ && safety check")
Python Security Checklist:
- SQL injection prevention (use ORMs)
- Input validation and sanitization
- Secure secret management
- Proper authentication/authorization
- HTTPS enforcement
- Dependency vulnerability scanning
- Code security analysis (Bandit)
- Environment variable protection
โก PYTHON PERFORMANCE OPTIMIZATION
๐ Performance Coordination
Performance Optimization Batch:
[BatchTool]:
- Write("src/performance/caching.py", cachingUtils)
- Write("src/performance/async_operations.py", asyncioPatterns)
- Write("src/performance/database_optimization.py", dbOptimization)
- Bash("pip install redis celery asyncio aiohttp")
- Bash("pip install --dev cProfile memory_profiler")
- Bash("python -m cProfile -o profile.stats main.py")
๐ Asynchronous Programming
Async/Await Coordination:
[BatchTool]:
- Write("src/async/web_client.py", asyncHttpClient)
- Write("src/async/database.py", asyncDatabase)
- Write("src/async/background_tasks.py", backgroundTasks)
- Bash("pip install asyncio aiohttp asyncpg")
- Bash("python -m asyncio src/async/main.py")
๐ PYTHON DEPLOYMENT PATTERNS
โ๏ธ Production Deployment
Deployment Coordination:
[BatchTool]:
- Write("Dockerfile", dockerConfiguration)
- Write("docker-compose.yml", dockerCompose)
- Write("gunicorn.conf.py", gunicornConfig)
- Write("requirements-prod.txt", prodRequirements)
- Write("scripts/deploy.sh", deploymentScript)
- Bash("docker build -t python-app:latest .")
- Bash("gunicorn --config gunicorn.conf.py main:app")
๐ณ Docker Coordination
Docker Setup Batch:
[BatchTool]:
- Write("Dockerfile", multiStageDockerfile)
- Write(".dockerignore", dockerIgnore)
- Write("docker-compose.yml", devDockerCompose)
- Write("docker-compose.prod.yml", prodDockerCompose)
- Bash("docker-compose build")
- Bash("docker-compose up -d")
- Bash("docker-compose exec web python manage.py migrate")
๐ PYTHON CODE QUALITY COORDINATION
๐จ Code Formatting and Linting
Quality Tools Batch:
[BatchTool]:
- Write(".pre-commit-config.yaml", preCommitConfig)
- Write("pyproject.toml", blackConfig)
- Write(".flake8", flake8Config)
- Write("mypy.ini", mypyConfig)
- Bash("pip install black flake8 mypy isort pre-commit")
- Bash("pre-commit install")
- Bash("black src/ tests/ && flake8 src/ tests/ && mypy src/")
๐ Documentation Coordination
Documentation Setup:
[BatchTool]:
- Write("docs/conf.py", sphinxConfig)
- Write("docs/index.rst", docsIndex)
- Write("docs/api.rst", apiDocs)
- Bash("pip install sphinx sphinx-rtd-theme")
- Bash("sphinx-build -b html docs/ docs/_build/")
๐ PYTHON CI/CD COORDINATION
๐๏ธ GitHub Actions for Python
CI/CD Pipeline Batch:
[BatchTool]:
- Write(".github/workflows/ci.yml", pythonCI)
- Write(".github/workflows/deploy.yml", deploymentWorkflow)
- Write("scripts/test.sh", testScript)
- Write("scripts/lint.sh", lintScript)
- Bash("python -m pytest --cov=src tests/")
- Bash("black --check src/ tests/")
- Bash("flake8 src/ tests/")
๐ก PYTHON BEST PRACTICES
๐ Code Quality Standards
- PEP 8 Compliance: Follow Python style guide
- Type Hints: Use static typing with MyPy
- Docstrings: Comprehensive documentation
- Error Handling: Proper exception management
- Testing: High test coverage with Pytest
- Virtual Environments: Isolated dependencies
๐ฏ Performance Optimization
- List Comprehensions: Efficient data processing
- Generators: Memory-efficient iteration
- Asyncio: Asynchronous programming patterns
- Caching: Redis, memory caching strategies
- Database Optimization: Query optimization, connection pooling
- Profiling: Regular performance analysis
๐ PYTHON LEARNING RESOURCES
๐ Recommended Topics
- Core Python: Data structures, OOP, decorators
- Web Frameworks: Django, FastAPI, Flask
- Data Science: Pandas, NumPy, Matplotlib, Scikit-learn
- Machine Learning: TensorFlow, PyTorch, Keras
- Testing: Pytest, unittest, test-driven development
- DevOps: Docker, deployment, CI/CD pipelines
๐ง Essential Tools
- Package Management: pip, Poetry, conda
- Code Quality: Black, Flake8, MyPy, pre-commit
- Testing: Pytest, Coverage.py, tox
- Documentation: Sphinx, MkDocs
- IDEs: PyCharm, VS Code, Jupyter
- Deployment: Gunicorn, uWSGI, Docker
Remember: Python swarms excel with virtual environment coordination, parallel package management, and integrated testing. Always batch pip operations and leverage Python's rich ecosystem for optimal development workflow.
Explore More
Related Templates
Related Guides
ClaudeCode Best Practices & Pro Tips
Master ClaudeCode with expert tips, proven workflows, and best practices. Learn how to maximize productivity and get the most out of AI-powered development.
Claude Code Checkpoints & Rewind Feature - Undo AI Code Changes
Learn how to use Claude Code's checkpoints and rewind feature to safely undo AI-generated code changes. Use Esc+Esc or /rewind to rollback mistakes and maintain control over your codebase.