openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
8b86354069b998fe6858aae6a7aee2153128384f

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

pyproject.toml

271lines · modecode

1[project]
2name = "openai"
3version = "2.41.0"
4description = "The official Python library for the openai API"
5dynamic = ["readme"]
6license = "Apache-2.0"
7authors = [
8{ name = "OpenAI", email = "support@openai.com" },
9]
10
11dependencies = [
12 "httpx>=0.23.0, <1",
13 "pydantic>=1.9.0, <3",
14 "typing-extensions>=4.14, <5",
15 "anyio>=3.5.0, <5",
16 "distro>=1.7.0, <2",
17 "sniffio",
18]
19
20requires-python = ">= 3.9"
21classifiers = [
22 "Typing :: Typed",
23 "Intended Audience :: Developers",
24 "Programming Language :: Python :: 3.9",
25 "Programming Language :: Python :: 3.10",
26 "Programming Language :: Python :: 3.11",
27 "Programming Language :: Python :: 3.12",
28 "Programming Language :: Python :: 3.13",
29 "Programming Language :: Python :: 3.14",
30 "Operating System :: OS Independent",
31 "Operating System :: POSIX",
32 "Operating System :: MacOS",
33 "Operating System :: POSIX :: Linux",
34 "Operating System :: Microsoft :: Windows",
35 "Topic :: Software Development :: Libraries :: Python Modules",
36 "License :: OSI Approved :: Apache Software License"
37]
38
39[project.urls]
40Homepage = "https://github.com/openai/openai-python"
41Repository = "https://github.com/openai/openai-python"
42
43[project.optional-dependencies]
44aiohttp = ["aiohttp", "httpx_aiohttp>=0.1.9"]
45realtime = ["websockets >= 13, < 16"]
46
47[tool.rye]
48managed = true
49# version pins are in requirements-dev.lock
50dev-dependencies = [
51 "pyright==1.1.399",
52 "mypy==1.17",
53 "respx",
54 "pytest",
55 "pytest-asyncio",
56 "ruff",
57 "time-machine",
58 "nox",
59 "dirty-equals>=0.6.0",
60 "importlib-metadata>=6.7.0",
61 "rich>=13.7.1",
62 "pytest-xdist>=3.6.1",
63 "griffe>=1",
64]
65
66[tool.rye.scripts]
67format = { chain = [
68 "format:ruff",
69 "format:docs",
70 "fix:ruff",
71 # run formatting again to fix any inconsistencies when imports are stripped
72 "format:ruff",
73]}
74"format:docs" = "bash -c 'python scripts/utils/ruffen-docs.py README.md $(find . -type f -name api.md)'"
75"format:ruff" = "ruff format"
76
77"lint" = { chain = [
78 "check:ruff",
79 "typecheck",
80 "check:importable",
81]}
82"check:ruff" = "ruff check ."
83"fix:ruff" = "ruff check --fix ."
84
85"check:importable" = "python -c 'import openai'"
86
87typecheck = { chain = [
88 "typecheck:pyright",
89 "typecheck:mypy"
90]}
91"typecheck:pyright" = "pyright"
92"typecheck:verify-types" = "pyright --verifytypes openai --ignoreexternal"
93"typecheck:mypy" = "mypy ."
94
95[build-system]
96requires = ["hatchling==1.26.3", "hatch-fancy-pypi-readme"]
97build-backend = "hatchling.build"
98
99[tool.hatch.build]
100include = [
101 "src/*"
102]
103
104[tool.hatch.build.targets.wheel]
105packages = ["src/openai"]
106
107[tool.hatch.build.targets.sdist]
108# Basically everything except hidden files/directories (such as .github, .devcontainers, .python-version, etc)
109include = [
110 "/*.toml",
111 "/*.json",
112 "/*.lock",
113 "/*.md",
114 "/mypy.ini",
115 "/noxfile.py",
116 "bin/*",
117 "examples/*",
118 "src/*",
119 "tests/*",
120]
121
122[tool.hatch.metadata.hooks.fancy-pypi-readme]
123content-type = "text/markdown"
124
125[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
126path = "README.md"
127
128[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
129# replace relative links with absolute links
130pattern = '\[(.+?)\]\(((?!https?://)\S+?)\)'
131replacement = '[\1](https://github.com/openai/openai-python/tree/main/\g<2>)'
132
133[tool.pytest.ini_options]
134testpaths = ["tests"]
135addopts = "--tb=short -n auto"
136xfail_strict = true
137asyncio_mode = "auto"
138asyncio_default_fixture_loop_scope = "session"
139filterwarnings = [
140 "error"
141]
142
143[tool.pyright]
144# this enables practically every flag given by pyright.
145# there are a couple of flags that are still disabled by
146# default in strict mode as they are experimental and niche.
147typeCheckingMode = "strict"
148pythonVersion = "3.9"
149
150exclude = [
151 "_dev",
152 ".venv",
153 ".nox",
154 ".git",
155]
156
157reportImplicitOverride = true
158reportOverlappingOverload = false
159
160reportImportCycles = false
161reportPrivateUsage = false
162
163[tool.mypy]
164pretty = true
165show_error_codes = true
166
167# Exclude _files.py because mypy isn't smart enough to apply
168# the correct type narrowing and as this is an internal module
169# it's fine to just use Pyright.
170#
171# We also exclude our `tests` as mypy doesn't always infer
172# types correctly and Pyright will still catch any type errors.
173exclude = ["src/openai/_files.py", "_dev/.*.py", "tests/.*"]
174
175strict_equality = true
176implicit_reexport = true
177check_untyped_defs = true
178no_implicit_optional = true
179
180warn_return_any = true
181warn_unreachable = true
182warn_unused_configs = true
183
184# Turn these options off as it could cause conflicts
185# with the Pyright options.
186warn_unused_ignores = false
187warn_redundant_casts = false
188
189disallow_any_generics = true
190disallow_untyped_defs = true
191disallow_untyped_calls = true
192disallow_subclassing_any = true
193disallow_incomplete_defs = true
194disallow_untyped_decorators = true
195cache_fine_grained = true
196
197# By default, mypy reports an error if you assign a value to the result
198# of a function call that doesn't return anything. We do this in our test
199# cases:
200# ```
201# result = ...
202# assert result is None
203# ```
204# Changing this codegen to make mypy happy would increase complexity
205# and would not be worth it.
206disable_error_code = "func-returns-value,overload-cannot-match"
207
208# https://github.com/python/mypy/issues/12162
209[[tool.mypy.overrides]]
210module = "black.files.*"
211ignore_errors = true
212ignore_missing_imports = true
213
214
215[tool.ruff]
216line-length = 120
217output-format = "grouped"
218target-version = "py38"
219
220[tool.ruff.format]
221docstring-code-format = true
222
223[tool.ruff.lint]
224select = [
225 # isort
226 "I",
227 # bugbear rules
228 "B",
229 # remove unused imports
230 "F401",
231 # check for missing future annotations
232 "FA102",
233 # bare except statements
234 "E722",
235 # unused arguments
236 "ARG",
237 # print statements
238 "T201",
239 "T203",
240 # misuse of typing.TYPE_CHECKING
241 "TC004",
242 # import rules
243 "TID251",
244]
245ignore = [
246 # mutable defaults
247 "B006",
248]
249unfixable = [
250 # disable auto fix for print statements
251 "T201",
252 "T203",
253]
254
255extend-safe-fixes = ["FA102"]
256
257[tool.ruff.lint.flake8-tidy-imports.banned-api]
258"functools.lru_cache".msg = "This function does not retain type information for the wrapped function's arguments; The `lru_cache` function from `_utils` should be used instead"
259
260[tool.ruff.lint.isort]
261length-sort = true
262length-sort-straight = true
263combine-as-imports = true
264extra-standard-library = ["typing_extensions"]
265known-first-party = ["openai", "tests"]
266
267[tool.ruff.lint.per-file-ignores]
268"bin/**.py" = ["T201", "T203"]
269"scripts/**.py" = ["T201", "T203"]
270"tests/**.py" = ["T201", "T203"]
271"examples/**.py" = ["T201", "T203"]
272