Skip to content

perf: reduce root import overhead#1513

Open
wilyan09007 wants to merge 1 commit into
anthropics:mainfrom
wilyan09007:issue-1211-slow-imports
Open

perf: reduce root import overhead#1513
wilyan09007 wants to merge 1 commit into
anthropics:mainfrom
wilyan09007:issue-1211-slow-imports

Conversation

@wilyan09007
Copy link
Copy Markdown

@wilyan09007 wilyan09007 commented May 8, 2026

Summary:
Fixes #1211 by reducing import anthropic overhead with lazy root exports while preserving the public import surface. The root import now avoids loading the heavy client/type stack until those symbols are used.

Changes:

  • Lazily resolve root client, type, cloud, streaming, credential, and helper exports.
  • Keep type-checker visibility without heavy runtime imports.
  • Avoid importing anthropic.types from _exceptions.py at runtime.
  • Add import regression tests for heavy modules and lazy exports.

Testing instructions:

  • Run uv run pytest tests\test_imports.py tests\lib\test_vertex.py tests\lib\tools\test_functions.py -q.
  • Run uv run ruff check src\anthropic\__init__.py src\anthropic\_exceptions.py tests\test_imports.py.
  • Run uv run pyright src\anthropic\__init__.py src\anthropic\_exceptions.py tests\test_imports.py.
  • Run python -X importtime -c "import anthropic".

@wilyan09007 wilyan09007 requested a review from a team as a code owner May 8, 2026 00:30
@wilyan09007 wilyan09007 force-pushed the issue-1211-slow-imports branch from fd2e46b to e8e2b6d Compare May 8, 2026 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slow imports

1 participant