nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 stdenv,
6
7 # build-system
8 hatch-fancy-pypi-readme,
9 hatchling,
10
11 # dependencies
12 anyio,
13 distro,
14 docstring-parser,
15 httpx,
16 jiter,
17 pydantic,
18 sniffio,
19 tokenizers,
20 typing-extensions,
21
22 # optional dependencies
23 google-auth,
24
25 # test
26 dirty-equals,
27 inline-snapshot,
28 nest-asyncio,
29 pytest-asyncio,
30 pytest-xdist,
31 pytestCheckHook,
32 respx,
33}:
34
35buildPythonPackage rec {
36 pname = "anthropic";
37 version = "0.76.0";
38 pyproject = true;
39
40 src = fetchFromGitHub {
41 owner = "anthropics";
42 repo = "anthropic-sdk-python";
43 tag = "v${version}";
44 hash = "sha256-QEwUOPL/9ROV/UgD6KF2ePzjXDKHYrYrFvbJpVV8MO0=";
45 };
46
47 postPatch = ''
48 substituteInPlace pyproject.toml \
49 --replace-fail '"hatchling==1.26.3"' '"hatchling>=1.26.3"'
50 '';
51
52 build-system = [
53 hatchling
54 hatch-fancy-pypi-readme
55 ];
56
57 dependencies = [
58 anyio
59 distro
60 docstring-parser
61 httpx
62 jiter
63 pydantic
64 sniffio
65 tokenizers
66 typing-extensions
67 ];
68
69 optional-dependencies = {
70 vertex = [ google-auth ];
71 };
72
73 nativeCheckInputs = [
74 dirty-equals
75 inline-snapshot
76 nest-asyncio
77 pytest-asyncio
78 pytest-xdist
79 pytestCheckHook
80 respx
81 ];
82
83 pythonImportsCheck = [ "anthropic" ];
84
85 disabledTests = [
86 # Test require network access
87 "test_copy_build_request"
88 ]
89 ++ lib.optionals stdenv.hostPlatform.isDarwin [
90 # Hangs
91 # https://github.com/anthropics/anthropic-sdk-python/issues/1008
92 "test_get_platform"
93 ];
94
95 disabledTestPaths = [
96 # Test require network access
97 "tests/api_resources"
98 "tests/lib/test_bedrock.py"
99 ];
100
101 pytestFlags = [
102 "-Wignore::DeprecationWarning"
103 ];
104
105 meta = {
106 description = "Anthropic's safety-first language model APIs";
107 homepage = "https://github.com/anthropics/anthropic-sdk-python";
108 changelog = "https://github.com/anthropics/anthropic-sdk-python/releases/tag/${src.tag}";
109 license = lib.licenses.mit;
110 maintainers = [
111 lib.maintainers.natsukium
112 lib.maintainers.sarahec
113 ];
114 };
115}