Querystring Class — anthropic-sdk-python Architecture
Architecture documentation for the Querystring class in _qs.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD 765fcca3_81c1_6ab1_98e8_c2929e7562e2["Querystring"] 738dc346_a11e_4dc7_f7df_dced9f1a2476["_qs.py"] 765fcca3_81c1_6ab1_98e8_c2929e7562e2 -->|defined in| 738dc346_a11e_4dc7_f7df_dced9f1a2476 78f46bcc_8476_4f5d_fc0e_2780e1fd8f1c["__init__()"] 765fcca3_81c1_6ab1_98e8_c2929e7562e2 -->|method| 78f46bcc_8476_4f5d_fc0e_2780e1fd8f1c b6ac4bed_a76e_e87f_8599_aceace51bb2e["parse()"] 765fcca3_81c1_6ab1_98e8_c2929e7562e2 -->|method| b6ac4bed_a76e_e87f_8599_aceace51bb2e bf6a5442_2bf0_bd51_b523_e2e0677623fb["stringify()"] 765fcca3_81c1_6ab1_98e8_c2929e7562e2 -->|method| bf6a5442_2bf0_bd51_b523_e2e0677623fb a4465198_32b8_125c_a12b_a1f3510b8955["stringify_items()"] 765fcca3_81c1_6ab1_98e8_c2929e7562e2 -->|method| a4465198_32b8_125c_a12b_a1f3510b8955 fb8d0988_171e_e6ac_7477_809943dfac39["_stringify_item()"] 765fcca3_81c1_6ab1_98e8_c2929e7562e2 -->|method| fb8d0988_171e_e6ac_7477_809943dfac39 ddfa0c97_1cdb_9784_5f60_3b9a93c5e730["_primitive_value_to_str()"] 765fcca3_81c1_6ab1_98e8_c2929e7562e2 -->|method| ddfa0c97_1cdb_9784_5f60_3b9a93c5e730
Relationship Graph
Source Code
src/anthropic/_qs.py lines 23–129
class Querystring:
array_format: ArrayFormat
nested_format: NestedFormat
def __init__(
self,
*,
array_format: ArrayFormat = "repeat",
nested_format: NestedFormat = "brackets",
) -> None:
self.array_format = array_format
self.nested_format = nested_format
def parse(self, query: str) -> Mapping[str, object]:
# Note: custom format syntax is not supported yet
return parse_qs(query)
def stringify(
self,
params: Params,
*,
array_format: ArrayFormat | NotGiven = not_given,
nested_format: NestedFormat | NotGiven = not_given,
) -> str:
return urlencode(
self.stringify_items(
params,
array_format=array_format,
nested_format=nested_format,
)
)
def stringify_items(
self,
params: Params,
*,
array_format: ArrayFormat | NotGiven = not_given,
nested_format: NestedFormat | NotGiven = not_given,
) -> list[tuple[str, str]]:
opts = Options(
qs=self,
array_format=array_format,
nested_format=nested_format,
)
return flatten([self._stringify_item(key, value, opts) for key, value in params.items()])
def _stringify_item(
self,
key: str,
value: Data,
opts: Options,
) -> list[tuple[str, str]]:
if isinstance(value, Mapping):
items: list[tuple[str, str]] = []
nested_format = opts.nested_format
for subkey, subvalue in value.items():
items.extend(
self._stringify_item(
# TODO: error if unknown format
f"{key}.{subkey}" if nested_format == "dots" else f"{key}[{subkey}]",
subvalue,
opts,
)
)
return items
if isinstance(value, (list, tuple)):
array_format = opts.array_format
if array_format == "comma":
return [
(
key,
",".join(self._primitive_value_to_str(item) for item in value if item is not None),
),
]
elif array_format == "repeat":
items = []
for item in value:
items.extend(self._stringify_item(key, item, opts))
return items
elif array_format == "indices":
Domain
Defined In
Source
Frequently Asked Questions
What is the Querystring class?
Querystring is a class in the anthropic-sdk-python codebase, defined in src/anthropic/_qs.py.
Where is Querystring defined?
Querystring is defined in src/anthropic/_qs.py at line 23.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free