API Operations¶
operations ¶
Standalone T3 API operations that work with authenticated clients.
This module provides high-level operations for T3 API endpoints that can be called independently with an authenticated client instance.
Available operations: - send_api_request / send_api_request_async: Most generic operation, supports any HTTP method, custom parameters, and doesn't assume response structure - get_collection / get_collection_async: Specialized for paginated collection endpoints, automatically adds page/pageSize parameters
send_api_request ¶
send_api_request(client: T3APIClient, path: str, *, method: str = 'GET', params: Optional[Dict[str, Any]] = None, json_body: Optional[Any] = None, files: Optional[Any] = None, headers: Optional[Dict[str, str]] = None, expected_status: Union[int, tuple[int, ...]] = 200) -> Any
Send a request to any T3 API endpoint (sync wrapper).
This is the most flexible operation that doesn't assume any specific parameter structure or response format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
T3APIClient
|
Authenticated T3APIClient instance |
required |
path
|
str
|
API endpoint path (e.g., "/v2/licenses", "/v2/packages/active", "/v2/facilities/123") |
required |
method
|
str
|
HTTP method (default: "GET") |
'GET'
|
params
|
Optional[Dict[str, Any]]
|
Query parameters (optional) |
None
|
json_body
|
Optional[Any]
|
JSON request body for POST/PUT requests (optional). Mutually exclusive with files. |
None
|
files
|
Optional[Any]
|
Multipart file upload data (optional). Mutually exclusive
with json_body. Accepts the same formats as |
None
|
headers
|
Optional[Dict[str, str]]
|
Additional headers (optional) |
None
|
expected_status
|
Union[int, tuple[int, ...]]
|
Expected HTTP status code(s) (default: 200) |
200
|
Returns:
| Type | Description |
|---|---|
Any
|
Raw response data (could be dict, list, or any JSON-serializable type) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both json_body and files are provided. |
T3HTTPError
|
If request fails or client not authenticated |
Source code in t3api_utils/api/operations.py
get_collection ¶
get_collection(client: T3APIClient, path: str, *, license_number: str, page: int = 1, page_size: int = 100, strict_pagination: bool = False, sort: Optional[str] = None, filter_logic: Literal['and', 'or'] = 'and', filter: Optional[List[str]] = None, **kwargs: Any) -> MetrcCollectionResponse
Get a collection from any T3 API endpoint (sync wrapper).
This is a wrapper around the async implementation using asyncio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
T3APIClient
|
Authenticated T3APIClient instance |
required |
path
|
str
|
API endpoint path (e.g., "/v2/licenses", "/v2/packages/active") |
required |
license_number
|
str
|
The unique identifier for the license (required) |
required |
page
|
int
|
Page number (1-based, default: 1) |
1
|
page_size
|
int
|
Number of items per page (default: 100) |
100
|
strict_pagination
|
bool
|
If enabled, out of bounds pages throw 400 (default: False) |
False
|
sort
|
Optional[str]
|
Collection sort order (e.g., "label:asc") |
None
|
filter_logic
|
Literal['and', 'or']
|
How filters are applied - "and" or "or" (default: "and") |
'and'
|
filter
|
Optional[List[str]]
|
List of collection filters (e.g., ["label__endswith:0003"]) |
None
|
**kwargs
|
Any
|
Additional query parameters |
{}
|
Returns:
| Type | Description |
|---|---|
MetrcCollectionResponse
|
MetrcCollectionResponse containing data from the endpoint |
Raises:
| Type | Description |
|---|---|
T3HTTPError
|
If request fails or client not authenticated |
Source code in t3api_utils/api/operations.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
get_collection_async
async
¶
get_collection_async(client: T3APIClient, path: str, *, license_number: str, page: int = 1, page_size: int = 100, strict_pagination: bool = False, sort: Optional[str] = None, filter_logic: Literal['and', 'or'] = 'and', filter: Optional[List[str]] = None, **kwargs: Any) -> MetrcCollectionResponse
Get a collection from any T3 API endpoint using an async client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
T3APIClient
|
Authenticated T3APIClient instance |
required |
path
|
str
|
API endpoint path (e.g., "/v2/licenses", "/v2/packages/active") |
required |
license_number
|
str
|
The unique identifier for the license (required) |
required |
page
|
int
|
Page number (1-based, default: 1) |
1
|
page_size
|
int
|
Number of items per page (default: 100) |
100
|
strict_pagination
|
bool
|
If enabled, out of bounds pages throw 400 (default: False) |
False
|
sort
|
Optional[str]
|
Collection sort order (e.g., "label:asc") |
None
|
filter_logic
|
Literal['and', 'or']
|
How filters are applied - "and" or "or" (default: "and") |
'and'
|
filter
|
Optional[List[str]]
|
List of collection filters (e.g., ["label__endswith:0003"]) |
None
|
**kwargs
|
Any
|
Additional query parameters |
{}
|
Returns:
| Type | Description |
|---|---|
MetrcCollectionResponse
|
MetrcCollectionResponse containing data from the endpoint |
Raises:
| Type | Description |
|---|---|
T3HTTPError
|
If request fails or client not authenticated |
Source code in t3api_utils/api/operations.py
send_api_request_async
async
¶
send_api_request_async(client: T3APIClient, path: str, *, method: str = 'GET', params: Optional[Dict[str, Any]] = None, json_body: Optional[Any] = None, files: Optional[Any] = None, headers: Optional[Dict[str, str]] = None, expected_status: Union[int, tuple[int, ...]] = 200) -> Any
Send a request to any T3 API endpoint using an async client.
This is the most flexible operation that doesn't assume any specific parameter structure or response format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
T3APIClient
|
Authenticated T3APIClient instance |
required |
path
|
str
|
API endpoint path (e.g., "/v2/licenses", "/v2/packages/active", "/v2/facilities/123") |
required |
method
|
str
|
HTTP method (default: "GET") |
'GET'
|
params
|
Optional[Dict[str, Any]]
|
Query parameters (optional) |
None
|
json_body
|
Optional[Any]
|
JSON request body for POST/PUT requests (optional). Mutually exclusive with files. |
None
|
files
|
Optional[Any]
|
Multipart file upload data (optional). Mutually exclusive
with json_body. Accepts the same formats as |
None
|
headers
|
Optional[Dict[str, str]]
|
Additional headers (optional) |
None
|
expected_status
|
Union[int, tuple[int, ...]]
|
Expected HTTP status code(s) (default: 200) |
200
|
Returns:
| Type | Description |
|---|---|
Any
|
Raw response data (could be dict, list, or any JSON-serializable type) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both json_body and files are provided. |
T3HTTPError
|
If request fails or client not authenticated |