ds_protocol_http_py_lib.utils

File: __init__.py Region: ds_protocol_http_py_lib/utils

Shared utilities used by linked services and datasets.

  • json_utils — JSON parse / dotted-path / list helpers

  • http — HTTP client, request snapshots, inject locations, rate limiting

Submodules

Functions

find_keys_in_json(→ str | None)

Recursively search for a set of keys in a nested JSON structure and return their value.

get_list(→ list[Any])

Read a list at path; missing path yields [].

get_path(→ Any)

Read a value via dotted path (a.b.0.c).

parse_json(→ Any)

Parse JSON bytes/str; empty content returns None.

Package Contents

ds_protocol_http_py_lib.utils.find_keys_in_json(json_data: dict[str, Any] | list[Any], target_keys: set[str]) → str | None[source]

Recursively search for a set of keys in a nested JSON structure and return their value.

Parameters:
  • json_data – The JSON data to search through.

  • target_keys – A set of keys to search for.

Returns:

The value of the found key as a string, or None if no key is found.

Example

>>> data = {"user": {"token": "abc123"}}
>>> find_keys_in_json(data, {"token"})
'abc123'
ds_protocol_http_py_lib.utils.get_list(data: Any, path: str) → list[Any][source]

Read a list at path; missing path yields [].

Raises:

TypeError – If the path resolves to a non-list value.

ds_protocol_http_py_lib.utils.get_path(data: Any, path: str) → Any[source]

Read a value via dotted path (a.b.0.c).

$ / "" returns data itself. Missing segments return None.

ds_protocol_http_py_lib.utils.parse_json(content: bytes | str | None) → Any[source]

Parse JSON bytes/str; empty content returns None.