anthropic-sdk-python  by anthropics

Python SDK for Anthropic's REST API

Created 2 years ago
2,249 stars

Top 20.2% 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

1 day ago

Responsiveness

1 day

Pull Requests (30d)
7
Issues (30d)
9
Star History
63 stars in the last 30 days

Explore Similar Projects

Starred by Patrick von Platen Patrick von Platen(Author of Hugging Face Diffusers; Research Engineer at Mistral) and Jeff Hammerbacher Jeff Hammerbacher(Cofounder of Cloudera).

client-python by mistralai

0.6%
648
Python SDK for Mistral AI platform
Created 1 year ago
Updated 2 weeks ago
Feedback? Help us improve.