_auth.py — anthropic-sdk-python Source File
Architecture documentation for _auth.py, a python file in the anthropic-sdk-python codebase. 4 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 5fc3941b_5c44_ade1_4cda_60070b8f7508["_auth.py"] 5f21b15f_f487_df79_900b_329b32fed2b6["_extras"] 5fc3941b_5c44_ade1_4cda_60070b8f7508 --> 5f21b15f_f487_df79_900b_329b32fed2b6 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"] 5fc3941b_5c44_ade1_4cda_60070b8f7508 --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875 29181b16_45cc_d54f_a79d_1520e70b58fe["google.auth.credentials"] 5fc3941b_5c44_ade1_4cda_60070b8f7508 --> 29181b16_45cc_d54f_a79d_1520e70b58fe cb1a5095_e070_af90_3baf_b4a46709576a["google.auth.transport.requests"] 5fc3941b_5c44_ade1_4cda_60070b8f7508 --> cb1a5095_e070_af90_3baf_b4a46709576a 7bcf2a66_49f2_0382_7180_1ee6501f1674["_client.py"] 7bcf2a66_49f2_0382_7180_1ee6501f1674 --> 5fc3941b_5c44_ade1_4cda_60070b8f7508 style 5fc3941b_5c44_ade1_4cda_60070b8f7508 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from __future__ import annotations
from typing import TYPE_CHECKING, Any, cast
from .._extras import google_auth
if TYPE_CHECKING:
from google.auth.credentials import Credentials # type: ignore[import-untyped]
# pyright: reportMissingTypeStubs=false, reportUnknownVariableType=false, reportUnknownMemberType=false, reportUnknownArgumentType=false
# google libraries don't provide types :/
# Note: these functions are blocking as they make HTTP requests, the async
# client runs these functions in a separate thread to ensure they do not
# cause synchronous blocking issues.
def load_auth(*, project_id: str | None) -> tuple[Credentials, str]:
try:
from google.auth.transport.requests import Request # type: ignore[import-untyped]
except ModuleNotFoundError as err:
raise RuntimeError(
f"Could not import google.auth, you need to install the SDK with `pip install anthropic[vertex]`"
) from err
credentials, loaded_project_id = google_auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"],
)
credentials = cast(Any, credentials)
credentials.refresh(Request())
if not project_id:
project_id = loaded_project_id
if not project_id:
raise ValueError("Could not resolve project_id")
if not isinstance(project_id, str):
raise TypeError(f"Expected project_id to be a str but got {type(project_id)}")
return credentials, project_id
def refresh_auth(credentials: Credentials) -> None:
from google.auth.transport.requests import Request # type: ignore[import-untyped]
credentials.refresh(Request())
Domain
Subdomains
Functions
Dependencies
- _extras
- google.auth.credentials
- google.auth.transport.requests
- typing
Imported By
Source
Frequently Asked Questions
What does _auth.py do?
_auth.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, Authentication subdomain.
What functions are defined in _auth.py?
_auth.py defines 3 function(s): google, load_auth, refresh_auth.
What does _auth.py depend on?
_auth.py imports 4 module(s): _extras, google.auth.credentials, google.auth.transport.requests, typing.
What files import _auth.py?
_auth.py is imported by 1 file(s): _client.py.
Where is _auth.py in the architecture?
_auth.py is located at src/anthropic/lib/vertex/_auth.py (domain: AnthropicClient, subdomain: Authentication, directory: src/anthropic/lib/vertex).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free