_auth.py — anthropic-sdk-python Source File
Architecture documentation for _auth.py, a python file in the anthropic-sdk-python codebase. 6 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR a77146a7_73e4_972e_7fba_fee2f52d6092["_auth.py"] da7ce3bd_4934_ff39_8877_5ba81a168358["_utils"] a77146a7_73e4_972e_7fba_fee2f52d6092 --> da7ce3bd_4934_ff39_8877_5ba81a168358 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"] a77146a7_73e4_972e_7fba_fee2f52d6092 --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875 9c26e8a9_1ad2_1174_876a_1fc500ce0eaf["httpx"] a77146a7_73e4_972e_7fba_fee2f52d6092 --> 9c26e8a9_1ad2_1174_876a_1fc500ce0eaf 987f39eb_2369_1187_7f43_345216a16436["boto3"] a77146a7_73e4_972e_7fba_fee2f52d6092 --> 987f39eb_2369_1187_7f43_345216a16436 5a6eada3_45ab_ad8f_dda1_0ec7260487dd["botocore.auth"] a77146a7_73e4_972e_7fba_fee2f52d6092 --> 5a6eada3_45ab_ad8f_dda1_0ec7260487dd 2e99d7ab_7c67_47cd_4c00_2d103544a457["botocore.awsrequest"] a77146a7_73e4_972e_7fba_fee2f52d6092 --> 2e99d7ab_7c67_47cd_4c00_2d103544a457 cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157["_client.py"] cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 --> a77146a7_73e4_972e_7fba_fee2f52d6092 style a77146a7_73e4_972e_7fba_fee2f52d6092 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from __future__ import annotations
from typing import TYPE_CHECKING
import httpx
from ..._utils import lru_cache
if TYPE_CHECKING:
import boto3
@lru_cache(maxsize=512)
def _get_session(
*,
aws_access_key: str | None,
aws_secret_key: str | None,
aws_session_token: str | None,
region: str | None,
profile: str | None,
) -> boto3.Session:
import boto3
return boto3.Session(
profile_name=profile,
region_name=region,
aws_access_key_id=aws_access_key,
aws_secret_access_key=aws_secret_key,
aws_session_token=aws_session_token,
)
def get_auth_headers(
*,
method: str,
url: str,
headers: httpx.Headers,
aws_access_key: str | None,
aws_secret_key: str | None,
aws_session_token: str | None,
region: str | None,
profile: str | None,
data: str | None,
) -> dict[str, str]:
from botocore.auth import SigV4Auth
from botocore.awsrequest import AWSRequest
session = _get_session(
profile=profile,
region=region,
aws_access_key=aws_access_key,
aws_secret_key=aws_secret_key,
aws_session_token=aws_session_token,
)
# The connection header may be stripped by a proxy somewhere, so the receiver
# of this message may not see this header, so we remove it from the set of headers
# that are signed.
headers = headers.copy()
del headers["connection"]
request = AWSRequest(method=method.upper(), url=url, headers=headers, data=data)
credentials = session.get_credentials()
if not credentials:
raise RuntimeError("could not resolve credentials from session")
signer = SigV4Auth(credentials, "bedrock", session.region_name)
signer.add_auth(request)
prepped = request.prepare()
return {key: value for key, value in dict(prepped.headers).items() if value is not None}
Domain
Subdomains
Functions
Dependencies
- _utils
- boto3
- botocore.auth
- botocore.awsrequest
- httpx
- 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): _get_session, boto3, get_auth_headers.
What does _auth.py depend on?
_auth.py imports 6 module(s): _utils, boto3, botocore.auth, botocore.awsrequest, httpx, 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/bedrock/_auth.py (domain: AnthropicClient, subdomain: Authentication, directory: src/anthropic/lib/bedrock).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free