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 | |
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'
|
**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 | |
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 |
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 |
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 | |