Python 가이드

Kiro의 AI 보조 기능을 활용해 Python 프로젝트를 더 빠르게 작성하고, 디버깅하고, 유지보수하는 방법을 정리했습니다.

사전 준비

추천 확장 프로그램

Kiro는 Open VSX 호환 확장을 지원합니다. Python 개발에 특히 유용한 확장은 다음과 같습니다.

Extensions 패널을 열고 위 이름으로 검색해 설치하세요.

환경 구성과 프로젝트 구조

Kiro에게 자연어로 요청하면 Python 모범 사례를 따르는 설정 파일과 디렉터리 구조를 만들어 줍니다.

"Set up a requirements.txt with development dependencies"
"Configure a .env file for my Django application"
"Set up a Python package structure with proper __init__.py files"
"Create a Flask project structure with blueprints"
"Organize my data science project with notebooks and modules"
"Create a pyproject.toml for a FastAPI project with pytest and black"

코드 분석과 리팩터링

"Analyze this function for potential bugs and performance issues"
"Refactor this code to follow PEP 8 style guidelines"
"Add type hints to this Python module"
"Convert this synchronous code to use async/await"

디버깅 보조

트레이스백을 평이한 언어로 풀어 설명하고, 일반적인 오류 패턴에 대한 해결책과 디버그 구성을 제안합니다.

"Explain this Python error: AttributeError: 'NoneType' object has no attribute 'split'"
"Help me debug this Django view that's returning a 500 error"
"Why is my pandas DataFrame operation so slow?"

Steering으로 컨텍스트 제공하기

Steering은 Kiro에게 프로젝트별 맥락을 알려주는 장치입니다. 기본 파일은 다음과 같습니다.

  1. Product briefproduct.md
  2. Technical Stacktech.md
  3. Project Structurestructure.md

커스텀 Steering 파일 만들기

  1. 왼쪽의 Kiro 사이드바를 엽니다.
  2. Agent Steering 영역에서 + 버튼을 클릭합니다.
  3. 의미가 드러나는 파일명을 입력합니다.
  4. 마크다운으로 규칙과 설명을 작성합니다.

저장 위치는 .kiro/steering/ 디렉터리입니다.

코드 스타일 규약 예시 (python-conventions.md)

Python Conventions
Naming Conventions
- Use snake_case for variables and functions
- Use PascalCase for classes
- Use UPPER_SNAKE_CASE for constants
- Use descriptive names that explain purpose

Code Style
- Follow PEP 8 guidelines
- Use Black for code formatting
- Maximum line length of 88 characters
- Use type hints for all public functions

File Structure
- One class per file for large classes
- Group related functions in modules
- Use __init__.py files for package organization
- Separate tests in tests/ directory

Documentation
- Use docstrings for all public functions and classes
- Follow Google or NumPy docstring style
- Include type information in docstrings

Django 가이드라인 예시 (django-patterns.md)

Django Development Guidelines
Model Design
- Use descriptive model names
- Add __str__ methods to all models
- Use model managers for complex queries
- Follow Django naming conventions for fields

View Structure
- Prefer class-based views for complex logic
- Use function-based views for simple operations
- Keep business logic in models or services
- Use proper HTTP status codes

Template Organization
- Use template inheritance effectively
- Keep templates DRY with includes and tags
- Use meaningful template names
- Organize templates by app

Performance Best Practices
- Use select_related and prefetch_related for queries
- Implement database indexing for frequently queried fields
- Use caching for expensive operations
- Profile database queries in development

데이터 사이언스 예시 (data-science-patterns.md)

Data Science Development Guidelines
Notebook Organization
- Use clear section headers and markdown cells
- Keep notebooks focused on single analyses
- Export reusable code to Python modules
- Include data source documentation

Data Handling
- Validate data quality early in pipelines
- Use consistent column naming conventions
- Document data transformations clearly
- Handle missing values explicitly

Model Development
- Use cross-validation for model evaluation
- Track experiments with clear versioning
- Document model assumptions and limitations
- Implement proper train/validation/test splits

Code Organization
- Separate data processing, modeling, and visualization
- Use configuration files for parameters
- Implement logging for long-running processes
- Create reproducible environments with requirements files

Agent Hooks로 반복 작업 자동화

Hooks는 자주 반복되는 작업을 자동화하는 트리거입니다.

  1. Kiro 패널에서 Agent Hooks로 이동합니다.
  2. + 버튼을 눌러 새 훅를 추가합니다.
  3. 원하는 동작을 자연어로 설명합니다.

활용 예시

테스트 자동 생성 훅

"Create a hook that generates pytest tests when I save a new Python module"

의존성 업데이트 훅

"Create a hook that checks for outdated pip packages and suggests updates"

린팅 훅

When a Python file is saved:
1. Run flake8 or pylint on the file
2. Report any style or quality issues
3. Suggest fixes for common problems
4. Update docstrings if missing

가상 환경 점검 훅

When requirements.txt or pyproject.toml is modified:
1. Check if virtual environment is activated
2. Install or update dependencies automatically
3. Report any dependency conflicts
4. Update requirements-dev.txt if needed

#docs로 문서 참조하기

채팅에서 #docs를 입력하면 공식 문서를 컨텍스트로 가져올 수 있습니다.

"#Python How do I use context managers effectively?"
"#Pytorch how can I add a custom operator?"
"#PySide6 What is the best way to add a button?"

특정 URL을 직접 참조하려면 #URL을 사용합니다.

"#URL https://docs.python.org/3/library/asyncio.html"

오류를 만났을 때

  1. Inline ChatCmd/Ctrl + I로 인라인 채팅을 엽니다.
  2. Add to ChatCmd/Ctrl + L로 현재 파일을 채팅에 추가합니다.
  3. Quick Fix — 오류나 경고 위에 마우스를 올린 뒤 Quick fixAsk Kiro를 선택합니다.
트레이스백 전체를 채팅에 붙여 넣으면 Kiro가 원인 후보와 수정안을 함께 제시합니다.

참고 자료