Skip to content

Commit 975e64f

Browse files
authored
Update Python instruction (#7)
* Update Python instruction * Fix typo
1 parent b800b9f commit 975e64f

8 files changed

Lines changed: 169 additions & 107 deletions

File tree

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ This is a self-paced workshop by following the links below:
7777

7878
Check out the complete example of each application. They're also vibe-coded with GitHub Copilot, therefore, they might not be perfect, and you don't have to follow the app.
7979

80-
| Language | Location |
81-
|------------------|--------------------------------------|
82-
| Python | [python](./complete/python/) |
83-
| JavaScript | [javascript](./complete/javascript/) |
84-
| Java | [java](./complete/java/) |
85-
| .NET | [dotnet](./complete/dotnet/) |
86-
| Containerization | [containerization](./complete/) |
80+
| Language | Application | Location |
81+
|---------------------|-------------|--------------------------------------|
82+
| Python Backend | FastAPI | [python](./complete/python/) |
83+
| JavaScript Frontend | React | [javascript](./complete/javascript/) |
84+
| Java Backend | Spring Boot | [java](./complete/java/) |
85+
| .NET Frontend | Blazor | [dotnet](./complete/dotnet/) |
86+
| Containerization | Container | [containerization](./complete/) |
8787

8888
## Read More...
8989

docs/00-setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,4 @@ Refer to the [README](../README.md) doc for preparation.
317317

318318
---
319319

320-
OK. You've completed the "Development Environment" step. Let's move onto [STEP 01: Python](./01-python.md).
320+
OK. You've completed the "Development Environment" step. Let's move onto [STEP 01: Python Backend Development](./01-python.md).

docs/01-python.md

Lines changed: 80 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,113 @@
1-
# 01: Python
1+
# 01: Python Backend Development
22

3-
## 시나리오
3+
## Scenario
44

5-
Contoso 아웃도어 컴파니의 마케팅 팀에서는 제품 홍보를 위한 마이크로 소셜 미디어 웹사이트를 빠르게 론칭하고 싶어 합니다. 개발팀의 Python 개발자인 당신은 GitHub Codespaces 안에서 GitHub Copilot을 이용해 간단한 백엔드 API를 만들어 달라는 요청을 받았습니다. 이에 따라 FastAPI를 사용하여 SNS 기능을 구현하고, 간단히 SQLite 데이터베이스를 연동해 CRUD를 수행하려고 합니다.
5+
Contoso is a company that sells products for various outdoor activities. A marketing department of Contoso would like to launch a micro social media website to promote their products for existing and potential customers.
66

7-
## 사전 준비사항
7+
As a Python developer, you're going to build a Python backend app using FastAPI. For now, you're using the in-memory feature of SQLite.
88

9-
[README](../README.md) 문서를 참조하여 개발 환경을 준비합니다.
9+
## Prerequisites
1010

11-
## 순서
11+
Refer to the [README](../README.md) doc for preparation.
1212

13-
- [개발 과정 프롬프트](#개발-과정-프롬프트)
14-
- [FastAPI 앱 프로젝트 준비](#fastapi-앱-프로젝트-준비)
15-
- [CRUD API 구현](#crud-api-구현)
16-
- [가상환경으로 앱 실행](#가상환경으로-앱-실행)
17-
- [API 확인](#api-확인)
18-
- [기본 데이터베이스 테이블 생성](#기본-데이터베이스-테이블-생성)
19-
- [서비스 종료](#서비스-종료)
13+
## Getting Started
2014

21-
## 개발 과정 프롬프트
15+
- [Check GitHub Copilot Agent Mode](#check-github-copilot-agent-mode)
16+
- [Prepare Custom Instructions](#prepare-custom-instructions)
17+
- [Prepare Virtual Environment](#prepare-virtual-environment)
18+
- [Build FastAPI Backend App](#build-fastapi-backend-app)
2219

23-
아래는 FastAPI 앱을 개발하여 간단한 SNS 기능을 구현하는 과정입니다.
20+
### Check GitHub Copilot Agent Mode
2421

25-
- FastAPI 앱 프로젝트 준비
26-
- CRUD API 구현
27-
- 가상환경으로 앱 실행
28-
- API 확인
29-
- 기본 데이터베이스 테이블 생성
22+
1. Click the GitHub Copilot icon on the top of GitHub Codespace or VS Code and open GitHub Copilot window.
3023

31-
### FastAPI 앱 프로젝트 준비
24+
![Open GitHub Copilot Chat](./images/setup-02.png)
3225

33-
1. 가상환경 생성
26+
1. If you're asked to login or sign up, do it. It's free of charge.
27+
1. Make sure you're using GitHub Copilot Agent Mode.
3428

35-
Python 프로젝트 디렉토리를 생성하고, 다음 명령어로 가상환경(venv)을 만듭니다:
29+
![GitHub Copilot Agent Mode](./images/setup-03.png)
3630

37-
```bash
38-
python -m venv .venv
39-
```
31+
1. Select model to either `GPT-4.1` or `Claude Sonnet 4`.
4032

41-
1. 가상환경 활성화 및 FastAPI 설치
33+
### Prepare Custom Instructions
4234

43-
**Windows**
35+
1. Set the environment variable of `$REPOSITORY_ROOT`.
4436

45-
```pwsh
46-
.venv/Scripts/activate
47-
```
37+
```bash
38+
# bash/zsh
39+
REPOSITORY_ROOT=$(git rev-parse --show-toplevel)
40+
```
4841

49-
**MacOS**, **Linux** 또는 **GitHub Codespaces**
42+
```powershell
43+
# PowerShell
44+
$REPOSITORY_ROOT = git rev-parse --show-toplevel
45+
```
5046

51-
```bash
52-
source .venv/bin/activate
53-
```
47+
1. Copy custom instructions.
5448

5549
```bash
56-
pip install fastapi uvicorn
50+
# bash/zsh
51+
cp -r $REPOSITORY_ROOT/docs/custom-instructions/python/. \
52+
$REPOSITORY_ROOT/.github/
5753
```
5854

59-
1. main.py 빈 파일 생성
60-
61-
### CRUD API 구현
62-
63-
FastAPI를 활용하여 소셜 네트워크 서비스의 모든 핵심 기능을 REST API로 구현합니다.
64-
65-
```text
66-
FastAPI를 사용하여 openapi.yaml 명세를 기반으로 소셜 네트워크 서비스의 백엔드 API를 구현해. openapi.yaml의 정의에 따라 포스트, 댓글, 좋아요 기능을 포함하는 모든 엔드포인트를 구현한다. 명세에 맞게 적절한 HTTP 메소드, 상태 코드, 요청/응답 형식을 구현하낟. Pydantic 모델을 사용하여 데이터 검증을 구현하고, 예외 처리도 포함해주세요. 데이터는 데이터베이스 없이 간단한 메모리로 관리한다. main.py 파일 하나에 모두 구현한다.
67-
```
68-
69-
### 가상환경으로 앱 실행
70-
71-
```bash
72-
source .venv/bin/activate
73-
```
74-
75-
```bash
76-
uvicorn python.main:app --reload
77-
```
78-
79-
### API 확인
80-
81-
브라우저에서 http://127.0.0.1:8000/docs 접속
82-
83-
### 기본 데이터베이스 테이블 생성
84-
85-
애플리케이션에 필요한 데이터를 저장할 SQLite 데이터베이스 스키마를 구성합니다.
55+
```powershell
56+
# PowerShell
57+
Copy-Item -Path $REPOSITORY_ROOT/docs/custom-instructions/python/* `
58+
-Destination $REPOSITORY_ROOT/.github/ -Recurse -Force
59+
```
8660

87-
```text
88-
SQLite 데이터베이스를 사용하여 openapi.yaml 명세를 참고하여 현재 정의된 API를 구현한다. 애플리케이션 시작 시 자동으로 데이터베이스와 테이블을 생성하는 코드를 구현하되, 테이블이 이미 존재하는 경우 다시 생성하지 않도록 'CREATE TABLE IF NOT EXISTS' 구문을 사용하세요.
89-
```
61+
### Prepare Virtual Environment
9062

91-
서버를 재시작한 후에도 SQLite 데이터베이스에 저장된 포스트 데이터가 유지되는지 확인합니다.
63+
1. Make sure that you're using GitHub Copilot Agent Mode with the model of `Claude Sonnet 4` or `GPT-4.1`.
64+
1. Use prompt like below to prepare virtual environment for Python app development.
9265
93-
## 서비스 종료
66+
```text
67+
I'd like to write a Python application. But before that, I need to set up a virtual environment. Follow the instructions below.
68+
69+
- Your working directory is `python`.
70+
- Identify all the steps first, which is you're going to do.
71+
- Use `.venv` for the virtual environment.
72+
- Use `uv` as the Python package manager.
73+
```
9474
95-
FastAPI 서버 등 현재 실행 중인 백엔드 서비스를 종료하려면, 터미널에서 **Ctrl + C**를 누르세요.
96-
이렇게 하면 서버가 정상적으로 종료되어 포트(예: 8000번)를 다른 백엔드 서비스가 사용할 수 있습니다.
75+
### Build FastAPI Backend App
76+
77+
1. Make sure that you're using GitHub Copilot Agent Mode with the model of `Claude Sonnet 4` or `GPT-4.1`.
78+
1. Add [`product-requirements.md`](../product-requirements.md) and [`openapi.yaml`](../openapi.yaml) to GitHub Copilot.
79+
1. Use prompt like below to build a FastAPI backend application.
80+
81+
```text
82+
I'd like to build a FastAPI application as a backend API. Carefully read the entire PRD and `openapi.yaml`. Then, follow the instructions below.
83+
84+
- Your working directory is `python`.
85+
- Identify all the steps first, which is you're going to do.
86+
- Use FastAPI as the API app framework.
87+
- Use SQLite as the database.
88+
- Use in-memory feature of SQLite.
89+
- The database should always be initialized whenever starting the app.
90+
- Use `openapi.yaml` that describes all the endpoints and data schema.
91+
- Use the port number of `5050`.
92+
- Entrypoint is `main.py`.
93+
- The API application should render Swagger UI page through a default endpoint.
94+
- The API application should render exactly the same OpenAPI document through a default endpoint.
95+
- DO NOT add anything not defined in `openapi.yaml`.
96+
- DO NOT modify anything defined in `openapi.yaml`.
97+
```
9798

98-
만약 서버가 백그라운드에서 실행 중이거나 포트가 여전히 점유 중이라면, 아래 명령어로 프로세스를 확인하고 종료할 수 있습니다.
99+
1. Once the application is built, verify if it's written properly or not.
99100
100-
```bash
101-
lsof -i :8000
102-
kill <PID>
103-
```
101+
```text
102+
Run the Python app and verify if the app is properly running. Also verify the OpenAPI endpoint renders exactly the same content as `openapi.yaml`.
104103
105-
lsof 명령어를 수행하면 아래처럼 나옵니다. "--reload" 옵션으로 서비스를 띄웠기 때문에 코드 변경을 감시하는 서버가 하나 더 띄워져서 두 개가 나옵니다.
104+
If app running fails, analyze the issues and fix them.
105+
```
106106
107-
```bash
108-
(base) tykimos@MacBook-Air-2 crewai % lsof -i :8000
109-
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
110-
Python 12707 tykimos 3u IPv4 0x9fddcce1c1588271 0t0 TCP localhost:irdmi (LISTEN)
111-
Python 12710 tykimos 3u IPv4 0x9fddcce1c1588271 0t0 TCP localhost:irdmi (LISTEN)
112-
```
107+
1. Open a web browser and navigate to `http://localhost:5050`.
113108
114-
이 경우 코드 변경 감시 서버만 종료하면 되지만 확인이 힘들다면 둘 다 종료시킵니다.
109+
1. Click the `[keep]` button of GitHub Copilot to take the changes.
115110
116-
```bash
117-
kill 12707
118-
kill 12710
119-
```
111+
---
120112
121-
그럼 다른 백엔드 서비스를 동일한 포트에서 실행할 수 있습니다.
113+
OK. You've completed the "Python" step. Let's move onto [STEP 02: JavaScript Frontend Development](./02-javascript.md).

docs/02-javascript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 02: JavaScript
1+
# 02: JavaScript Frontend Development
22

33
## 시나리오
44

docs/03-java.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 03: Java
1+
# 03: Java Migration from Python
22

33
## 시나리오
44

docs/04-dotnet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 04: .NET
1+
# 04: .NET Migration from JavaScript
22

33
## Scenario
44

docs/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
Here are the self-paced learning instruction materials. Use them and build apps!
44

5-
| Step | Link |
6-
|-----------------------------|----------------------------------------------------|
7-
| 00: Development Environment | [00-setup.md](./00-setup.md) |
8-
| 01: Python | [01-python.md](./01-python.md) |
9-
| 02: JavaScript | [02-javascript.md](./02-javascript.md) |
10-
| 03: Java | [03-java.md](./03-java.md) |
11-
| 04: .NET | [04-dotnet.md](./04-dotnet.md) |
12-
| 05: Containerization | [05-containerization.md](./05-containerization.md) |
5+
| Step | Link |
6+
|-------------------------------------|----------------------------------------------------|
7+
| 00: Development Environment | [00-setup.md](./00-setup.md) |
8+
| 01: Python Backend Development | [01-python.md](./01-python.md) |
9+
| 02: JavaScript Frontend Development | [02-javascript.md](./02-javascript.md) |
10+
| 03: Java Migration from Python | [03-java.md](./03-java.md) |
11+
| 04: .NET Migration from JavaScript | [04-dotnet.md](./04-dotnet.md) |
12+
| 05: Containerization | [05-containerization.md](./05-containerization.md) |
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Python Development Rules
2+
3+
You are a senior Python developer and an expert in Python, FastAPI, SQLite and scalable API development.
4+
5+
## Key Principles
6+
7+
- Write concise, technical responses with accurate Python examples.
8+
- Use functional, declarative programming; avoid classes where possible.
9+
- Prefer iteration and modularization over code duplication.
10+
- Use descriptive variable names with auxiliary verbs (e.g., is_active, has_permission).
11+
- Use lowercase with underscores for directories and files (e.g., routers/user_routes.py).
12+
- Favor named exports for routes and utility functions.
13+
- Use the Receive an Object, Return an Object (RORO) pattern.
14+
15+
## Python/FastAPI
16+
17+
- Use def for pure functions and async def for asynchronous operations.
18+
- Use type hints for all function signatures. Prefer Pydantic models over raw dictionaries for input validation.
19+
- File structure: exported router, sub-routes, utilities, static content, types (models, schemas).
20+
- Avoid unnecessary curly braces in conditional statements.
21+
- For single-line statements in conditionals, omit curly braces.
22+
- Use concise, one-line syntax for simple conditional statements (e.g., if condition: do_something()).
23+
24+
## Error Handling and Validation
25+
26+
- Prioritize error handling and edge cases:
27+
- Handle errors and edge cases at the beginning of functions.
28+
- Use early returns for error conditions to avoid deeply nested if statements.
29+
- Place the happy path last in the function for improved readability.
30+
- Avoid unnecessary else statements; use the if-return pattern instead.
31+
- Use guard clauses to handle preconditions and invalid states early.
32+
- Implement proper error logging and user-friendly error messages.
33+
- Use custom error types or error factories for consistent error handling.
34+
35+
## Dependencies
36+
37+
- FastAPI
38+
- Pydantic v2
39+
- Async database libraries like asyncpg or aiomysql
40+
- SQLAlchemy 2.0 (if using ORM features)
41+
42+
## FastAPI-Specific Guidelines
43+
44+
- Use functional components (plain functions) and Pydantic models for input validation and response schemas.
45+
- Use declarative route definitions with clear return type annotations.
46+
- Use def for synchronous operations and async def for asynchronous ones.
47+
- Minimize @app.on_event("startup") and @app.on_event("shutdown"); prefer lifespan context managers for managing startup and shutdown events.
48+
- Use middleware for logging, error monitoring, and performance optimization.
49+
- Optimize for performance using async functions for I/O-bound tasks, caching strategies, and lazy loading.
50+
- Use HTTPException for expected errors and model them as specific HTTP responses.
51+
- Use middleware for handling unexpected errors, logging, and error monitoring.
52+
- Use Pydantic's BaseModel for consistent input/output validation and response schemas.
53+
54+
## Performance Optimization
55+
56+
- Minimize blocking I/O operations; use asynchronous operations for all database calls and external API requests.
57+
- Implement caching for static and frequently accessed data using tools like Redis or in-memory stores.
58+
- Optimize data serialization and deserialization with Pydantic.
59+
- Use lazy loading techniques for large datasets and substantial API responses.
60+
61+
## Key Conventions
62+
63+
1. Rely on FastAPI’s dependency injection system for managing state and shared resources.
64+
2. Prioritize API performance metrics (response time, latency, throughput).
65+
3. Limit blocking operations in routes:
66+
- Favor asynchronous and non-blocking flows.
67+
- Use dedicated async functions for database and external API operations.
68+
- Structure routes and dependencies clearly to optimize readability and maintainability.
69+
70+
Refer to FastAPI documentation for Data Models, Path Operations, and Middleware for best practices.

0 commit comments

Comments
 (0)