Skip to main content

Anthropic Python SDK

Official Python library for the Claude API

LLM FrameworksPaid

The Anthropic Python SDK is the official Python client for the Claude API. It provides typed interfaces for current Claude models (Claude Fable 5.2, Opus 5.5, Sonnet 5.5 and Haiku 5.5), streaming, tool use, vision and batch requests.

Key specs
10,000,000 Monthly PyPI downloads source
as of 2026-03-27

Maker of Anthropic Python SDK? Get your db.fyi badge

What we know

PricingPaidfrom our original listing, not yet re-checked

Why it matters

  • 10M+ monthly PyPI downloads — the standard SDK for Claude integration in Python applications.
  • Claude's strong results on coding, reasoning and instruction following make the SDK a common starting point for AI apps.
  • A 1M-token context window on current models handles very long documents, codebases and conversations.
  • Tool use (function calling) enables agentic applications where Claude takes actions, retrieves data, and completes multi-step tasks.

Key capabilities

  • Chat completions: client.messages.create() for all Claude models (Sonnet, Haiku, Opus).
  • Streaming: client.messages.stream() for token-by-token streaming responses.
  • Vision: Pass images (base64 or URL) for Claude to analyze alongside text.
  • Tool use: Define and call functions; Claude decides when and how to use them.
  • System prompts: Set behavior, persona, and constraints via system parameter.
  • Async support: AsyncAnthropic client for async/await usage in FastAPI or asyncio.
  • Batches API: Submit large batches for 50% cost reduction with async processing.
  • Message counting: Count tokens before sending to manage context windows.

Technical notes

  • Install: pip install anthropic
  • License: MIT (open source)
  • GitHub: github.com/anthropics/anthropic-sdk-python
  • Models: claude-fable-5-2, claude-opus-5-5, claude-sonnet-5-5, claude-haiku-5-5
  • Context: 1M tokens on current models
  • Pricing: Sonnet $3/$15 per M tokens; Haiku $0.25/$1.25; Opus $15/$75
  • Python: 3.7+

Usage example

import anthropic

client = anthropic.Anthropic()

message = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Explain quantum entanglement simply."}]
)
print(message.content[0].text)

Ideal for

  • Python developers building applications that use Claude for reasoning, coding, writing, analysis, or agent tasks.
  • Teams comparing Claude with GPT who want to test the official API with minimal setup.
  • Applications requiring large context windows (legal docs, long codebases, lengthy conversations).

Not ideal for

  • JavaScript/TypeScript applications — use @anthropic-ai/sdk npm package instead.
  • Multi-provider applications — use Vercel AI SDK, LangChain, or Portkey for provider-agnostic access.
  • Teams who need Claude in a managed workflow (Workbench, Claude.ai) rather than API access.

See also

  • OpenAI Python SDK — the equivalent SDK for OpenAI's models; similar interface.
  • Vercel AI SDK — TypeScript multi-provider SDK for web applications.
  • LangChain — Orchestration framework that wraps the Anthropic SDK with chains and agent abstractions.

Sources

FAQ

What is the Anthropic Python SDK?

The Anthropic Python SDK (`pip install anthropic`) is the official Python client for Claude. Use `client.messages.create()` to call Claude Fable 5.2, Opus 5.5, Sonnet 5.5 and Haiku 5.5.

Is the Anthropic SDK free?

The SDK is free and open source (MIT). You pay for API usage per token: from $0.10 per million input tokens on Claude Haiku 5.5 to $8 on Claude Fable 5.2.

How do I use tool use (function calling) with the Anthropic SDK?

Define tools as JSON schemas with `name`, `description`, and `input_schema`. Pass them to `client.messages.create(tools=[...])`. When Claude decides to use a tool, it returns a `tool_use` block with the function name and arguments. You execute the function and return the result in a `tool_result` content block. Claude then continues the conversation with the tool result. Similar to OpenAI's function calling pattern.

Does the Anthropic SDK support vision?

Yes. Pass images as base64-encoded content blocks or URLs in the `content` array. All current Claude models accept image input.

Alternatives

Integrations

None listed.

Built on

None listed.

Good for these tasks

Listed 2026-02-28 · updated 2026-11-12