π Python Project Guide
This guide covers how to make the most of ECC in Python projects.
Quick Setupβ
1. Install the Python Rule Packβ
# Copy Python rules to the CodeBuddy config directory
cp -r rules/python/* ~/.codebuddy/rules/
2. Virtual Environment Setupβ
ECC automatically detects and manages virtual environments:
# If .venv doesn't exist, ECC will create it automatically
uv venv -p 3.11
# Activate the environment
source .venv/bin/activate
3. Recommended Project Structureβ
your-project/
βββ .codebuddy/
β βββ rules/ # Project-specific rules
βββ src/
β βββ your_package/
β βββ __init__.py
β βββ main.py
β βββ utils.py
βββ tests/
β βββ unit/
β βββ integration/
βββ pyproject.toml
βββ requirements.txt
Recommended Workflowβ
New Feature Developmentβ
# 1. Plan
/plan Implement a data processing pipeline
# 2. TDD development
/tdd --feature="data-pipeline"
# 3. Code review
/code-review src/
# 4. Test coverage
/test --coverage
Data Science Projectsβ
# 1. Exploratory analysis planning
/plan Analyze user behavior data
# 2. Architecture design
/architect Design an ETL pipeline
# 3. Implementation
/tdd --feature="etl-transform"
Hook Configurationβ
Recommended Python Hooksβ
{
"hooks": {
"postToolUse": [
{
"name": "black",
"trigger": "*.py",
"command": "black"
},
{
"name": "ruff",
"trigger": "*.py",
"command": "ruff check --fix"
},
{
"name": "mypy",
"trigger": "*.py",
"command": "mypy"
}
]
}
}
Best Practicesβ
Type Annotationsβ
# β
Use type annotations
from typing import Optional, List
def process_users(
users: List[dict],
filter_active: bool = True
) -> List[dict]:
"""Process a list of users"""
if filter_active:
return [u for u in users if u.get('active')]
return users
Data Validation (Pydantic)β
# β
Use Pydantic for data validation
from pydantic import BaseModel, EmailStr
class User(BaseModel):
id: int
email: EmailStr
name: str
class Config:
frozen = True # Immutable
Error Handlingβ
# β
Use context managers and specific exceptions
try:
with open(filepath, 'r') as f:
data = json.load(f)
except FileNotFoundError:
logger.error(f"File not found: {filepath}")
raise
except json.JSONDecodeError as e:
logger.error(f"JSON parse error: {e}")
raise
Testing Frameworkβ
Recommended pytest Configurationβ
# pytest.ini
[pytest]
testpaths = tests
python_files = test_*.py
python_functions = test_*
addopts = -v --cov=src --cov-report=html
Common Commandsβ
| Scenario | Command |
|---|---|
| Start a new feature | /plan Feature description |
| TDD development | /tdd --feature="name" |
| Code review | /code-review |
| Type checking | /typecheck |
| Security scan | /security |
π‘ Tip: For Python projects, we recommend pytest as the test framework and ruff as a replacement for flake8 + isort!