C.W.K.
Stream
Lesson 01 of 06 · published

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 패키지는 빠르게 움직여. 새 SDK 릴리스마다 헬퍼 추가, 타입 정제, 가끔은 validation 강화. 모델 id 핀하듯 pyproject.toml이나 requirements.txt에 버전을 핀해 — 그다음 의도적으로 업그레이드, 우연히 X.

실제로 깔린 게 뭔지 검증

SDK quirk debug 전에 venv에서 어느 버전 도는지 증명. pip show anthropic, python -c "import anthropic; print(anthropic.__version__)", anthropic.Anthropic.__doc__ 한 번 — '왜 로컬에서 되는데 CI에서 안 돼' 버그 80%를 잡는 세 명령어.

두 클라이언트

SDK가 한 패키지 안에 클라이언트 두 개 — Anthropic(sync), AsyncAnthropic(async). 같은 표면, 다른 I/O 모델. 런타임에 따라 골라 — 스크립트엔 sync, FastAPI 라우트랑 이미 event loop 도는 코드엔 async.

원칙: SDK를 진짜 업그레이드 스토리 가진 versioned 의존성으로 다뤄. 로컬과 prod 간 drift는 플래닝 버그지 배포 깜짝쇼 아니야.

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를 테스트된 범위로 lock. 설치 버전 출력하는 한 줄 CI 단계 추가. 개발 박스랑 매칭 검증. 세 commit, 세 줄.
Hint
Venv가 CI보다 오래되면 이미 버그 ship한 거 — 아직 못 본 것뿐.

Progress

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

댓글 0

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

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