_httpx.py — anthropic-sdk-python Source File
Architecture documentation for _httpx.py, a python file in the anthropic-sdk-python codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR b2d85656_2934_236c_1afe_774e6230184c["_httpx.py"] 60ae2a50_ba5e_3ce6_385a_d75327a2552c["ipaddress"] b2d85656_2934_236c_1afe_774e6230184c --> 60ae2a50_ba5e_3ce6_385a_d75327a2552c 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"] b2d85656_2934_236c_1afe_774e6230184c --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875 825a128d_2d13_7953_a9ac_215c6b03f8c8["urllib.request"] b2d85656_2934_236c_1afe_774e6230184c --> 825a128d_2d13_7953_a9ac_215c6b03f8c8 style b2d85656_2934_236c_1afe_774e6230184c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""
This file includes code adapted from HTTPX's utility module
(https://github.com/encode/httpx/blob/336204f0121a9aefdebac5cacd81f912bafe8057/httpx/_utils.py).
We implement custom proxy handling to support configurations like `socket_options`,
which are not currently configurable through the HTTPX client.
For more context, see: https://github.com/encode/httpx/discussions/3514
"""
from __future__ import annotations
import ipaddress
from typing import Mapping
from urllib.request import getproxies
def is_ipv4_hostname(hostname: str) -> bool:
try:
ipaddress.IPv4Address(hostname.split("/")[0])
except Exception:
return False
return True
def is_ipv6_hostname(hostname: str) -> bool:
try:
ipaddress.IPv6Address(hostname.split("/")[0])
except Exception:
return False
return True
def get_environment_proxies() -> Mapping[str, str | None]:
"""
Gets the proxy mappings based on environment variables.
We use our own logic to parse these variables, as HTTPX
doesn’t allow full configuration of the underlying
transport when proxies are set via environment variables.
"""
proxy_info = getproxies()
mounts: dict[str, str | None] = {}
for scheme in ("http", "https", "all"):
if proxy_info.get(scheme):
hostname = proxy_info[scheme]
mounts[f"{scheme}://"] = hostname if "://" in hostname else f"http://{hostname}"
no_proxy_hosts = [host.strip() for host in proxy_info.get("no", "").split(",")]
for hostname in no_proxy_hosts:
if hostname == "*":
return {}
elif hostname:
if "://" in hostname:
mounts[hostname] = None
elif is_ipv4_hostname(hostname):
mounts[f"all://{hostname}"] = None
elif is_ipv6_hostname(hostname):
mounts[f"all://[{hostname}]"] = None
elif hostname.lower() == "localhost":
mounts[f"all://{hostname}"] = None
else:
mounts[f"all://*{hostname}"] = None
return mounts
Domain
Subdomains
Dependencies
- ipaddress
- typing
- urllib.request
Source
Frequently Asked Questions
What does _httpx.py do?
_httpx.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, AsyncAPI subdomain.
What functions are defined in _httpx.py?
_httpx.py defines 3 function(s): get_environment_proxies, is_ipv4_hostname, is_ipv6_hostname.
What does _httpx.py depend on?
_httpx.py imports 3 module(s): ipaddress, typing, urllib.request.
Where is _httpx.py in the architecture?
_httpx.py is located at src/anthropic/_utils/_httpx.py (domain: AnthropicClient, subdomain: AsyncAPI, directory: src/anthropic/_utils).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free