Anthropic Python SDK

The official Python SDK for the Anthropic Claude API, with typed clients, streaming, and tool use.

SDK
PyPI
v2.3.0
4,002 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
96 /100 Excellent
Development Activity 100
Maintenance 100
Community 92
Maturity 52
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
91 /100 Excellent
Architecture 92
Code Quality 95
Innovation 90
Learning Curve 85

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

Python
84%
MIT

LiteLLM

AI Development · Developer Tools

61,933

Open source AI gateway and Python SDK that gives you one OpenAI-compatible interface to call 100+ LLM providers, with built-in routing, cost tracking, guardrails, and virtual keys.

View details
93
Repo Health
81
Technical
69
Dependency
Built with
Python 84%
TypeScript 11%
Updated 5 days ago
Rust
84%
Apache 2.0

liteparse

Developer Tools

12,906

A fast, lightweight, open-source document parser that extracts spatial text, bounding boxes, and Markdown from PDFs and Office files — entirely on your machine.

View details
83
Repo Health
80
Technical
71
Dependency
Built with
Rust 84%
Updated 1 weeks ago
Python
45%
GPL 3.0

MaxKB

AI Development · Knowledge Management

23,022

Build enterprise-grade AI agents with RAG, workflows & multi-modal support

View details
92
Repo Health
68
Technical
66
Dependency
Built with
Python 45%
Vue 37%
TypeScript 17%
Updated 6 days ago
Python
66%
Other

Morphik

AI Development · Databases · Search

3,717

Morphik is an AI-native ingestion and retrieval engine that lets developers store, search, and reason over visually rich documents — scanned PDFs, manuals, slides, and video — without duct-taping together OCR, an embedding model, and a vector database.

View details
64
Repo Health
71
Technical
67
Dependency
Built with
Python 66%
TypeScript 23%
Updated 1 weeks ago
TypeScript
84%
Apache 2.0

nao

AI Development · Analytics

1,949

Build and deploy an open-source analytics agent that understands your data warehouse and answers business questions in plain English.

View details
85
Repo Health
76
Technical
67
Dependency
Built with
TypeScript 84%
Python 15%
Updated 5 days ago
TypeScript
60%
MIT

oh-my-claudecode

AI Agents

40,215

Multi-agent orchestration for Claude Code with zero learning curve — install as a plugin or npm CLI and coordinate parallel Claude Code agents through pre-built workflows instead of managing them by hand.

View details
85
Repo Health
70
Technical
73
Dependency
Built with
TypeScript 60%
JavaScript 39%
Updated 5 days ago
Python
38%
Other

Open WebUI

AI Agents · AI Assistants

156,607

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
92
Repo Health
75
Technical
66
Dependency
Built with
Python 38%
Svelte 35%
JavaScript 19%
Updated 5 days ago
TypeScript
92%
Other

OpenHands

AI Code Assistants · AI Development

91,695

The self-hosted developer control center for running AI coding agents — locally, in Docker, on VMs, or across cloud backends — with automation workflows for GitHub, Slack, and more.

View details
91
Repo Health
82
Technical
67
Dependency
Built with
TypeScript 92%
Updated 6 days ago
Python
49%
Other

Arize Phoenix

Analytics · Devops · Monitoring

11,976

Open-source AI observability platform for tracing, evaluating, and debugging LLM applications with built-in intelligence and MCP support.

View details
92
Repo Health
88
Technical
67
Dependency
Built with
Python 49%
TypeScript 43%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers