-
Notifications
You must be signed in to change notification settings - Fork 1.2k
CLAUDE MD Python
MANDATORY RULE: Python projects require virtual environment coordination with pip/conda parallel operations.
ABSOLUTE RULE: ALL Python operations MUST be concurrent/parallel in a single message:
- 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
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)
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")
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 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 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")
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 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/")
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 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")
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 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/*")
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
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")
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")
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 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")
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 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/")
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/")
- 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
- 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
- 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
- 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.