Python SDK for Anthropic's REST API
Top 21.4% on sourcepulse
This Python SDK provides a convenient interface for interacting with the Anthropic API, targeting developers building applications with Anthropic's Claude models. It offers both synchronous and asynchronous clients, simplifying API calls, handling streaming responses, and managing complex features like tool use and message batches.
How It Works
The library leverages httpx
for both synchronous and asynchronous HTTP requests, ensuring efficient and modern network communication. It provides type-hinted request parameters and Pydantic models for responses, enhancing developer experience through autocompletion and early error detection. Key features include built-in support for streaming responses via Server-Sent Events (SSE) and a client.messages.stream
context manager for simplified stream processing.
Quick Start & Requirements
pip install anthropic
ANTHROPIC_API_KEY
environment variable or passed directly.Highlighted Details
anthropic[bedrock]
) and Google Vertex AI (anthropic[vertex]
) integration.Maintenance & Community
The library is maintained by Anthropic. Feedback and contributions are encouraged via GitHub issues.
Licensing & Compatibility
The library is released under a permissive license, allowing for commercial use and integration with closed-source applications.
Limitations & Caveats
Non-streaming requests with very large max_tokens
values are discouraged and may result in a ValueError
due to potential network timeouts; streaming is recommended for long-running requests. The library uses _
prefixed attributes for internal use, with _request_id
being a public exception.
22 hours ago
1 day