Skip to main content

Claude SDK for Python

PyPI version

The Claude SDK for Python provides access to the Claude API from Python applications.

Documentation

Tool helpers (@beta_tool, the tool runner and ToolError) are documented in tools.md. The browser and computer toolset classes have their own guides, browser-toolset.md and computer-toolset.md.

Full documentation is available at platform.claude.com/docs/en/api/sdks/python.

Installation

pip install anthropic

Upgrading from a 0.x release? See the v1 migration guide.

Getting started

import os
from anthropic import Anthropic

client = Anthropic(
    api_key=os.environ.get("ANTHROPIC_API_KEY"),  # This is the default and can be omitted
)

message = client.messages.create(
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": "Hello, Claude",
        }
    ],

    model="claude-opus-5-5",
)

print(message.content)

OpenTelemetry

The SDK reports each API call as an OpenTelemetry span when your application has registered a tracer provider. It depends on opentelemetry-api, a required dependency, and never on an OpenTelemetry SDK.

# a provider other than the registered one
client = Anthropic(open_telemetry={"tracer_provider": tracer_provider})
# no spans
quiet = Anthropic(open_telemetry=False)
# adds prompts and completions
verbose = Anthropic(open_telemetry={"traces": {"content_mode": "content"}})
# keeps the content of one span within this size
bounded = Anthropic(
    open_telemetry={"traces": {"content_mode": "content", "max_content_bytes": 65_536}}
)
# sends no trace context headers, for an application whose HTTP client instrumentation already sends them, so that
# a request does not carry them twice
unpropagated = Anthropic(open_telemetry={"propagation": False})

# sets gen_ai.conversation.id on the spans of one conversation's requests. with_options replaces the whole option,
# so start from client.open_telemetry, which has the client's
conversation = client.with_options(
    open_telemetry={**client.open_telemetry, "conversation_id": conversation_id}
)
conversation.messages.create(...)

A client that is given no open_telemetry option reads these environment variables when it is constructed: ANTHROPIC_OPEN_TELEMETRY=false turns its spans off, ANTHROPIC_OPEN_TELEMETRY_TRACES_CONTENT_MODE=content adds prompts and completions, ANTHROPIC_OPEN_TELEMETRY_TRACES_MAX_CONTENT_BYTES sets max_content_bytes, and ANTHROPIC_OPEN_TELEMETRY_PROPAGATION=false sends no trace context headers. A client that is given the option, even {} or a tracer_provider alone, reads none of them: what the option leaves out has its default (spans on, trace context headers sent, no prompts or completions, 750,000 bytes). A copy made with with_options or copy keeps its client's option unless it is given its own.

Requirements

Python 3.10+

Contributing

See CONTRIBUTING.md.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Metadata

Release files for anthropic 1.17.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anthropic 1.17.0
File Size Uploaded Provenance
anthropic-1.17.0.tar.gz 1.8 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for anthropic 1.17.0
File Interpreter ABI Platform
anthropic-1.17.0-py3-none-any.whl Python 3 none any Details

Total release size: 3.9 MB

Release files / anthropic-1.17.0.tar.gz

Download URL anthropic-1.17.0.tar.gz
Size 1.8 MB
Tags Source
SHA-256 checksum
How to use checksums
dcf77a74dde89a9fd12405fca798b012725a107f7c9488454234a74e275c2163
BLAKE2b-256 checksum
How to use checksums
4e664ec271f7607460005276bb09b0d1c749a9ed0cead35a488a8676f15ed6d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / anthropic-1.17.0-py3-none-any.whl

Download URL anthropic-1.17.0-py3-none-any.whl
Size 2.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
ccb98b85e1a14f81cf1e2ba348393f341f342bad9e07e014f96c9b69f853aaa7
BLAKE2b-256 checksum
How to use checksums
989db4d4e46ec05bf19bcfd46c1417337e7cf42b9ecb95c3c63f295e2e9fee4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for anthropic 1.17.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.17.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page