Capability · Framework — orchestration

Anthropic SDK (Python)

The Anthropic Python SDK is the canonical way to call Claude models from Python. It offers synchronous and async clients, first-class streaming, typed message parts (text, image, tool_use, tool_result), retry/backoff, and helpers for long-running features like Batch, Files, and MCP. The SDK targets Python 3.9+ and is generated from the same OpenAPI spec that powers the TS and Go SDKs.

Framework facts

Category
orchestration
Language
Python
License
MIT
Repository
https://github.com/anthropics/anthropic-sdk-python

Install

pip install anthropic
export ANTHROPIC_API_KEY=sk-ant-...

Quickstart

from anthropic import Anthropic

client = Anthropic()
resp = client.messages.create(
    model='claude-opus-4-7',
    max_tokens=1024,
    messages=[{'role':'user','content':'Explain attention in one paragraph.'}]
)
print(resp.content[0].text)

Alternatives

  • Anthropic TS SDK — JavaScript/TypeScript equivalent
  • LiteLLM / OpenRouter — provider-agnostic proxies
  • LangChain / Mirascope — higher-level Python wrappers
  • Direct httpx calls against the Messages API

Frequently asked questions

Sync or async?

Use `AsyncAnthropic` in async web apps (FastAPI, Starlette) for higher concurrency. Sync is fine for scripts and batch jobs.

Does the SDK support prompt caching?

Yes — set `cache_control={'type':'ephemeral'}` on message parts. The SDK passes the beta header automatically when you use the helper; see the docs for the exact cache lifetime.

Sources

  1. Anthropic Python SDK GitHub — accessed 2026-04-20
  2. Anthropic API docs — accessed 2026-04-20