본문 바로가기
C.W.K.
Stream
Lesson 01 of 06 · published

Python SDK는 설치한 버전부터 증명해

~12 min · install, pinning, version

Level 0Observer
0 XP0/64 lessons0/13 achievements
0/150 XP to next level150 XP to go0% complete

모델처럼 SDK도 버전을 고정해

PyPI의 anthropic 패키지는 빠르게 바뀌어. 새 도우미와 더 정교한 타입이 들어오고 입력 검증이 엄격해지기도 하지. pyproject.toml이나 requirements.txt에 버전을 고정하고, 변경 기록과 시험을 거쳐 의도적으로 올려. 설치할 때마다 우연히 최신이 되는 상태는 운영 정책이 아니야.

이상 행동을 보기 전에 실제 버전을 확인해

pip show anthropic으로 설치 위치와 버전을 보고, python -c "import anthropic; print(anthropic.__version__)"으로 현재 인터프리터가 불러온 버전을 확인해. 필요하면 anthropic.Anthropic.__doc__도 살펴. 로컬에서는 되는데 CI에서는 깨지는 문제 상당수가 서로 다른 파이썬이나 패키지 버전에서 시작돼.

동기와 비동기 클라이언트를 런타임에 맞춰

같은 패키지에 동기식 Anthropic과 비동기식 AsyncAnthropic이 있어. 짧은 스크립트에는 동기 클라이언트가 단순하고, FastAPI 라우트나 이미 사건 루프가 도는 작업자에는 비동기 클라이언트가 자연스러워. 기능 차이가 아니라 입출력 방식의 선택이야.

원칙: SDK도 업그레이드 절차가 필요한 버전 의존성이야. 로컬과 운영의 차이는 배포 날 발견할 일이 아니야.

Code

핀 설치 (pyproject.toml fragment)·text
[project]
dependencies = [
  "anthropic>=0.49,<0.60",  # 범위, loose X; 의도적으로 bump
  # 필요할 때 옵션 추가:
  # "anthropic[bedrock]",
  # "anthropic[vertex]",
]
로컬·CI 검증·bash
python -c "import anthropic; print(anthropic.__version__)"
pip show anthropic | head -n 5
python - <<'PY'
from anthropic import Anthropic
client = Anthropic()
print(type(client).__name__, [m for m in dir(client) if not m.startswith('_')][:8])
PY
Sync·async 클라이언트 나란히·python
from anthropic import Anthropic, AsyncAnthropic
import asyncio

# Sync — 스크립트랑 CLI 도구에 OK
sync_client = Anthropic()
resp = sync_client.messages.create(
    model="claude-haiku-4-5-20251001",
    max_tokens=64,
    messages=[{"role": "user", "content": "sync hello"}],
)
print("sync:", resp.content[0].text)

# Async — FastAPI / event-loop 코드에 필수
async_client = AsyncAnthropic()
async def go():
    r = await async_client.messages.create(
        model="claude-haiku-4-5-20251001",
        max_tokens=64,
        messages=[{"role": "user", "content": "async hello"}],
    )
    print("async:", r.content[0].text)
asyncio.run(go())

External links

Exercise

프로젝트의 anthropic SDK 버전을 시험한 범위로 고정하고, CI에 실제 설치 버전을 출력하는 한 줄을 넣어. 개발 환경과 같은지 확인해.
Hint
개발 환경이 CI보다 오래됐다면 아직 드러나지 않은 버그를 이미 품고 있을 수 있어.

Progress

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

댓글 0

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

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