C.W.K.
Stream
Lesson 04 of 05 · published

Prefect — Pythonic 대안

~11 min · prefect, flows, orchestration

Level 0구경꾼
0 XP0/47 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

라이브러리처럼 느껴지는 orchestration

Prefect (2026.4 기준 3.x) 는 한 가지에 최적화: "Python 처럼 느껴져야지, platform 처럼 말고." Flow 가 decorate 된 Python 함수. Task 가 decorate 된 Python 함수. python flow.py 로 local 실행, 같은 코드를 Prefect Cloud 또는 self-hosted 서버에 rewrite 없이 배포 가능.

Prefect 가 다른 거 대비 강조하는 거

  • Native async/await. Task 가 coroutine 가능. 동시성이 first-class.
  • Hybrid 실행. Prefect Cloud 가 orchestrate; 본인 코드는 본인 인프라에서 실행 (시크릿 + 데이터가 본인 네트워크 떠나지 않음).
  • 작은 프로젝트엔 의식 적음. 단일 Python 파일이 배포 가능 flow.
  • Stateful flow. Task 가 result 통해 통신, retry 시 자동 cache + replay.

Code

Prefect flow — Pythonic, async-friendly, 그대로 배포 가능·python
import pandas as pd
from prefect import flow, task, get_run_logger

@task(retries=3, retry_delay_seconds=30)
def extract(ds: str) -> pd.DataFrame:
    log = get_run_logger()
    df = pd.read_csv(f'source/orders_{ds}.csv', dtype=str)
    log.info('extracted %d rows', len(df))
    return df

@task
def transform(raw: pd.DataFrame) -> pd.DataFrame:
    return (raw
        .assign(amount_usd=lambda d: pd.to_numeric(d['amount_usd']))
        .dropna(subset=['amount_usd']))

@task
def load(clean: pd.DataFrame, ds: str) -> str:
    path = f'warehouse/orders/date={ds}/part-0.parquet'
    clean.to_parquet(path, index=False)
    return path

@flow(name='orders_pipeline')
def orders_pipeline(ds: str = '2026-04-30') -> str:
    raw = extract(ds)
    clean = transform(raw)
    return load(clean, ds)

if __name__ == '__main__':
    orders_pipeline('2026-04-30')

External links

Exercise

새 venv 에서 pip install prefect. 위 orders flow 복사. python flow.py 실행 — local 실행. 그리고 다른 터미널에서 prefect server start, localhost:4200 에서 UI 열고 다시 실행 — 같은 코드, 이제 UI 에서 보임. 핵심: 배포는 대부분 config flip, rewrite 아님.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.