| title | Python Code Quality Standards | ||||
|---|---|---|---|---|---|
| description | Guides Kiro to write clean, consistent Python code | ||||
| category | code-quality | ||||
| tags |
|
||||
| inclusion | always | ||||
| applicableTo |
|
||||
| filePatterns |
|
This steering document guides Kiro to write Python code that follows basic standards and avoids common syntax errors. When Kiro generates or edits Python files, it will automatically apply these standards.
You MUST follow these rules when creating or editing Python files:
-
You MUST use 4-space indentation (never tabs or mixed spacing)
-
You MUST organize imports (standard library, third-party, local)
-
You MUST use snake_case for functions/variables and PascalCase for classes
-
You MUST catch specific exceptions (not bare
except:) -
You MUST NOT mix tabs and spaces (this breaks Python)
Always use 4 spaces: Never mix tabs and spaces (this breaks Python!)
# Kiro will write:
def example_function():
if condition:
return 'properly indented'
else:
return 'consistent spacing'
# Not mixed tabs/spaces or 2-space indentationGroup imports: Standard library first, then third-party, then local imports
# Kiro will write:
import os
import sys
import requests
import pandas as pd
from .models import User
from .utils import helper_function
# Not scattered or mixed throughout the fileUse Python naming patterns: snake_case for functions/variables, PascalCase for classes
# Kiro will write:
class UserManager:
def __init__(self, database_url):
self.database_url = database_url
def create_user(self, user_data):
user_id = self._generate_id()
return self._save_user(user_id, user_data)
# Not camelCase or inconsistent namingSimple exception handling: Catch specific errors, avoid bare except
# Kiro will write:
def process_file(filename):
try:
with open(filename, 'r') as file:
return file.read()
except FileNotFoundError:
print(f"File {filename} not found")
return None
# Avoid bare except: clauses-
Indentation errors that break Python code
-
Import chaos with scattered dependencies
-
Naming inconsistencies across functions and classes
-
Silent errors from poor exception handling
# Kiro will write:
def calculate_total(items):
total = 0
for item in items:
if item.get('price'):
total += item['price']
return total
# Clean, consistent, readable# Kiro will write:
class Calculator:
def __init__(self):
self.result = 0
def add(self, number):
self.result += number
return self.result
# Simple, clear structureThis is your starting point! You can modify these rules by editing this steering document:
-
Adjust indentation if your team uses a different standard
-
Change import organization patterns
-
Add project-specific naming conventions
-
Include additional error handling patterns
Want to validate that generated code follows these standards? Add these tools:
pip install black flake8
# Format code
black your_file.py
# Check for issues
flake8 your_file.py
Note: These tools validate the code after Kiro writes it, but aren't required for the steering document to work.
This steering document works automatically when you:
-
Ask Kiro to create Python files (.py)
-
Request code modifications or refactoring
-
Generate Python scripts or modules
The formatting rules apply consistently across all Python code generation in your project.