anthropic-sdk-python  by anthropics

Python SDK for Anthropic's REST API

created 2 years ago
2,151 stars

Top 21.4% on sourcepulse

GitHubView on GitHub
Project Summary

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

  • Install via pip: pip install anthropic
  • Requires Python 3.8+
  • API key can be set via the ANTHROPIC_API_KEY environment variable or passed directly.
  • Documentation: docs.anthropic.com

Highlighted Details

  • Supports both synchronous and asynchronous API interactions.
  • Provides utilities for streaming responses, token counting, and message batching.
  • Includes optional extras for AWS Bedrock (anthropic[bedrock]) and Google Vertex AI (anthropic[vertex]) integration.
  • Offers robust error handling with specific exceptions for connection issues, rate limits, and status errors.
  • Features automatic retries for transient errors and configurable timeouts.

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.

Health Check
Last commit

22 hours ago

Responsiveness

1 day

Pull Requests (30d)
15
Issues (30d)
13
Star History
276 stars in the last 90 days

Explore Similar Projects

Starred by Jeff Hammerbacher Jeff Hammerbacher(Cofounder of Cloudera) and Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems).

bytewax by bytewax

0.3%
2k
Python framework for stateful stream processing
created 3 years ago
updated 4 months ago
Starred by Patrick von Platen Patrick von Platen(Core Contributor to Hugging Face Transformers and Diffusers) and Jeff Hammerbacher Jeff Hammerbacher(Cofounder of Cloudera).

client-python by mistralai

0.3%
628
Python SDK for Mistral AI platform
created 1 year ago
updated 1 week ago
Feedback? Help us improve.