fal 0.12.1__py3-none-any.whl → 0.12.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fal might be problematic. Click here for more details.

Files changed (116) hide show
  1. fal/__init__.py +12 -3
  2. fal/_serialization.py +18 -0
  3. fal/api.py +140 -59
  4. fal/app.py +309 -86
  5. fal/apps.py +92 -8
  6. fal/auth/__init__.py +20 -1
  7. fal/auth/auth0.py +32 -22
  8. fal/cli.py +34 -52
  9. fal/env.py +0 -4
  10. fal/exceptions/handlers.py +3 -2
  11. fal/flags.py +5 -0
  12. fal/logging/__init__.py +0 -2
  13. fal/logging/trace.py +8 -1
  14. fal/logging/user.py +2 -1
  15. fal/rest_client.py +2 -2
  16. fal/sdk.py +46 -31
  17. fal/sync.py +3 -3
  18. fal/toolkit/__init__.py +18 -1
  19. fal/toolkit/file/file.py +98 -11
  20. fal/toolkit/file/providers/fal.py +43 -2
  21. fal/toolkit/file/types.py +1 -1
  22. fal/toolkit/image/image.py +26 -4
  23. fal/toolkit/optimize.py +50 -0
  24. fal/toolkit/utils/download_utils.py +59 -13
  25. {fal-0.12.1.dist-info → fal-0.12.3.dist-info}/METADATA +7 -7
  26. fal-0.12.3.dist-info/RECORD +66 -0
  27. openapi_fal_rest/models/__init__.py +2 -70
  28. openapi_fal_rest/models/customer_details.py +26 -0
  29. openapi_fal_rest/models/lock_reason.py +16 -0
  30. fal/logging/datadog.py +0 -77
  31. fal-0.12.1.dist-info/RECORD +0 -147
  32. openapi_fal_rest/api/admin/get_invoice_users.py +0 -142
  33. openapi_fal_rest/api/admin/get_usage_per_user.py +0 -199
  34. openapi_fal_rest/api/admin/handle_user_lock.py +0 -191
  35. openapi_fal_rest/api/admin/set_billing_type.py +0 -186
  36. openapi_fal_rest/api/applications/get_status_applications_app_user_id_app_alias_or_id_status_get.py +0 -179
  37. openapi_fal_rest/api/billing/delete_payment_method.py +0 -162
  38. openapi_fal_rest/api/billing/get_checkout_page.py +0 -198
  39. openapi_fal_rest/api/billing/get_setup_intent_key.py +0 -141
  40. openapi_fal_rest/api/billing/get_user_invoices.py +0 -152
  41. openapi_fal_rest/api/billing/get_user_payment_methods.py +0 -152
  42. openapi_fal_rest/api/billing/get_user_price.py +0 -186
  43. openapi_fal_rest/api/billing/get_user_spending.py +0 -192
  44. openapi_fal_rest/api/billing/handle_stripe_webhook.py +0 -173
  45. openapi_fal_rest/api/billing/upcoming_invoice.py +0 -143
  46. openapi_fal_rest/api/billing/update_customer_budget.py +0 -183
  47. openapi_fal_rest/api/files/delete.py +0 -162
  48. openapi_fal_rest/api/files/download.py +0 -162
  49. openapi_fal_rest/api/files/file_exists.py +0 -183
  50. openapi_fal_rest/api/files/list_directory.py +0 -173
  51. openapi_fal_rest/api/files/list_root.py +0 -152
  52. openapi_fal_rest/api/files/upload_from_url.py +0 -179
  53. openapi_fal_rest/api/health/__init__.py +0 -0
  54. openapi_fal_rest/api/health/check.py +0 -136
  55. openapi_fal_rest/api/keys/__init__.py +0 -0
  56. openapi_fal_rest/api/keys/create_key.py +0 -188
  57. openapi_fal_rest/api/keys/delete_key.py +0 -162
  58. openapi_fal_rest/api/keys/list_keys.py +0 -152
  59. openapi_fal_rest/api/logs/__init__.py +0 -0
  60. openapi_fal_rest/api/logs/list_since.py +0 -224
  61. openapi_fal_rest/api/requests/__init__.py +0 -0
  62. openapi_fal_rest/api/requests/requests.py +0 -247
  63. openapi_fal_rest/api/storage/__init__.py +0 -0
  64. openapi_fal_rest/api/storage/get_file_link.py +0 -200
  65. openapi_fal_rest/api/storage/initiate_upload.py +0 -172
  66. openapi_fal_rest/api/storage/upload_file.py +0 -172
  67. openapi_fal_rest/api/tokens/__init__.py +0 -0
  68. openapi_fal_rest/api/tokens/create_token.py +0 -166
  69. openapi_fal_rest/api/usage/__init__.py +0 -0
  70. openapi_fal_rest/api/usage/get_custom_usage_per_machine.py +0 -203
  71. openapi_fal_rest/api/usage/get_gateway_request_stats.py +0 -247
  72. openapi_fal_rest/api/usage/get_gateway_request_stats_by_time.py +0 -236
  73. openapi_fal_rest/api/usage/get_gateway_stats_for_yesterday.py +0 -152
  74. openapi_fal_rest/api/usage/get_shared_usage_per_app.py +0 -203
  75. openapi_fal_rest/api/usage/get_usage_records.py +0 -253
  76. openapi_fal_rest/api/usage/per_machine_usage.py +0 -218
  77. openapi_fal_rest/api/usage/per_machine_usage_details.py +0 -173
  78. openapi_fal_rest/api/users/__init__.py +0 -0
  79. openapi_fal_rest/api/users/handle_user_registration.py +0 -228
  80. openapi_fal_rest/models/billing_type.py +0 -9
  81. openapi_fal_rest/models/body_create_token.py +0 -68
  82. openapi_fal_rest/models/body_upload_file.py +0 -75
  83. openapi_fal_rest/models/file_spec.py +0 -110
  84. openapi_fal_rest/models/gateway_stats_by_time.py +0 -115
  85. openapi_fal_rest/models/gateway_usage_stats.py +0 -147
  86. openapi_fal_rest/models/get_gateway_request_stats_by_time_response_get_gateway_request_stats_by_time.py +0 -70
  87. openapi_fal_rest/models/grouped_usage_detail.py +0 -85
  88. openapi_fal_rest/models/handle_stripe_webhook_response_handle_stripe_webhook.py +0 -43
  89. openapi_fal_rest/models/initiate_upload_info.py +0 -64
  90. openapi_fal_rest/models/invoice.py +0 -129
  91. openapi_fal_rest/models/invoice_item.py +0 -85
  92. openapi_fal_rest/models/key_scope.py +0 -9
  93. openapi_fal_rest/models/log_entry.py +0 -104
  94. openapi_fal_rest/models/log_entry_labels.py +0 -43
  95. openapi_fal_rest/models/new_user_key.py +0 -64
  96. openapi_fal_rest/models/payment_method.py +0 -96
  97. openapi_fal_rest/models/per_app_usage_detail.py +0 -88
  98. openapi_fal_rest/models/persisted_usage_record.py +0 -118
  99. openapi_fal_rest/models/persisted_usage_record_meta.py +0 -43
  100. openapi_fal_rest/models/presigned_upload_url.py +0 -64
  101. openapi_fal_rest/models/request_io.py +0 -112
  102. openapi_fal_rest/models/request_io_json_input.py +0 -43
  103. openapi_fal_rest/models/request_io_json_output.py +0 -43
  104. openapi_fal_rest/models/run_type.py +0 -9
  105. openapi_fal_rest/models/stats_timeframe.py +0 -12
  106. openapi_fal_rest/models/status.py +0 -82
  107. openapi_fal_rest/models/status_health.py +0 -10
  108. openapi_fal_rest/models/uploaded_file_result.py +0 -64
  109. openapi_fal_rest/models/url_file_upload.py +0 -57
  110. openapi_fal_rest/models/usage_per_machine_type.py +0 -115
  111. openapi_fal_rest/models/usage_per_user.py +0 -71
  112. openapi_fal_rest/models/usage_run_detail.py +0 -73
  113. openapi_fal_rest/models/user_key_info.py +0 -84
  114. /openapi_fal_rest/api/admin/__init__.py → /fal/py.typed +0 -0
  115. {fal-0.12.1.dist-info → fal-0.12.3.dist-info}/WHEEL +0 -0
  116. {fal-0.12.1.dist-info → fal-0.12.3.dist-info}/entry_points.txt +0 -0
@@ -1,203 +0,0 @@
1
- import datetime
2
- from http import HTTPStatus
3
- from typing import Any, Dict, List, Optional, Union
4
-
5
- import httpx
6
-
7
- from ... import errors
8
- from ...client import Client
9
- from ...models.grouped_usage_detail import GroupedUsageDetail
10
- from ...models.http_validation_error import HTTPValidationError
11
- from ...types import UNSET, Response, Unset
12
-
13
-
14
- def _get_kwargs(
15
- *,
16
- client: Client,
17
- start_date: Union[Unset, None, datetime.date] = UNSET,
18
- end_date: Union[Unset, None, datetime.date] = UNSET,
19
- ) -> Dict[str, Any]:
20
- url = "{}/usage/custom_usage_per_machine".format(client.base_url)
21
-
22
- headers: Dict[str, str] = client.get_headers()
23
- cookies: Dict[str, Any] = client.get_cookies()
24
-
25
- params: Dict[str, Any] = {}
26
- json_start_date: Union[Unset, None, str] = UNSET
27
- if not isinstance(start_date, Unset):
28
- json_start_date = start_date.isoformat() if start_date else None
29
-
30
- params["start_date"] = json_start_date
31
-
32
- json_end_date: Union[Unset, None, str] = UNSET
33
- if not isinstance(end_date, Unset):
34
- json_end_date = end_date.isoformat() if end_date else None
35
-
36
- params["end_date"] = json_end_date
37
-
38
- params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
39
-
40
- return {
41
- "method": "get",
42
- "url": url,
43
- "headers": headers,
44
- "cookies": cookies,
45
- "timeout": client.get_timeout(),
46
- "follow_redirects": client.follow_redirects,
47
- "params": params,
48
- }
49
-
50
-
51
- def _parse_response(
52
- *, client: Client, response: httpx.Response
53
- ) -> Optional[Union[HTTPValidationError, List["GroupedUsageDetail"]]]:
54
- if response.status_code == HTTPStatus.OK:
55
- response_200 = []
56
- _response_200 = response.json()
57
- for response_200_item_data in _response_200:
58
- response_200_item = GroupedUsageDetail.from_dict(response_200_item_data)
59
-
60
- response_200.append(response_200_item)
61
-
62
- return response_200
63
- if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
64
- response_422 = HTTPValidationError.from_dict(response.json())
65
-
66
- return response_422
67
- if client.raise_on_unexpected_status:
68
- raise errors.UnexpectedStatus(response.status_code, response.content)
69
- else:
70
- return None
71
-
72
-
73
- def _build_response(
74
- *, client: Client, response: httpx.Response
75
- ) -> Response[Union[HTTPValidationError, List["GroupedUsageDetail"]]]:
76
- return Response(
77
- status_code=HTTPStatus(response.status_code),
78
- content=response.content,
79
- headers=response.headers,
80
- parsed=_parse_response(client=client, response=response),
81
- )
82
-
83
-
84
- def sync_detailed(
85
- *,
86
- client: Client,
87
- start_date: Union[Unset, None, datetime.date] = UNSET,
88
- end_date: Union[Unset, None, datetime.date] = UNSET,
89
- ) -> Response[Union[HTTPValidationError, List["GroupedUsageDetail"]]]:
90
- """Get Custom Usage Per Machine
91
-
92
- Args:
93
- start_date (Union[Unset, None, datetime.date]):
94
- end_date (Union[Unset, None, datetime.date]):
95
-
96
- Raises:
97
- errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
98
- httpx.TimeoutException: If the request takes longer than Client.timeout.
99
-
100
- Returns:
101
- Response[Union[HTTPValidationError, List['GroupedUsageDetail']]]
102
- """
103
-
104
- kwargs = _get_kwargs(
105
- client=client,
106
- start_date=start_date,
107
- end_date=end_date,
108
- )
109
-
110
- response = httpx.request(
111
- verify=client.verify_ssl,
112
- **kwargs,
113
- )
114
-
115
- return _build_response(client=client, response=response)
116
-
117
-
118
- def sync(
119
- *,
120
- client: Client,
121
- start_date: Union[Unset, None, datetime.date] = UNSET,
122
- end_date: Union[Unset, None, datetime.date] = UNSET,
123
- ) -> Optional[Union[HTTPValidationError, List["GroupedUsageDetail"]]]:
124
- """Get Custom Usage Per Machine
125
-
126
- Args:
127
- start_date (Union[Unset, None, datetime.date]):
128
- end_date (Union[Unset, None, datetime.date]):
129
-
130
- Raises:
131
- errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
132
- httpx.TimeoutException: If the request takes longer than Client.timeout.
133
-
134
- Returns:
135
- Union[HTTPValidationError, List['GroupedUsageDetail']]
136
- """
137
-
138
- return sync_detailed(
139
- client=client,
140
- start_date=start_date,
141
- end_date=end_date,
142
- ).parsed
143
-
144
-
145
- async def asyncio_detailed(
146
- *,
147
- client: Client,
148
- start_date: Union[Unset, None, datetime.date] = UNSET,
149
- end_date: Union[Unset, None, datetime.date] = UNSET,
150
- ) -> Response[Union[HTTPValidationError, List["GroupedUsageDetail"]]]:
151
- """Get Custom Usage Per Machine
152
-
153
- Args:
154
- start_date (Union[Unset, None, datetime.date]):
155
- end_date (Union[Unset, None, datetime.date]):
156
-
157
- Raises:
158
- errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
159
- httpx.TimeoutException: If the request takes longer than Client.timeout.
160
-
161
- Returns:
162
- Response[Union[HTTPValidationError, List['GroupedUsageDetail']]]
163
- """
164
-
165
- kwargs = _get_kwargs(
166
- client=client,
167
- start_date=start_date,
168
- end_date=end_date,
169
- )
170
-
171
- async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
172
- response = await _client.request(**kwargs)
173
-
174
- return _build_response(client=client, response=response)
175
-
176
-
177
- async def asyncio(
178
- *,
179
- client: Client,
180
- start_date: Union[Unset, None, datetime.date] = UNSET,
181
- end_date: Union[Unset, None, datetime.date] = UNSET,
182
- ) -> Optional[Union[HTTPValidationError, List["GroupedUsageDetail"]]]:
183
- """Get Custom Usage Per Machine
184
-
185
- Args:
186
- start_date (Union[Unset, None, datetime.date]):
187
- end_date (Union[Unset, None, datetime.date]):
188
-
189
- Raises:
190
- errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
191
- httpx.TimeoutException: If the request takes longer than Client.timeout.
192
-
193
- Returns:
194
- Union[HTTPValidationError, List['GroupedUsageDetail']]
195
- """
196
-
197
- return (
198
- await asyncio_detailed(
199
- client=client,
200
- start_date=start_date,
201
- end_date=end_date,
202
- )
203
- ).parsed
@@ -1,247 +0,0 @@
1
- import datetime
2
- from http import HTTPStatus
3
- from typing import Any, Dict, List, Optional, Union
4
-
5
- import httpx
6
-
7
- from ... import errors
8
- from ...client import Client
9
- from ...models.gateway_usage_stats import GatewayUsageStats
10
- from ...models.http_validation_error import HTTPValidationError
11
- from ...models.stats_timeframe import StatsTimeframe
12
- from ...types import UNSET, Response, Unset
13
-
14
-
15
- def _get_kwargs(
16
- *,
17
- client: Client,
18
- start_time: datetime.datetime,
19
- end_time: datetime.datetime,
20
- timeframe: StatsTimeframe,
21
- get_stats_by_time: Union[Unset, None, bool] = True,
22
- app_alias: Union[Unset, None, str] = UNSET,
23
- ) -> Dict[str, Any]:
24
- url = "{}/usage/stats/app".format(client.base_url)
25
-
26
- headers: Dict[str, str] = client.get_headers()
27
- cookies: Dict[str, Any] = client.get_cookies()
28
-
29
- params: Dict[str, Any] = {}
30
- json_start_time = start_time.isoformat()
31
-
32
- params["start_time"] = json_start_time
33
-
34
- json_end_time = end_time.isoformat()
35
-
36
- params["end_time"] = json_end_time
37
-
38
- json_timeframe = timeframe.value
39
-
40
- params["timeframe"] = json_timeframe
41
-
42
- params["get_stats_by_time"] = get_stats_by_time
43
-
44
- params["app_alias"] = app_alias
45
-
46
- params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
47
-
48
- return {
49
- "method": "get",
50
- "url": url,
51
- "headers": headers,
52
- "cookies": cookies,
53
- "timeout": client.get_timeout(),
54
- "follow_redirects": client.follow_redirects,
55
- "params": params,
56
- }
57
-
58
-
59
- def _parse_response(
60
- *, client: Client, response: httpx.Response
61
- ) -> Optional[Union[HTTPValidationError, List["GatewayUsageStats"]]]:
62
- if response.status_code == HTTPStatus.OK:
63
- response_200 = []
64
- _response_200 = response.json()
65
- for response_200_item_data in _response_200:
66
- response_200_item = GatewayUsageStats.from_dict(response_200_item_data)
67
-
68
- response_200.append(response_200_item)
69
-
70
- return response_200
71
- if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
72
- response_422 = HTTPValidationError.from_dict(response.json())
73
-
74
- return response_422
75
- if client.raise_on_unexpected_status:
76
- raise errors.UnexpectedStatus(response.status_code, response.content)
77
- else:
78
- return None
79
-
80
-
81
- def _build_response(
82
- *, client: Client, response: httpx.Response
83
- ) -> Response[Union[HTTPValidationError, List["GatewayUsageStats"]]]:
84
- return Response(
85
- status_code=HTTPStatus(response.status_code),
86
- content=response.content,
87
- headers=response.headers,
88
- parsed=_parse_response(client=client, response=response),
89
- )
90
-
91
-
92
- def sync_detailed(
93
- *,
94
- client: Client,
95
- start_time: datetime.datetime,
96
- end_time: datetime.datetime,
97
- timeframe: StatsTimeframe,
98
- get_stats_by_time: Union[Unset, None, bool] = True,
99
- app_alias: Union[Unset, None, str] = UNSET,
100
- ) -> Response[Union[HTTPValidationError, List["GatewayUsageStats"]]]:
101
- """Get Gateway Request Stats
102
-
103
- Args:
104
- start_time (datetime.datetime):
105
- end_time (datetime.datetime):
106
- timeframe (StatsTimeframe): An enumeration.
107
- get_stats_by_time (Union[Unset, None, bool]): Default: True.
108
- app_alias (Union[Unset, None, str]):
109
-
110
- Raises:
111
- errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
112
- httpx.TimeoutException: If the request takes longer than Client.timeout.
113
-
114
- Returns:
115
- Response[Union[HTTPValidationError, List['GatewayUsageStats']]]
116
- """
117
-
118
- kwargs = _get_kwargs(
119
- client=client,
120
- start_time=start_time,
121
- end_time=end_time,
122
- timeframe=timeframe,
123
- get_stats_by_time=get_stats_by_time,
124
- app_alias=app_alias,
125
- )
126
-
127
- response = httpx.request(
128
- verify=client.verify_ssl,
129
- **kwargs,
130
- )
131
-
132
- return _build_response(client=client, response=response)
133
-
134
-
135
- def sync(
136
- *,
137
- client: Client,
138
- start_time: datetime.datetime,
139
- end_time: datetime.datetime,
140
- timeframe: StatsTimeframe,
141
- get_stats_by_time: Union[Unset, None, bool] = True,
142
- app_alias: Union[Unset, None, str] = UNSET,
143
- ) -> Optional[Union[HTTPValidationError, List["GatewayUsageStats"]]]:
144
- """Get Gateway Request Stats
145
-
146
- Args:
147
- start_time (datetime.datetime):
148
- end_time (datetime.datetime):
149
- timeframe (StatsTimeframe): An enumeration.
150
- get_stats_by_time (Union[Unset, None, bool]): Default: True.
151
- app_alias (Union[Unset, None, str]):
152
-
153
- Raises:
154
- errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
155
- httpx.TimeoutException: If the request takes longer than Client.timeout.
156
-
157
- Returns:
158
- Union[HTTPValidationError, List['GatewayUsageStats']]
159
- """
160
-
161
- return sync_detailed(
162
- client=client,
163
- start_time=start_time,
164
- end_time=end_time,
165
- timeframe=timeframe,
166
- get_stats_by_time=get_stats_by_time,
167
- app_alias=app_alias,
168
- ).parsed
169
-
170
-
171
- async def asyncio_detailed(
172
- *,
173
- client: Client,
174
- start_time: datetime.datetime,
175
- end_time: datetime.datetime,
176
- timeframe: StatsTimeframe,
177
- get_stats_by_time: Union[Unset, None, bool] = True,
178
- app_alias: Union[Unset, None, str] = UNSET,
179
- ) -> Response[Union[HTTPValidationError, List["GatewayUsageStats"]]]:
180
- """Get Gateway Request Stats
181
-
182
- Args:
183
- start_time (datetime.datetime):
184
- end_time (datetime.datetime):
185
- timeframe (StatsTimeframe): An enumeration.
186
- get_stats_by_time (Union[Unset, None, bool]): Default: True.
187
- app_alias (Union[Unset, None, str]):
188
-
189
- Raises:
190
- errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
191
- httpx.TimeoutException: If the request takes longer than Client.timeout.
192
-
193
- Returns:
194
- Response[Union[HTTPValidationError, List['GatewayUsageStats']]]
195
- """
196
-
197
- kwargs = _get_kwargs(
198
- client=client,
199
- start_time=start_time,
200
- end_time=end_time,
201
- timeframe=timeframe,
202
- get_stats_by_time=get_stats_by_time,
203
- app_alias=app_alias,
204
- )
205
-
206
- async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
207
- response = await _client.request(**kwargs)
208
-
209
- return _build_response(client=client, response=response)
210
-
211
-
212
- async def asyncio(
213
- *,
214
- client: Client,
215
- start_time: datetime.datetime,
216
- end_time: datetime.datetime,
217
- timeframe: StatsTimeframe,
218
- get_stats_by_time: Union[Unset, None, bool] = True,
219
- app_alias: Union[Unset, None, str] = UNSET,
220
- ) -> Optional[Union[HTTPValidationError, List["GatewayUsageStats"]]]:
221
- """Get Gateway Request Stats
222
-
223
- Args:
224
- start_time (datetime.datetime):
225
- end_time (datetime.datetime):
226
- timeframe (StatsTimeframe): An enumeration.
227
- get_stats_by_time (Union[Unset, None, bool]): Default: True.
228
- app_alias (Union[Unset, None, str]):
229
-
230
- Raises:
231
- errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
232
- httpx.TimeoutException: If the request takes longer than Client.timeout.
233
-
234
- Returns:
235
- Union[HTTPValidationError, List['GatewayUsageStats']]
236
- """
237
-
238
- return (
239
- await asyncio_detailed(
240
- client=client,
241
- start_time=start_time,
242
- end_time=end_time,
243
- timeframe=timeframe,
244
- get_stats_by_time=get_stats_by_time,
245
- app_alias=app_alias,
246
- )
247
- ).parsed
@@ -1,236 +0,0 @@
1
- import datetime
2
- from http import HTTPStatus
3
- from typing import Any, Dict, List, Optional, Union
4
-
5
- import httpx
6
-
7
- from ... import errors
8
- from ...client import Client
9
- from ...models.get_gateway_request_stats_by_time_response_get_gateway_request_stats_by_time import (
10
- GetGatewayRequestStatsByTimeResponseGetGatewayRequestStatsByTime,
11
- )
12
- from ...models.http_validation_error import HTTPValidationError
13
- from ...models.stats_timeframe import StatsTimeframe
14
- from ...types import UNSET, Response, Unset
15
-
16
-
17
- def _get_kwargs(
18
- *,
19
- client: Client,
20
- start_time: datetime.datetime,
21
- end_time: datetime.datetime,
22
- timeframe: StatsTimeframe,
23
- app_aliases: Union[Unset, None, List[str]] = UNSET,
24
- ) -> Dict[str, Any]:
25
- url = "{}/usage/stats/app/time".format(client.base_url)
26
-
27
- headers: Dict[str, str] = client.get_headers()
28
- cookies: Dict[str, Any] = client.get_cookies()
29
-
30
- params: Dict[str, Any] = {}
31
- json_start_time = start_time.isoformat()
32
-
33
- params["start_time"] = json_start_time
34
-
35
- json_end_time = end_time.isoformat()
36
-
37
- params["end_time"] = json_end_time
38
-
39
- json_timeframe = timeframe.value
40
-
41
- params["timeframe"] = json_timeframe
42
-
43
- json_app_aliases: Union[Unset, None, List[str]] = UNSET
44
- if not isinstance(app_aliases, Unset):
45
- if app_aliases is None:
46
- json_app_aliases = None
47
- else:
48
- json_app_aliases = app_aliases
49
-
50
- params["app_aliases"] = json_app_aliases
51
-
52
- params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
53
-
54
- return {
55
- "method": "get",
56
- "url": url,
57
- "headers": headers,
58
- "cookies": cookies,
59
- "timeout": client.get_timeout(),
60
- "follow_redirects": client.follow_redirects,
61
- "params": params,
62
- }
63
-
64
-
65
- def _parse_response(
66
- *, client: Client, response: httpx.Response
67
- ) -> Optional[Union[GetGatewayRequestStatsByTimeResponseGetGatewayRequestStatsByTime, HTTPValidationError]]:
68
- if response.status_code == HTTPStatus.OK:
69
- response_200 = GetGatewayRequestStatsByTimeResponseGetGatewayRequestStatsByTime.from_dict(response.json())
70
-
71
- return response_200
72
- if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
73
- response_422 = HTTPValidationError.from_dict(response.json())
74
-
75
- return response_422
76
- if client.raise_on_unexpected_status:
77
- raise errors.UnexpectedStatus(response.status_code, response.content)
78
- else:
79
- return None
80
-
81
-
82
- def _build_response(
83
- *, client: Client, response: httpx.Response
84
- ) -> Response[Union[GetGatewayRequestStatsByTimeResponseGetGatewayRequestStatsByTime, HTTPValidationError]]:
85
- return Response(
86
- status_code=HTTPStatus(response.status_code),
87
- content=response.content,
88
- headers=response.headers,
89
- parsed=_parse_response(client=client, response=response),
90
- )
91
-
92
-
93
- def sync_detailed(
94
- *,
95
- client: Client,
96
- start_time: datetime.datetime,
97
- end_time: datetime.datetime,
98
- timeframe: StatsTimeframe,
99
- app_aliases: Union[Unset, None, List[str]] = UNSET,
100
- ) -> Response[Union[GetGatewayRequestStatsByTimeResponseGetGatewayRequestStatsByTime, HTTPValidationError]]:
101
- """Get Gateway Request Stats By Time
102
-
103
- Args:
104
- start_time (datetime.datetime):
105
- end_time (datetime.datetime):
106
- timeframe (StatsTimeframe): An enumeration.
107
- app_aliases (Union[Unset, None, List[str]]):
108
-
109
- Raises:
110
- errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
111
- httpx.TimeoutException: If the request takes longer than Client.timeout.
112
-
113
- Returns:
114
- Response[Union[GetGatewayRequestStatsByTimeResponseGetGatewayRequestStatsByTime, HTTPValidationError]]
115
- """
116
-
117
- kwargs = _get_kwargs(
118
- client=client,
119
- start_time=start_time,
120
- end_time=end_time,
121
- timeframe=timeframe,
122
- app_aliases=app_aliases,
123
- )
124
-
125
- response = httpx.request(
126
- verify=client.verify_ssl,
127
- **kwargs,
128
- )
129
-
130
- return _build_response(client=client, response=response)
131
-
132
-
133
- def sync(
134
- *,
135
- client: Client,
136
- start_time: datetime.datetime,
137
- end_time: datetime.datetime,
138
- timeframe: StatsTimeframe,
139
- app_aliases: Union[Unset, None, List[str]] = UNSET,
140
- ) -> Optional[Union[GetGatewayRequestStatsByTimeResponseGetGatewayRequestStatsByTime, HTTPValidationError]]:
141
- """Get Gateway Request Stats By Time
142
-
143
- Args:
144
- start_time (datetime.datetime):
145
- end_time (datetime.datetime):
146
- timeframe (StatsTimeframe): An enumeration.
147
- app_aliases (Union[Unset, None, List[str]]):
148
-
149
- Raises:
150
- errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
151
- httpx.TimeoutException: If the request takes longer than Client.timeout.
152
-
153
- Returns:
154
- Union[GetGatewayRequestStatsByTimeResponseGetGatewayRequestStatsByTime, HTTPValidationError]
155
- """
156
-
157
- return sync_detailed(
158
- client=client,
159
- start_time=start_time,
160
- end_time=end_time,
161
- timeframe=timeframe,
162
- app_aliases=app_aliases,
163
- ).parsed
164
-
165
-
166
- async def asyncio_detailed(
167
- *,
168
- client: Client,
169
- start_time: datetime.datetime,
170
- end_time: datetime.datetime,
171
- timeframe: StatsTimeframe,
172
- app_aliases: Union[Unset, None, List[str]] = UNSET,
173
- ) -> Response[Union[GetGatewayRequestStatsByTimeResponseGetGatewayRequestStatsByTime, HTTPValidationError]]:
174
- """Get Gateway Request Stats By Time
175
-
176
- Args:
177
- start_time (datetime.datetime):
178
- end_time (datetime.datetime):
179
- timeframe (StatsTimeframe): An enumeration.
180
- app_aliases (Union[Unset, None, List[str]]):
181
-
182
- Raises:
183
- errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
184
- httpx.TimeoutException: If the request takes longer than Client.timeout.
185
-
186
- Returns:
187
- Response[Union[GetGatewayRequestStatsByTimeResponseGetGatewayRequestStatsByTime, HTTPValidationError]]
188
- """
189
-
190
- kwargs = _get_kwargs(
191
- client=client,
192
- start_time=start_time,
193
- end_time=end_time,
194
- timeframe=timeframe,
195
- app_aliases=app_aliases,
196
- )
197
-
198
- async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
199
- response = await _client.request(**kwargs)
200
-
201
- return _build_response(client=client, response=response)
202
-
203
-
204
- async def asyncio(
205
- *,
206
- client: Client,
207
- start_time: datetime.datetime,
208
- end_time: datetime.datetime,
209
- timeframe: StatsTimeframe,
210
- app_aliases: Union[Unset, None, List[str]] = UNSET,
211
- ) -> Optional[Union[GetGatewayRequestStatsByTimeResponseGetGatewayRequestStatsByTime, HTTPValidationError]]:
212
- """Get Gateway Request Stats By Time
213
-
214
- Args:
215
- start_time (datetime.datetime):
216
- end_time (datetime.datetime):
217
- timeframe (StatsTimeframe): An enumeration.
218
- app_aliases (Union[Unset, None, List[str]]):
219
-
220
- Raises:
221
- errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
222
- httpx.TimeoutException: If the request takes longer than Client.timeout.
223
-
224
- Returns:
225
- Union[GetGatewayRequestStatsByTimeResponseGetGatewayRequestStatsByTime, HTTPValidationError]
226
- """
227
-
228
- return (
229
- await asyncio_detailed(
230
- client=client,
231
- start_time=start_time,
232
- end_time=end_time,
233
- timeframe=timeframe,
234
- app_aliases=app_aliases,
235
- )
236
- ).parsed