Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 0.22.0 #416

Merged
merged 12 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.21.3"
".": "0.22.0"
}
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# Changelog

## 0.22.0 (2024-04-04)

Full Changelog: [v0.21.3...v0.22.0](https://github.com/anthropics/anthropic-sdk-python/compare/v0.21.3...v0.22.0)

### Features

* **client:** increase default HTTP max_connections to 1000 and max_keepalive_connections to 100 ([#428](https://github.com/anthropics/anthropic-sdk-python/issues/428)) ([9a43940](https://github.com/anthropics/anthropic-sdk-python/commit/9a4394008db937a9ad851589b9adfbd9e15333ef))
* **package:** export default constants ([#423](https://github.com/anthropics/anthropic-sdk-python/issues/423)) ([0d694e1](https://github.com/anthropics/anthropic-sdk-python/commit/0d694e157b040993d937f136c5072c98b87434ff))


### Bug Fixes

* **client:** correct logic for line decoding in streaming ([#433](https://github.com/anthropics/anthropic-sdk-python/issues/433)) ([6bf9379](https://github.com/anthropics/anthropic-sdk-python/commit/6bf93794127a62a077f2e50a2acfe01464742319))
* **project:** use absolute github links on PyPi ([#427](https://github.com/anthropics/anthropic-sdk-python/issues/427)) ([cbd8b1c](https://github.com/anthropics/anthropic-sdk-python/commit/cbd8b1c789e83d2c84ba10165778e4ad2af1ac20))
* revert regression with 3.7 support ([#419](https://github.com/anthropics/anthropic-sdk-python/issues/419)) ([fa21f36](https://github.com/anthropics/anthropic-sdk-python/commit/fa21f3643714d985b10b45dc8bfc3887ed20eba7))
* **streaming:** correct accumulation of output tokens ([#426](https://github.com/anthropics/anthropic-sdk-python/issues/426)) ([b50ed05](https://github.com/anthropics/anthropic-sdk-python/commit/b50ed05a991f02bccfd9f65a1c59e56540adba08))


### Chores

* **client:** validate that max_retries is not None ([#430](https://github.com/anthropics/anthropic-sdk-python/issues/430)) ([31b2a2f](https://github.com/anthropics/anthropic-sdk-python/commit/31b2a2fd4069a670c795eeaf51b641fbf2097af1))
* **internal:** bump dependencies ([#421](https://github.com/anthropics/anthropic-sdk-python/issues/421)) ([30e8031](https://github.com/anthropics/anthropic-sdk-python/commit/30e8031469a4c4beb0bb906920f53d5d4da2e2c3))
* **internal:** defer model build for import latency ([#431](https://github.com/anthropics/anthropic-sdk-python/issues/431)) ([51d4783](https://github.com/anthropics/anthropic-sdk-python/commit/51d47832ae44415604725bb763cf567fb9dc1b34))
* **internal:** formatting change ([#415](https://github.com/anthropics/anthropic-sdk-python/issues/415)) ([1474f44](https://github.com/anthropics/anthropic-sdk-python/commit/1474f443201949c9b8a7d0a8562968d57d421fb5))


### Documentation

* **contributing:** fix typo ([#414](https://github.com/anthropics/anthropic-sdk-python/issues/414)) ([aeaf995](https://github.com/anthropics/anthropic-sdk-python/commit/aeaf99573a9140b6bb5c0af4cefddbd6f469a6a5))
* **readme:** change undocumented params wording ([#429](https://github.com/anthropics/anthropic-sdk-python/issues/429)) ([1336958](https://github.com/anthropics/anthropic-sdk-python/commit/13369583fc74101e002427079c9871e05e5536e8))

## 0.21.3 (2024-03-21)

Full Changelog: [v0.21.2...v0.21.3](https://github.com/anthropics/anthropic-sdk-python/compare/v0.21.2...v0.21.3)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,12 @@ response = client.post(
print(response.headers.get("x-foo"))
```

#### Undocumented params
#### Undocumented request params

If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request
options.

#### Undocumented properties
#### Undocumented response properties

To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You
can also get all the extra fields on the Pydantic model as a dict with
Expand Down
18 changes: 15 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[project]
name = "anthropic"
version = "0.21.3"
version = "0.22.0"
description = "The official Python library for the anthropic API"
readme = "README.md"
dynamic = ["readme"]
license = "MIT"
authors = [
{ name = "Anthropic", email = "[email protected]" },
Expand Down Expand Up @@ -90,7 +90,7 @@ typecheck = { chain = [
"typecheck:mypy" = "mypy ."

[build-system]
requires = ["hatchling"]
requires = ["hatchling", "hatch-fancy-pypi-readme"]
build-backend = "hatchling.build"

[tool.hatch.build]
Expand All @@ -101,6 +101,17 @@ include = [
[tool.hatch.build.targets.wheel]
packages = ["src/anthropic"]

[tool.hatch.metadata.hooks.fancy-pypi-readme]
content-type = "text/markdown"

[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
path = "README.md"

[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
# replace relative links with absolute links
pattern = '\[(.+?)\]\(((?!https?://)\S+?)\)'
replacement = '[\1](https://github.com/anthropics/anthropic-sdk-python/tree/main/\g<2>)'

[tool.black]
line-length = 120
target-version = ["py37"]
Expand Down Expand Up @@ -132,6 +143,7 @@ reportImplicitOverride = true
reportImportCycles = false
reportPrivateUsage = false


[tool.ruff]
line-length = 120
output-format = "grouped"
Expand Down
14 changes: 7 additions & 7 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ botocore==1.31.58
# via anthropic
# via boto3
# via s3transfer
botocore-stubs==1.34.49
botocore-stubs==1.34.69
# via boto3-stubs
cachetools==5.3.2
cachetools==5.3.3
# via google-auth
certifi==2023.7.22
# via httpcore
Expand All @@ -46,7 +46,7 @@ exceptiongroup==1.1.3
filelock==3.12.4
# via huggingface-hub
# via virtualenv
fsspec==2024.2.0
fsspec==2024.3.1
# via huggingface-hub
google-auth==2.26.2
# via anthropic
Expand Down Expand Up @@ -85,16 +85,16 @@ pluggy==1.3.0
# via pytest
py==1.11.0
# via pytest
pyasn1==0.5.1
pyasn1==0.6.0
# via pyasn1-modules
# via rsa
pyasn1-modules==0.3.0
pyasn1-modules==0.4.0
# via google-auth
pydantic==2.4.2
# via anthropic
pydantic-core==2.10.1
# via pydantic
pyright==1.1.351
pyright==1.1.353
pytest==7.1.1
# via pytest-asyncio
pytest-asyncio==0.21.1
Expand Down Expand Up @@ -129,7 +129,7 @@ tomli==2.0.1
# via pytest
tqdm==4.66.2
# via huggingface-hub
types-awscrt==0.20.4
types-awscrt==0.20.5
# via botocore-stubs
types-s3transfer==0.10.0
# via boto3-stubs
Expand Down
22 changes: 11 additions & 11 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ annotated-types==0.6.0
anyio==4.1.0
# via anthropic
# via httpx
boto3==1.34.45
boto3==1.34.72
# via anthropic
botocore==1.34.45
botocore==1.34.72
# via anthropic
# via boto3
# via s3transfer
cachetools==5.3.2
cachetools==5.3.3
# via google-auth
certifi==2023.7.22
# via httpcore
Expand All @@ -31,11 +31,11 @@ distro==1.8.0
# via anthropic
exceptiongroup==1.1.3
# via anyio
filelock==3.13.1
filelock==3.13.3
# via huggingface-hub
fsspec==2024.2.0
fsspec==2024.3.1
# via huggingface-hub
google-auth==2.28.0
google-auth==2.29.0
# via anthropic
h11==0.14.0
# via httpcore
Expand All @@ -52,26 +52,26 @@ idna==3.4
jmespath==1.0.1
# via boto3
# via botocore
packaging==23.2
packaging==24.0
# via huggingface-hub
pyasn1==0.5.1
pyasn1==0.6.0
# via pyasn1-modules
# via rsa
pyasn1-modules==0.3.0
pyasn1-modules==0.4.0
# via google-auth
pydantic==2.4.2
# via anthropic
pydantic-core==2.10.1
# via pydantic
python-dateutil==2.8.2
python-dateutil==2.9.0.post0
# via botocore
pyyaml==6.0.1
# via huggingface-hub
requests==2.31.0
# via huggingface-hub
rsa==4.9
# via google-auth
s3transfer==0.10.0
s3transfer==0.10.1
# via boto3
six==1.16.0
# via python-dateutil
Expand Down
11 changes: 10 additions & 1 deletion src/anthropic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
from ._models import BaseModel
from ._version import __title__, __version__
from ._response import APIResponse as APIResponse, AsyncAPIResponse as AsyncAPIResponse
from ._constants import AI_PROMPT as AI_PROMPT, HUMAN_PROMPT as HUMAN_PROMPT
from ._constants import (
AI_PROMPT as AI_PROMPT,
HUMAN_PROMPT as HUMAN_PROMPT,
DEFAULT_TIMEOUT,
DEFAULT_MAX_RETRIES,
DEFAULT_CONNECTION_LIMITS,
)
from ._exceptions import (
APIError,
ConflictError,
Expand Down Expand Up @@ -69,6 +75,9 @@
"AsyncAnthropic",
"file_from_path",
"BaseModel",
"DEFAULT_TIMEOUT",
"DEFAULT_MAX_RETRIES",
"DEFAULT_CONNECTION_LIMITS",
"HUMAN_PROMPT",
"AI_PROMPT",
]
Expand Down
11 changes: 8 additions & 3 deletions src/anthropic/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@
extract_response_type,
)
from ._constants import (
DEFAULT_LIMITS,
DEFAULT_TIMEOUT,
MAX_RETRY_DELAY,
DEFAULT_MAX_RETRIES,
INITIAL_RETRY_DELAY,
RAW_RESPONSE_HEADER,
OVERRIDE_CAST_TO_HEADER,
DEFAULT_CONNECTION_LIMITS,
)
from ._streaming import Stream, SSEDecoder, AsyncStream, SSEBytesDecoder
from ._exceptions import (
Expand Down Expand Up @@ -361,6 +361,11 @@ def __init__(
self._strict_response_validation = _strict_response_validation
self._idempotency_header = None

if max_retries is None: # pyright: ignore[reportUnnecessaryComparison]
raise TypeError(
"max_retries cannot be None. If you want to disable retries, pass `0`; if you want unlimited retries, pass `math.inf` or a very high number; if you want the default behavior, pass `anthropic.DEFAULT_MAX_RETRIES`"
)

def _enforce_trailing_slash(self, url: URL) -> URL:
if url.raw_path.endswith(b"/"):
return url
Expand Down Expand Up @@ -747,7 +752,7 @@ def __init__(
if http_client is not None:
raise ValueError("The `http_client` argument is mutually exclusive with `connection_pool_limits`")
else:
limits = DEFAULT_LIMITS
limits = DEFAULT_CONNECTION_LIMITS

if transport is not None:
warnings.warn(
Expand Down Expand Up @@ -1294,7 +1299,7 @@ def __init__(
if http_client is not None:
raise ValueError("The `http_client` argument is mutually exclusive with `connection_pool_limits`")
else:
limits = DEFAULT_LIMITS
limits = DEFAULT_CONNECTION_LIMITS

if transport is not None:
warnings.warn(
Expand Down
6 changes: 3 additions & 3 deletions src/anthropic/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
async_get_tokenizer,
)
from ._base_client import (
DEFAULT_LIMITS,
DEFAULT_MAX_RETRIES,
DEFAULT_CONNECTION_LIMITS,
SyncAPIClient,
AsyncAPIClient,
SyncHttpxClientWrapper,
Expand Down Expand Up @@ -239,7 +239,7 @@ def copy(

http_client = None
else:
if self._limits is not DEFAULT_LIMITS:
if self._limits is not DEFAULT_CONNECTION_LIMITS:
connection_pool_limits = self._limits
else:
connection_pool_limits = None
Expand Down Expand Up @@ -499,7 +499,7 @@ def copy(

http_client = None
else:
if self._limits is not DEFAULT_LIMITS:
if self._limits is not DEFAULT_CONNECTION_LIMITS:
connection_pool_limits = self._limits
else:
connection_pool_limits = None
Expand Down
2 changes: 1 addition & 1 deletion src/anthropic/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# default timeout is 10 minutes
DEFAULT_TIMEOUT = httpx.Timeout(timeout=600.0, connect=5.0)
DEFAULT_MAX_RETRIES = 2
DEFAULT_LIMITS = httpx.Limits(max_connections=100, max_keepalive_connections=20)
DEFAULT_CONNECTION_LIMITS = httpx.Limits(max_connections=1000, max_keepalive_connections=100)

INITIAL_RETRY_DELAY = 0.5
MAX_RETRY_DELAY = 8.0
Expand Down
14 changes: 10 additions & 4 deletions src/anthropic/_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
import inspect
from typing import TYPE_CHECKING, Any, Type, Union, Generic, TypeVar, Callable, cast
from datetime import date, datetime
Expand Down Expand Up @@ -38,6 +39,7 @@
is_given,
is_mapping,
parse_date,
coerce_boolean,
parse_datetime,
strip_not_given,
extract_type_arg,
Expand Down Expand Up @@ -74,7 +76,9 @@ class _ConfigProtocol(Protocol):

class BaseModel(pydantic.BaseModel):
if PYDANTIC_V2:
model_config: ClassVar[ConfigDict] = ConfigDict(extra="allow")
model_config: ClassVar[ConfigDict] = ConfigDict(
extra="allow", defer_build=coerce_boolean(os.environ.get("DEFER_PYDANTIC_BUILD", "true"))
)
else:

@property
Expand Down Expand Up @@ -538,12 +542,14 @@ class GenericModel(BaseGenericModel, BaseModel):


if PYDANTIC_V2:
from pydantic import TypeAdapter as _TypeAdapter

_CachedTypeAdapter = cast("TypeAdapter[object]", lru_cache(maxsize=None)(_TypeAdapter))

if TYPE_CHECKING:
from pydantic import TypeAdapter
else:
from pydantic import TypeAdapter as _TypeAdapter

TypeAdapter = lru_cache(_TypeAdapter)
TypeAdapter = _CachedTypeAdapter

def _validate_non_model_type(*, type_: type[_T], value: object) -> _T:
return TypeAdapter(type_).validate_python(value)
Expand Down
Loading