Anthropic Python SDK
The official Python SDK for the Anthropic Claude API, with typed clients, streaming, and tool use.
Repository Health
Technical Analysis
The Anthropic Python SDK is the official client library for calling the Claude API from Python applications. It exposes a fully typed, ergonomic interface over the Messages API, streaming, tool use, batch processing, and model management, so you can integrate Claude without hand-writing HTTP requests or response parsing.
Generated from Anthropic’s OpenAPI specification and hand-augmented with helpers, it ships synchronous and asynchronous clients, automatic retries with backoff, rich error types, and first-class support for running on Amazon Bedrock and Google Vertex AI. Pydantic-backed models give editor autocompletion and static type checking across every request and response.
What You Get
- Synchronous (
Anthropic) and asynchronous (AsyncAnthropic) clients over the full Claude API surface - First-class streaming helpers with typed events for incremental message output
- Built-in tool use, a tool runner, and MCP integration for agentic workflows
- Automatic retries with exponential backoff, configurable timeouts, and typed error hierarchy
- Cloud-provider clients for Amazon Bedrock and Google Vertex AI alongside the direct API
Common Use Cases
- Building chat and assistant experiences powered by Claude models
- Streaming long-form generations token-by-token to a UI or terminal
- Orchestrating tool-calling and agent loops with function definitions and MCP servers
- Running large offline jobs through the Message Batches API
- Deploying Claude on enterprise infrastructure via Bedrock or Vertex AI
Under The Hood
Architecture
The public entry points Anthropic and AsyncAnthropic in src/anthropic/_client.py (~1,100 lines) subclass SyncAPIClient/AsyncAPIClient in src/anthropic/_base_client.py (~2,650 lines), which centralizes the httpx transport, request building, retry-with-backoff logic, pagination, and streaming decode. API surface is organized into resource namespaces under src/anthropic/resources/ (messages, models, completions, and a beta tree), each mapping to typed request/response models in types/. Streaming lives in _streaming.py, while agentic features (tool runner, MCP integration, session runners) sit in lib/tools/, and hand-written auth plus cloud variants live in lib/credentials, lib/bedrock, and lib/vertex.
Tech Stack
Targets Python 3.9+ and is built on httpx for HTTP, Pydantic (v1.9-v3) for validated models, anyio for async, and jiter for fast JSON decoding, with distro and sniffio as runtime helpers. Optional extras pull in aiohttp, boto3/botocore (Bedrock/AWS), google-auth (Vertex), and the mcp package. The core is generated from Anthropic’s OpenAPI spec by Stainless and hand-augmented; the dev toolchain uses uv for locking plus ruff, pyright, mypy, and pytest.
Code Quality
The library is fully typed and ships py.typed, with strict type checking enforced via pyright and mypy in CI. Testing is substantial — roughly 103 test files under tests/ using pytest, pytest-asyncio, respx for HTTP mocking, and inline-snapshot. Error handling is well-structured: _exceptions.py defines a granular hierarchy keyed to HTTP status codes, and retry/timeout behavior is configurable and consistent across sync and async paths.
API Design
The developer experience is a strong point: a client is instantiated with an API key (auto-read from ANTHROPIC_API_KEY) and used through resource-oriented calls like client.messages.create(...), with sync and async interfaces kept symmetric. Getting started requires almost no boilerplate, and the repo backs the API with 30-plus runnable scripts in examples/ plus dedicated api.md, helpers.md, and tools.md references, making the naming and usage patterns easy to discover.
Used by 34 apps in this directory
PostHog
Ab Testing Experimentation · Analytics · Developer Tools
The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.
PrivateGPT
AI Development
The open-source API layer that turns local LLMs into production private AI applications with full Claude API compatibility
Promptfoo
AI Development
An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.
Skyvern
AI Agents · Automation
Skyvern (YC S2023) automates browser-based workflows by pairing LLMs with computer vision, letting agents click, fill, and extract data on sites they've never seen, without brittle XPath selectors that break on every layout change.
supermemory
AI Development · AI Memory · Note Taking
The state-of-the-art memory and context engine for AI agents — ranked #1 on all three major AI memory benchmarks.
Temps
Analytics · Devops · Monitoring
A self-hosted Rust PaaS that replaces Vercel, Sentry, PostHog, Pingdom, Resend, and E2B with one binary — plus 440+ CLI operations agents like Claude Code can drive directly.
Trieve
AI Development · Developer Tools · Search
All-in-one self-hostable platform for hybrid search, RAG, recommendations, and analytics built on Rust and Qdrant.