Skip to content

http

Generic HTTP client for Snowpark Stored Procedures.

Supports OAuth2 (client_credentials + password grant), HTTP Basic, Bearer token, and API key authentication. Secrets are injected from Snowflake Secrets at call time.

All imports of requests and snowflake.snowpark.secrets are lazy so the module is importable in environments where those packages are not installed.

concurrent_map(fn, inputs, *, max_workers=10)

Apply fn concurrently over inputs using a thread pool.

Designed for vectorized UDFs where each row triggers an independent HTTP call. Preserves input order in the returned list.

Parameters:

Name Type Description Default
fn Callable[[Any], Any]

Callable to apply to each element of inputs.

required
inputs list[Any]

List of arguments passed to fn one at a time.

required
max_workers int

Maximum number of concurrent threads.

10

Returns:

Type Description
list[Any]

List of results in the same order as inputs.

Source code in src/pinky_connect/http.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def concurrent_map(
    fn: Callable[[Any], Any],
    inputs: list[Any],
    *,
    max_workers: int = 10,
) -> list[Any]:
    """Apply *fn* concurrently over *inputs* using a thread pool.

    Designed for vectorized UDFs where each row triggers an independent
    HTTP call.  Preserves input order in the returned list.

    Args:
        fn: Callable to apply to each element of *inputs*.
        inputs: List of arguments passed to *fn* one at a time.
        max_workers: Maximum number of concurrent threads.

    Returns:
        List of results in the same order as *inputs*.
    """
    raise NotImplementedError("pending migration from _BACKUP/snowflake-kit-connect-bak")

fetch_token(token_url, client_id, client_secret, grant_type='client_credentials', **extra)

Obtain an OAuth2 access token.

Parameters:

Name Type Description Default
token_url str

The OAuth2 token endpoint URL.

required
client_id str

OAuth2 client identifier.

required
client_secret str

OAuth2 client secret.

required
grant_type str

OAuth2 grant type — client_credentials or password.

'client_credentials'
**extra Any

Additional parameters forwarded to the token request body.

{}

Returns:

Type Description
str

The raw access token string.

Raises:

Type Description
HTTPError

If the token endpoint returns a non-2xx status.

Source code in src/pinky_connect/http.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def fetch_token(
    token_url: str,
    client_id: str,
    client_secret: str,
    grant_type: str = "client_credentials",
    **extra: Any,
) -> str:
    """Obtain an OAuth2 access token.

    Args:
        token_url: The OAuth2 token endpoint URL.
        client_id: OAuth2 client identifier.
        client_secret: OAuth2 client secret.
        grant_type: OAuth2 grant type — ``client_credentials`` or ``password``.
        **extra: Additional parameters forwarded to the token request body.

    Returns:
        The raw access token string.

    Raises:
        requests.HTTPError: If the token endpoint returns a non-2xx status.
    """
    raise NotImplementedError("pending migration from _BACKUP/snowflake-kit-connect-bak")

paginate(url, *, auth_scheme, secret_name, params=None, page_size=100)

Fetch all pages from a paginated REST endpoint.

Supports Link-header pagination, next_key, and next_param strategies. Yields one response dict per page.

Parameters:

Name Type Description Default
url str

The base endpoint URL.

required
auth_scheme str

Authentication strategy — one of oauth2_client_credentials, oauth2_password, basic, bearer, api_key.

required
secret_name str

Name of the Snowflake Secret holding credentials.

required
params dict[str, Any] | None

Initial query parameters merged into every request.

None
page_size int

Number of records requested per page.

100

Yields:

Type Description
Iterable[dict[str, Any]]

Parsed JSON response body for each page.

Raises:

Type Description
HTTPError

On non-2xx responses.

ValueError

If auth_scheme is not recognised.

Source code in src/pinky_connect/http.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def paginate(
    url: str,
    *,
    auth_scheme: str,
    secret_name: str,
    params: dict[str, Any] | None = None,
    page_size: int = 100,
) -> Iterable[dict[str, Any]]:
    """Fetch all pages from a paginated REST endpoint.

    Supports Link-header pagination, next_key, and next_param strategies.
    Yields one response dict per page.

    Args:
        url: The base endpoint URL.
        auth_scheme: Authentication strategy — one of ``oauth2_client_credentials``,
            ``oauth2_password``, ``basic``, ``bearer``, ``api_key``.
        secret_name: Name of the Snowflake Secret holding credentials.
        params: Initial query parameters merged into every request.
        page_size: Number of records requested per page.

    Yields:
        Parsed JSON response body for each page.

    Raises:
        requests.HTTPError: On non-2xx responses.
        ValueError: If ``auth_scheme`` is not recognised.
    """
    raise NotImplementedError("pending migration from _BACKUP/snowflake-kit-connect-bak")