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

Install, Pin, and Verify the SDK

~12 min · install, pinning, version

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

Pin the SDK like you pin your model

The anthropic package on PyPI moves quickly. New SDK releases add helpers, refine types, and occasionally tighten validation. Pin the version in pyproject.toml or requirements.txt the same way you pin your model id — then upgrade deliberately, not accidentally.

Verify what is actually installed

Before you debug an SDK quirk, prove which version is running in the venv. pip show anthropic, python -c "import anthropic; print(anthropic.__version__)", and a quick look at anthropic.Anthropic.__doc__ are the three commands that catch 80% of 'why does this work locally and not in CI' bugs.

The two clients

The SDK ships two clients in one package: Anthropic (sync) and AsyncAnthropic (async). Same surface, different I/O model. Pick by your runtime — sync for scripts, async for FastAPI routes and any code that already runs an event loop.

Principle: Treat the SDK as a versioned dependency with a real upgrade story. Drift between local and prod is a planning bug, not a deploy surprise.

Code

Pinned install (pyproject.toml fragment)·text
[project]
dependencies = [
  "anthropic>=0.49,<0.60",  # range, not loose; bump intentionally
  # Optional extras when you need them:
  # "anthropic[bedrock]",
  # "anthropic[vertex]",
]
Verify locally and in 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 and async clients side by side·python
from anthropic import Anthropic, AsyncAnthropic
import asyncio

# Sync — fine for scripts and CLI tools
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 — required for FastAPI / event-loop code
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

Lock the anthropic SDK to a tested range in your project. Add a one-line CI step that prints the installed version. Verify it matches your dev box. Three commits, three lines.
Hint
If your venv is older than your CI, you have already shipped the bug — just have not seen it yet.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.