anthropic 0.72.0__py3-none-any.whl → 0.72.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- anthropic/_models.py +37 -15
- anthropic/_streaming.py +4 -6
- anthropic/_utils/_sync.py +3 -31
- anthropic/_utils/_utils.py +1 -1
- anthropic/_version.py +1 -1
- {anthropic-0.72.0.dist-info → anthropic-0.72.1.dist-info}/METADATA +4 -5
- {anthropic-0.72.0.dist-info → anthropic-0.72.1.dist-info}/RECORD +9 -9
- {anthropic-0.72.0.dist-info → anthropic-0.72.1.dist-info}/WHEEL +0 -0
- {anthropic-0.72.0.dist-info → anthropic-0.72.1.dist-info}/licenses/LICENSE +0 -0
anthropic/_models.py
CHANGED
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
4
|
import inspect
|
|
5
|
+
import weakref
|
|
5
6
|
from typing import TYPE_CHECKING, Any, Type, Union, Generic, TypeVar, Callable, Optional, cast
|
|
6
7
|
from datetime import date, datetime
|
|
7
8
|
from typing_extensions import (
|
|
@@ -272,15 +273,16 @@ class BaseModel(pydantic.BaseModel):
|
|
|
272
273
|
mode: Literal["json", "python"] | str = "python",
|
|
273
274
|
include: IncEx | None = None,
|
|
274
275
|
exclude: IncEx | None = None,
|
|
276
|
+
context: Any | None = None,
|
|
275
277
|
by_alias: bool | None = None,
|
|
276
278
|
exclude_unset: bool = False,
|
|
277
279
|
exclude_defaults: bool = False,
|
|
278
280
|
exclude_none: bool = False,
|
|
281
|
+
exclude_computed_fields: bool = False,
|
|
279
282
|
round_trip: bool = False,
|
|
280
283
|
warnings: bool | Literal["none", "warn", "error"] = True,
|
|
281
|
-
context: dict[str, Any] | None = None,
|
|
282
|
-
serialize_as_any: bool = False,
|
|
283
284
|
fallback: Callable[[Any], Any] | None = None,
|
|
285
|
+
serialize_as_any: bool = False,
|
|
284
286
|
) -> dict[str, Any]:
|
|
285
287
|
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
|
|
286
288
|
|
|
@@ -288,16 +290,24 @@ class BaseModel(pydantic.BaseModel):
|
|
|
288
290
|
|
|
289
291
|
Args:
|
|
290
292
|
mode: The mode in which `to_python` should run.
|
|
291
|
-
If mode is 'json', the
|
|
292
|
-
If mode is 'python', the
|
|
293
|
-
include: A
|
|
294
|
-
exclude: A
|
|
293
|
+
If mode is 'json', the output will only contain JSON serializable types.
|
|
294
|
+
If mode is 'python', the output may contain non-JSON-serializable Python objects.
|
|
295
|
+
include: A set of fields to include in the output.
|
|
296
|
+
exclude: A set of fields to exclude from the output.
|
|
297
|
+
context: Additional context to pass to the serializer.
|
|
295
298
|
by_alias: Whether to use the field's alias in the dictionary key if defined.
|
|
296
|
-
exclude_unset: Whether to exclude fields that
|
|
297
|
-
exclude_defaults: Whether to exclude fields that are set to their default value
|
|
298
|
-
exclude_none: Whether to exclude fields that have a value of `None
|
|
299
|
-
|
|
300
|
-
|
|
299
|
+
exclude_unset: Whether to exclude fields that have not been explicitly set.
|
|
300
|
+
exclude_defaults: Whether to exclude fields that are set to their default value.
|
|
301
|
+
exclude_none: Whether to exclude fields that have a value of `None`.
|
|
302
|
+
exclude_computed_fields: Whether to exclude computed fields.
|
|
303
|
+
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
|
304
|
+
`round_trip` parameter instead.
|
|
305
|
+
round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T].
|
|
306
|
+
warnings: How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
|
|
307
|
+
"error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
|
|
308
|
+
fallback: A function to call when an unknown value is encountered. If not provided,
|
|
309
|
+
a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError] error is raised.
|
|
310
|
+
serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.
|
|
301
311
|
|
|
302
312
|
Returns:
|
|
303
313
|
A dictionary representation of the model.
|
|
@@ -314,6 +324,8 @@ class BaseModel(pydantic.BaseModel):
|
|
|
314
324
|
raise ValueError("serialize_as_any is only supported in Pydantic v2")
|
|
315
325
|
if fallback is not None:
|
|
316
326
|
raise ValueError("fallback is only supported in Pydantic v2")
|
|
327
|
+
if exclude_computed_fields != False:
|
|
328
|
+
raise ValueError("exclude_computed_fields is only supported in Pydantic v2")
|
|
317
329
|
dumped = super().dict( # pyright: ignore[reportDeprecated]
|
|
318
330
|
include=include,
|
|
319
331
|
exclude=exclude,
|
|
@@ -330,15 +342,17 @@ class BaseModel(pydantic.BaseModel):
|
|
|
330
342
|
self,
|
|
331
343
|
*,
|
|
332
344
|
indent: int | None = None,
|
|
345
|
+
ensure_ascii: bool = False,
|
|
333
346
|
include: IncEx | None = None,
|
|
334
347
|
exclude: IncEx | None = None,
|
|
348
|
+
context: Any | None = None,
|
|
335
349
|
by_alias: bool | None = None,
|
|
336
350
|
exclude_unset: bool = False,
|
|
337
351
|
exclude_defaults: bool = False,
|
|
338
352
|
exclude_none: bool = False,
|
|
353
|
+
exclude_computed_fields: bool = False,
|
|
339
354
|
round_trip: bool = False,
|
|
340
355
|
warnings: bool | Literal["none", "warn", "error"] = True,
|
|
341
|
-
context: dict[str, Any] | None = None,
|
|
342
356
|
fallback: Callable[[Any], Any] | None = None,
|
|
343
357
|
serialize_as_any: bool = False,
|
|
344
358
|
) -> str:
|
|
@@ -370,6 +384,10 @@ class BaseModel(pydantic.BaseModel):
|
|
|
370
384
|
raise ValueError("serialize_as_any is only supported in Pydantic v2")
|
|
371
385
|
if fallback is not None:
|
|
372
386
|
raise ValueError("fallback is only supported in Pydantic v2")
|
|
387
|
+
if ensure_ascii != False:
|
|
388
|
+
raise ValueError("ensure_ascii is only supported in Pydantic v2")
|
|
389
|
+
if exclude_computed_fields != False:
|
|
390
|
+
raise ValueError("exclude_computed_fields is only supported in Pydantic v2")
|
|
373
391
|
return super().json( # type: ignore[reportDeprecated]
|
|
374
392
|
indent=indent,
|
|
375
393
|
include=include,
|
|
@@ -589,6 +607,9 @@ class CachedDiscriminatorType(Protocol):
|
|
|
589
607
|
__discriminator__: DiscriminatorDetails
|
|
590
608
|
|
|
591
609
|
|
|
610
|
+
DISCRIMINATOR_CACHE: weakref.WeakKeyDictionary[type, DiscriminatorDetails] = weakref.WeakKeyDictionary()
|
|
611
|
+
|
|
612
|
+
|
|
592
613
|
class DiscriminatorDetails:
|
|
593
614
|
field_name: str
|
|
594
615
|
"""The name of the discriminator field in the variant class, e.g.
|
|
@@ -631,8 +652,9 @@ class DiscriminatorDetails:
|
|
|
631
652
|
|
|
632
653
|
|
|
633
654
|
def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any, ...]) -> DiscriminatorDetails | None:
|
|
634
|
-
|
|
635
|
-
|
|
655
|
+
cached = DISCRIMINATOR_CACHE.get(union)
|
|
656
|
+
if cached is not None:
|
|
657
|
+
return cached
|
|
636
658
|
|
|
637
659
|
discriminator_field_name: str | None = None
|
|
638
660
|
|
|
@@ -685,7 +707,7 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any,
|
|
|
685
707
|
discriminator_field=discriminator_field_name,
|
|
686
708
|
discriminator_alias=discriminator_alias,
|
|
687
709
|
)
|
|
688
|
-
|
|
710
|
+
DISCRIMINATOR_CACHE.setdefault(union, details)
|
|
689
711
|
return details
|
|
690
712
|
|
|
691
713
|
|
anthropic/_streaming.py
CHANGED
|
@@ -113,9 +113,8 @@ class Stream(Generic[_T], metaclass=_SyncStreamMeta):
|
|
|
113
113
|
response=self.response,
|
|
114
114
|
)
|
|
115
115
|
|
|
116
|
-
#
|
|
117
|
-
|
|
118
|
-
...
|
|
116
|
+
# As we might not fully consume the response stream, we need to close it explicitly
|
|
117
|
+
response.close()
|
|
119
118
|
|
|
120
119
|
def __enter__(self) -> Self:
|
|
121
120
|
return self
|
|
@@ -231,9 +230,8 @@ class AsyncStream(Generic[_T], metaclass=_AsyncStreamMeta):
|
|
|
231
230
|
response=self.response,
|
|
232
231
|
)
|
|
233
232
|
|
|
234
|
-
#
|
|
235
|
-
|
|
236
|
-
...
|
|
233
|
+
# As we might not fully consume the response stream, we need to close it explicitly
|
|
234
|
+
await response.aclose()
|
|
237
235
|
|
|
238
236
|
async def __aenter__(self) -> Self:
|
|
239
237
|
return self
|
anthropic/_utils/_sync.py
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import sys
|
|
4
3
|
import asyncio
|
|
5
4
|
import functools
|
|
6
|
-
import
|
|
7
|
-
from typing import Any, TypeVar, Callable, Awaitable
|
|
5
|
+
from typing import TypeVar, Callable, Awaitable
|
|
8
6
|
from typing_extensions import ParamSpec
|
|
9
7
|
|
|
10
8
|
import anyio
|
|
@@ -15,34 +13,11 @@ T_Retval = TypeVar("T_Retval")
|
|
|
15
13
|
T_ParamSpec = ParamSpec("T_ParamSpec")
|
|
16
14
|
|
|
17
15
|
|
|
18
|
-
if sys.version_info >= (3, 9):
|
|
19
|
-
_asyncio_to_thread = asyncio.to_thread
|
|
20
|
-
else:
|
|
21
|
-
# backport of https://docs.python.org/3/library/asyncio-task.html#asyncio.to_thread
|
|
22
|
-
# for Python 3.8 support
|
|
23
|
-
async def _asyncio_to_thread(
|
|
24
|
-
func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
|
|
25
|
-
) -> Any:
|
|
26
|
-
"""Asynchronously run function *func* in a separate thread.
|
|
27
|
-
|
|
28
|
-
Any *args and **kwargs supplied for this function are directly passed
|
|
29
|
-
to *func*. Also, the current :class:`contextvars.Context` is propagated,
|
|
30
|
-
allowing context variables from the main thread to be accessed in the
|
|
31
|
-
separate thread.
|
|
32
|
-
|
|
33
|
-
Returns a coroutine that can be awaited to get the eventual result of *func*.
|
|
34
|
-
"""
|
|
35
|
-
loop = asyncio.events.get_running_loop()
|
|
36
|
-
ctx = contextvars.copy_context()
|
|
37
|
-
func_call = functools.partial(ctx.run, func, *args, **kwargs)
|
|
38
|
-
return await loop.run_in_executor(None, func_call)
|
|
39
|
-
|
|
40
|
-
|
|
41
16
|
async def to_thread(
|
|
42
17
|
func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
|
|
43
18
|
) -> T_Retval:
|
|
44
19
|
if sniffio.current_async_library() == "asyncio":
|
|
45
|
-
return await
|
|
20
|
+
return await asyncio.to_thread(func, *args, **kwargs)
|
|
46
21
|
|
|
47
22
|
return await anyio.to_thread.run_sync(
|
|
48
23
|
functools.partial(func, *args, **kwargs),
|
|
@@ -53,10 +28,7 @@ async def to_thread(
|
|
|
53
28
|
def asyncify(function: Callable[T_ParamSpec, T_Retval]) -> Callable[T_ParamSpec, Awaitable[T_Retval]]:
|
|
54
29
|
"""
|
|
55
30
|
Take a blocking function and create an async one that receives the same
|
|
56
|
-
positional and keyword arguments.
|
|
57
|
-
asyncio.to_thread to run the function in a separate thread. For python version
|
|
58
|
-
3.8, it uses locally defined copy of the asyncio.to_thread function which was
|
|
59
|
-
introduced in python 3.9.
|
|
31
|
+
positional and keyword arguments.
|
|
60
32
|
|
|
61
33
|
Usage:
|
|
62
34
|
|
anthropic/_utils/_utils.py
CHANGED
|
@@ -133,7 +133,7 @@ def is_given(obj: _T | NotGiven | Omit) -> TypeGuard[_T]:
|
|
|
133
133
|
# Type safe methods for narrowing types with TypeVars.
|
|
134
134
|
# The default narrowing for isinstance(obj, dict) is dict[unknown, unknown],
|
|
135
135
|
# however this cause Pyright to rightfully report errors. As we know we don't
|
|
136
|
-
# care about the contained types we can safely use `object` in
|
|
136
|
+
# care about the contained types we can safely use `object` in its place.
|
|
137
137
|
#
|
|
138
138
|
# There are two separate functions defined, `is_*` and `is_*_t` for different use cases.
|
|
139
139
|
# `is_*` is for when you're dealing with an unknown input
|
anthropic/_version.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: anthropic
|
|
3
|
-
Version: 0.72.
|
|
3
|
+
Version: 0.72.1
|
|
4
4
|
Summary: The official Python library for the anthropic API
|
|
5
5
|
Project-URL: Homepage, https://github.com/anthropics/anthropic-sdk-python
|
|
6
6
|
Project-URL: Repository, https://github.com/anthropics/anthropic-sdk-python
|
|
@@ -13,7 +13,6 @@ Classifier: Operating System :: Microsoft :: Windows
|
|
|
13
13
|
Classifier: Operating System :: OS Independent
|
|
14
14
|
Classifier: Operating System :: POSIX
|
|
15
15
|
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.9
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
@@ -21,7 +20,7 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
21
20
|
Classifier: Programming Language :: Python :: 3.13
|
|
22
21
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
22
|
Classifier: Typing :: Typed
|
|
24
|
-
Requires-Python: >=3.
|
|
23
|
+
Requires-Python: >=3.9
|
|
25
24
|
Requires-Dist: anyio<5,>=3.5.0
|
|
26
25
|
Requires-Dist: distro<2,>=1.7.0
|
|
27
26
|
Requires-Dist: docstring-parser<1,>=0.15
|
|
@@ -45,7 +44,7 @@ Description-Content-Type: text/markdown
|
|
|
45
44
|
<!-- prettier-ignore -->
|
|
46
45
|
[)](https://pypi.org/project/anthropic/)
|
|
47
46
|
|
|
48
|
-
The Anthropic Python library provides convenient access to the Anthropic REST API from any Python 3.
|
|
47
|
+
The Anthropic Python library provides convenient access to the Anthropic REST API from any Python 3.9+
|
|
49
48
|
application. It includes type definitions for all request params and response fields,
|
|
50
49
|
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
|
|
51
50
|
|
|
@@ -909,7 +908,7 @@ print(anthropic.__version__)
|
|
|
909
908
|
|
|
910
909
|
## Requirements
|
|
911
910
|
|
|
912
|
-
Python 3.
|
|
911
|
+
Python 3.9 or higher.
|
|
913
912
|
|
|
914
913
|
## Contributing
|
|
915
914
|
|
|
@@ -6,13 +6,13 @@ anthropic/_constants.py,sha256=wADeUqY3lsseF0L6jIen-PexfQ06FOtf2dVESXDM828,885
|
|
|
6
6
|
anthropic/_exceptions.py,sha256=bkSqVWxtRdRb31H7MIvtxfh5mo_Xf7Ib3nPTOmAOmGs,4073
|
|
7
7
|
anthropic/_files.py,sha256=_Ux6v6nAsxK4e_4efdt1DiIOZ0hGmlR2ZKKcVfJIfGU,3623
|
|
8
8
|
anthropic/_legacy_response.py,sha256=QsroQ_9LHI8tSoPEvbIXXB44SvLJXaXQX7khjZpnqfE,17235
|
|
9
|
-
anthropic/_models.py,sha256=
|
|
9
|
+
anthropic/_models.py,sha256=IyrtLs1oMFJfVFZP2l5If10nLPldtx7GIa7BFTT-mPQ,33342
|
|
10
10
|
anthropic/_qs.py,sha256=craIKyvPktJ94cvf9zn8j8ekG9dWJzhWv0ob34lIOv4,4828
|
|
11
11
|
anthropic/_resource.py,sha256=FYEOzfhB-XWTR2gyTmQuuFoecRiVXxe_SpjZlQQGytU,1080
|
|
12
12
|
anthropic/_response.py,sha256=1Y7-OrGn1lOwvZ_SmMlwT9Nb2i9A1RYw2Q4-F1cwPSU,30542
|
|
13
|
-
anthropic/_streaming.py,sha256=
|
|
13
|
+
anthropic/_streaming.py,sha256=AVgSkkvKHZsFD4xQbkOi9Oi0vkHoEZbkccyUw5yIxmA,14072
|
|
14
14
|
anthropic/_types.py,sha256=vEab5B5Hp7xQQafVrgSCHeEPUmf74jofqIPo-n7Xljk,7338
|
|
15
|
-
anthropic/_version.py,sha256=
|
|
15
|
+
anthropic/_version.py,sha256=z8I3OHqtTfd1EnrVYdD1E1IUxYez5VVMOM8BxtooIxQ,162
|
|
16
16
|
anthropic/pagination.py,sha256=MgGFbx3GDm4XASijWas0-2eVb1iGR-DgqyPrDf5Jll8,5152
|
|
17
17
|
anthropic/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
18
|
anthropic/_decoders/jsonl.py,sha256=KDLw-Frjo7gRup5qDp_BWkXIZ-mFZU5vFDz0WBhEKcs,3510
|
|
@@ -25,10 +25,10 @@ anthropic/_utils/_proxy.py,sha256=aglnj2yBTDyGX9Akk2crZHrl10oqRmceUy2Zp008XEs,19
|
|
|
25
25
|
anthropic/_utils/_reflection.py,sha256=ZmGkIgT_PuwedyNBrrKGbxoWtkpytJNU1uU4QHnmEMU,1364
|
|
26
26
|
anthropic/_utils/_resources_proxy.py,sha256=Y6WaTfDzBlt-GXVlTQLlIjpkSZZ8fRlMzXuRBh64CrA,604
|
|
27
27
|
anthropic/_utils/_streams.py,sha256=SMC90diFFecpEg_zgDRVbdR3hSEIgVVij4taD-noMLM,289
|
|
28
|
-
anthropic/_utils/_sync.py,sha256=
|
|
28
|
+
anthropic/_utils/_sync.py,sha256=HBnZkkBnzxtwOZe0212C4EyoRvxhTVtTrLFDz2_xVCg,1589
|
|
29
29
|
anthropic/_utils/_transform.py,sha256=NjCzmnfqYrsAikUHQig6N9QfuTVbKipuP3ur9mcNF-E,15951
|
|
30
30
|
anthropic/_utils/_typing.py,sha256=N_5PPuFNsaygbtA_npZd98SVN1LQQvFTKL6bkWPBZGU,4786
|
|
31
|
-
anthropic/_utils/_utils.py,sha256=
|
|
31
|
+
anthropic/_utils/_utils.py,sha256=ugfUaneOK7I8h9b3656flwf5u_kthY0gvNuqvgOLoSU,12252
|
|
32
32
|
anthropic/lib/.keep,sha256=wuNrz-5SXo3jJaJOJgz4vFHM41YH_g20F5cRQo0vLes,224
|
|
33
33
|
anthropic/lib/__init__.py,sha256=ed3VXosCln6iXSojwutNZjzjoIVpDLIHfMiiMiSHjlU,99
|
|
34
34
|
anthropic/lib/_files.py,sha256=7gggVMi-rWE-42gElwl7nncy3Gf_V62Ga6cIln_yG_M,1209
|
|
@@ -407,7 +407,7 @@ anthropic/types/shared/not_found_error.py,sha256=R6OsCvAmsf_SB2TwoX6E63o049qZMaA
|
|
|
407
407
|
anthropic/types/shared/overloaded_error.py,sha256=PlyhHt3wmzcnynSfkWbfP4XkLoWsPa9B39V3CyAdgx8,282
|
|
408
408
|
anthropic/types/shared/permission_error.py,sha256=nuyxtLXOiEkYEbFRXiAWjxU6XtdyjkAaXQ2NgMB3pjw,282
|
|
409
409
|
anthropic/types/shared/rate_limit_error.py,sha256=eYULATjXa6KKdqeBauest7RzuN-bhGsY5BWwH9eYv4c,280
|
|
410
|
-
anthropic-0.72.
|
|
411
|
-
anthropic-0.72.
|
|
412
|
-
anthropic-0.72.
|
|
413
|
-
anthropic-0.72.
|
|
410
|
+
anthropic-0.72.1.dist-info/METADATA,sha256=FBwucRG7lCoAQd8FrN19_dX8a37wBSa05nMBeTrCvj0,28514
|
|
411
|
+
anthropic-0.72.1.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
412
|
+
anthropic-0.72.1.dist-info/licenses/LICENSE,sha256=i_lphP-Lz65-SMrnalKeiiUxe6ngKr9_08xk_flWV6Y,1056
|
|
413
|
+
anthropic-0.72.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|