Collection¶
utils ¶
Collection utilities for parallel API data loading.
This module provides both legacy and enhanced parallel loading capabilities, supporting both the original t3api-based functions and new httpx-based clients.
parallel_load_collection ¶
parallel_load_collection(method: Callable[P, MetrcCollectionResponse], max_workers: int | None = None, *args: args, **kwargs: kwargs) -> List[MetrcCollectionResponse]
Fetch paginated responses in parallel using a thread pool.
Makes an initial request to determine total records and page size, then fetches all remaining pages concurrently via a thread pool executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Callable[P, MetrcCollectionResponse]
|
A callable that returns a |
required |
max_workers
|
int | None
|
Maximum number of threads for concurrent fetching.
Passed directly to |
None
|
*args
|
args
|
Positional arguments forwarded to |
()
|
**kwargs
|
kwargs
|
Keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
List[MetrcCollectionResponse]
|
A list of |
List[MetrcCollectionResponse]
|
by page number. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the first response is missing the |
Source code in t3api_utils/collection/utils.py
extract_data ¶
Flatten a list of MetrcCollectionResponse objects that each have a .data property
into a single list of MetrcObject items.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
responses
|
List[MetrcCollectionResponse]
|
A list of MetrcCollectionResponse objects. |
required |
Returns:
| Type | Description |
|---|---|
List[MetrcObject]
|
List[MetrcObject]: A flattened list of all items from the |
Example
extract_data([Response1(data=[1, 2]), Response2(data=[3])]) [1, 2, 3]