latitudesh-python-sdk 0.0.6__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 latitudesh-python-sdk might be problematic. Click here for more details.

Files changed (206) hide show
  1. latitudesh_python_sdk/__init__.py +18 -0
  2. latitudesh_python_sdk/_hooks/__init__.py +5 -0
  3. latitudesh_python_sdk/_hooks/registration.py +13 -0
  4. latitudesh_python_sdk/_hooks/sdkhooks.py +76 -0
  5. latitudesh_python_sdk/_hooks/types.py +106 -0
  6. latitudesh_python_sdk/_version.py +15 -0
  7. latitudesh_python_sdk/apikeys.py +802 -0
  8. latitudesh_python_sdk/basesdk.py +366 -0
  9. latitudesh_python_sdk/billing.py +210 -0
  10. latitudesh_python_sdk/events_sdk.py +240 -0
  11. latitudesh_python_sdk/firewalls_sdk.py +1640 -0
  12. latitudesh_python_sdk/httpclient.py +136 -0
  13. latitudesh_python_sdk/ipaddresses_sdk.py +448 -0
  14. latitudesh_python_sdk/models/__init__.py +1927 -0
  15. latitudesh_python_sdk/models/api_key.py +81 -0
  16. latitudesh_python_sdk/models/apierror.py +22 -0
  17. latitudesh_python_sdk/models/assign_server_virtual_networkop.py +43 -0
  18. latitudesh_python_sdk/models/bandwidth_packages.py +67 -0
  19. latitudesh_python_sdk/models/bandwidth_plan.py +72 -0
  20. latitudesh_python_sdk/models/bandwidth_plans.py +15 -0
  21. latitudesh_python_sdk/models/billing_usage.py +158 -0
  22. latitudesh_python_sdk/models/create_api_key.py +40 -0
  23. latitudesh_python_sdk/models/create_firewall_assignmentop.py +61 -0
  24. latitudesh_python_sdk/models/create_firewallop.py +69 -0
  25. latitudesh_python_sdk/models/create_ipmi_sessionop.py +16 -0
  26. latitudesh_python_sdk/models/create_projectop.py +79 -0
  27. latitudesh_python_sdk/models/create_server_actionop.py +69 -0
  28. latitudesh_python_sdk/models/create_server_out_of_bandop.py +61 -0
  29. latitudesh_python_sdk/models/create_server_reinstallop.py +140 -0
  30. latitudesh_python_sdk/models/create_serverop.py +173 -0
  31. latitudesh_python_sdk/models/create_tagop.py +50 -0
  32. latitudesh_python_sdk/models/create_virtual_networkop.py +72 -0
  33. latitudesh_python_sdk/models/custom_tag.py +54 -0
  34. latitudesh_python_sdk/models/delete_api_keyop.py +16 -0
  35. latitudesh_python_sdk/models/delete_firewall_assignmentop.py +25 -0
  36. latitudesh_python_sdk/models/delete_firewallop.py +18 -0
  37. latitudesh_python_sdk/models/delete_project_ssh_keyop.py +23 -0
  38. latitudesh_python_sdk/models/delete_project_user_dataop.py +23 -0
  39. latitudesh_python_sdk/models/delete_projectop.py +18 -0
  40. latitudesh_python_sdk/models/delete_storage_filesystemsop.py +16 -0
  41. latitudesh_python_sdk/models/delete_virtual_networks_assignmentsop.py +16 -0
  42. latitudesh_python_sdk/models/delete_vpn_sessionop.py +16 -0
  43. latitudesh_python_sdk/models/deploy_config.py +74 -0
  44. latitudesh_python_sdk/models/destroy_serverop.py +31 -0
  45. latitudesh_python_sdk/models/destroy_tagop.py +16 -0
  46. latitudesh_python_sdk/models/destroy_team_memberop.py +18 -0
  47. latitudesh_python_sdk/models/destroy_virtual_machineop.py +16 -0
  48. latitudesh_python_sdk/models/destroy_virtual_networkop.py +18 -0
  49. latitudesh_python_sdk/models/error_object.py +49 -0
  50. latitudesh_python_sdk/models/events.py +90 -0
  51. latitudesh_python_sdk/models/filesystem_data.py +53 -0
  52. latitudesh_python_sdk/models/firewall.py +71 -0
  53. latitudesh_python_sdk/models/firewall_server.py +50 -0
  54. latitudesh_python_sdk/models/firewalls.py +26 -0
  55. latitudesh_python_sdk/models/get_bandwidth_plansop.py +33 -0
  56. latitudesh_python_sdk/models/get_billing_usageop.py +46 -0
  57. latitudesh_python_sdk/models/get_eventsop.py +98 -0
  58. latitudesh_python_sdk/models/get_firewall_assignmentsop.py +18 -0
  59. latitudesh_python_sdk/models/get_firewallop.py +18 -0
  60. latitudesh_python_sdk/models/get_ipop.py +33 -0
  61. latitudesh_python_sdk/models/get_ipsop.py +91 -0
  62. latitudesh_python_sdk/models/get_planop.py +16 -0
  63. latitudesh_python_sdk/models/get_plans_operating_systemop.py +19 -0
  64. latitudesh_python_sdk/models/get_plansop.py +125 -0
  65. latitudesh_python_sdk/models/get_project_ssh_keyop.py +37 -0
  66. latitudesh_python_sdk/models/get_project_ssh_keysop.py +33 -0
  67. latitudesh_python_sdk/models/get_project_user_dataop.py +38 -0
  68. latitudesh_python_sdk/models/get_project_users_dataop.py +46 -0
  69. latitudesh_python_sdk/models/get_projectsop.py +76 -0
  70. latitudesh_python_sdk/models/get_regionop.py +18 -0
  71. latitudesh_python_sdk/models/get_role_idop.py +16 -0
  72. latitudesh_python_sdk/models/get_rolesop.py +19 -0
  73. latitudesh_python_sdk/models/get_server_deploy_configop.py +18 -0
  74. latitudesh_python_sdk/models/get_server_out_of_bandop.py +18 -0
  75. latitudesh_python_sdk/models/get_serverop.py +33 -0
  76. latitudesh_python_sdk/models/get_serversop.py +156 -0
  77. latitudesh_python_sdk/models/get_storage_filesystemsop.py +22 -0
  78. latitudesh_python_sdk/models/get_traffic_consumptionop.py +45 -0
  79. latitudesh_python_sdk/models/get_traffic_quotaop.py +20 -0
  80. latitudesh_python_sdk/models/get_user_profileop.py +19 -0
  81. latitudesh_python_sdk/models/get_virtual_networkop.py +32 -0
  82. latitudesh_python_sdk/models/get_virtual_networks_assignmentsop.py +40 -0
  83. latitudesh_python_sdk/models/get_virtual_networksop.py +40 -0
  84. latitudesh_python_sdk/models/get_vpn_sessionsop.py +70 -0
  85. latitudesh_python_sdk/models/index_virtual_machineop.py +22 -0
  86. latitudesh_python_sdk/models/ip_address.py +122 -0
  87. latitudesh_python_sdk/models/ip_addresses.py +15 -0
  88. latitudesh_python_sdk/models/ipmi_session.py +53 -0
  89. latitudesh_python_sdk/models/list_firewallsop.py +20 -0
  90. latitudesh_python_sdk/models/membership.py +63 -0
  91. latitudesh_python_sdk/models/operating_systems.py +57 -0
  92. latitudesh_python_sdk/models/out_of_band_connection.py +88 -0
  93. latitudesh_python_sdk/models/patch_current_teamop.py +91 -0
  94. latitudesh_python_sdk/models/patch_storage_filesystemsop.py +79 -0
  95. latitudesh_python_sdk/models/patch_user_profileop.py +88 -0
  96. latitudesh_python_sdk/models/plan.py +15 -0
  97. latitudesh_python_sdk/models/plan_data.py +206 -0
  98. latitudesh_python_sdk/models/post_api_keyop.py +19 -0
  99. latitudesh_python_sdk/models/post_project_ssh_keyop.py +81 -0
  100. latitudesh_python_sdk/models/post_project_user_dataop.py +68 -0
  101. latitudesh_python_sdk/models/post_storage_filesystemsop.py +63 -0
  102. latitudesh_python_sdk/models/post_team_membersop.py +54 -0
  103. latitudesh_python_sdk/models/post_teamop.py +67 -0
  104. latitudesh_python_sdk/models/post_vpn_sessionop.py +63 -0
  105. latitudesh_python_sdk/models/project.py +130 -0
  106. latitudesh_python_sdk/models/project_include.py +72 -0
  107. latitudesh_python_sdk/models/projects.py +15 -0
  108. latitudesh_python_sdk/models/put_project_ssh_keyop.py +87 -0
  109. latitudesh_python_sdk/models/put_project_user_dataop.py +76 -0
  110. latitudesh_python_sdk/models/put_vpn_sessionop.py +16 -0
  111. latitudesh_python_sdk/models/region.py +50 -0
  112. latitudesh_python_sdk/models/region_resource_data.py +37 -0
  113. latitudesh_python_sdk/models/regions.py +50 -0
  114. latitudesh_python_sdk/models/role.py +15 -0
  115. latitudesh_python_sdk/models/role_data.py +35 -0
  116. latitudesh_python_sdk/models/security.py +25 -0
  117. latitudesh_python_sdk/models/server.py +54 -0
  118. latitudesh_python_sdk/models/server_action.py +52 -0
  119. latitudesh_python_sdk/models/server_data.py +219 -0
  120. latitudesh_python_sdk/models/server_exit_rescue_modeop.py +16 -0
  121. latitudesh_python_sdk/models/server_lockop.py +16 -0
  122. latitudesh_python_sdk/models/server_rescue.py +22 -0
  123. latitudesh_python_sdk/models/server_schedule_deletion.py +44 -0
  124. latitudesh_python_sdk/models/server_schedule_deletionop.py +16 -0
  125. latitudesh_python_sdk/models/server_start_rescue_modeop.py +16 -0
  126. latitudesh_python_sdk/models/server_unlockop.py +16 -0
  127. latitudesh_python_sdk/models/server_unschedule_deletionop.py +16 -0
  128. latitudesh_python_sdk/models/servers.py +26 -0
  129. latitudesh_python_sdk/models/show_virtual_machineop.py +16 -0
  130. latitudesh_python_sdk/models/ssh_key.py +15 -0
  131. latitudesh_python_sdk/models/ssh_key_data.py +55 -0
  132. latitudesh_python_sdk/models/storage_plan.py +36 -0
  133. latitudesh_python_sdk/models/storage_plans.py +15 -0
  134. latitudesh_python_sdk/models/team.py +74 -0
  135. latitudesh_python_sdk/models/team_include.py +43 -0
  136. latitudesh_python_sdk/models/team_members.py +51 -0
  137. latitudesh_python_sdk/models/teams.py +26 -0
  138. latitudesh_python_sdk/models/traffic.py +133 -0
  139. latitudesh_python_sdk/models/traffic_quota.py +106 -0
  140. latitudesh_python_sdk/models/update_api_key.py +48 -0
  141. latitudesh_python_sdk/models/update_api_keyop.py +41 -0
  142. latitudesh_python_sdk/models/update_firewallop.py +89 -0
  143. latitudesh_python_sdk/models/update_plans_bandwidthop.py +50 -0
  144. latitudesh_python_sdk/models/update_projectop.py +95 -0
  145. latitudesh_python_sdk/models/update_server_deploy_configop.py +122 -0
  146. latitudesh_python_sdk/models/update_serverop.py +69 -0
  147. latitudesh_python_sdk/models/update_tagop.py +74 -0
  148. latitudesh_python_sdk/models/update_virtual_networkop.py +67 -0
  149. latitudesh_python_sdk/models/user.py +59 -0
  150. latitudesh_python_sdk/models/user_data.py +15 -0
  151. latitudesh_python_sdk/models/user_data_properties.py +46 -0
  152. latitudesh_python_sdk/models/user_include.py +52 -0
  153. latitudesh_python_sdk/models/user_team.py +61 -0
  154. latitudesh_python_sdk/models/user_teams.py +26 -0
  155. latitudesh_python_sdk/models/user_update.py +37 -0
  156. latitudesh_python_sdk/models/virtual_machine.py +25 -0
  157. latitudesh_python_sdk/models/virtual_machine_payload.py +41 -0
  158. latitudesh_python_sdk/models/virtual_machine_plans.py +180 -0
  159. latitudesh_python_sdk/models/virtual_network.py +103 -0
  160. latitudesh_python_sdk/models/virtual_network1.py +84 -0
  161. latitudesh_python_sdk/models/virtual_network_assignment.py +37 -0
  162. latitudesh_python_sdk/models/virtual_network_assignments.py +29 -0
  163. latitudesh_python_sdk/models/virtual_networks.py +26 -0
  164. latitudesh_python_sdk/models/vpn_session_data_with_password.py +77 -0
  165. latitudesh_python_sdk/models/vpn_session_with_password.py +18 -0
  166. latitudesh_python_sdk/operatingsystems_sdk.py +188 -0
  167. latitudesh_python_sdk/plans.py +1178 -0
  168. latitudesh_python_sdk/privatenetworks.py +1672 -0
  169. latitudesh_python_sdk/projects_sdk.py +864 -0
  170. latitudesh_python_sdk/py.typed +1 -0
  171. latitudesh_python_sdk/regions_sdk.py +376 -0
  172. latitudesh_python_sdk/roles.py +374 -0
  173. latitudesh_python_sdk/sdk.py +214 -0
  174. latitudesh_python_sdk/sdkconfiguration.py +57 -0
  175. latitudesh_python_sdk/servers_sdk.py +3810 -0
  176. latitudesh_python_sdk/sshkeys.py +1050 -0
  177. latitudesh_python_sdk/storage.py +820 -0
  178. latitudesh_python_sdk/tags.py +786 -0
  179. latitudesh_python_sdk/teams_sdk.py +596 -0
  180. latitudesh_python_sdk/teamsmembers.py +578 -0
  181. latitudesh_python_sdk/traffic_sdk.py +400 -0
  182. latitudesh_python_sdk/types/__init__.py +21 -0
  183. latitudesh_python_sdk/types/basemodel.py +39 -0
  184. latitudesh_python_sdk/userdata_sdk.py +1052 -0
  185. latitudesh_python_sdk/userprofile.py +596 -0
  186. latitudesh_python_sdk/utils/__init__.py +101 -0
  187. latitudesh_python_sdk/utils/annotations.py +55 -0
  188. latitudesh_python_sdk/utils/enums.py +34 -0
  189. latitudesh_python_sdk/utils/eventstreaming.py +238 -0
  190. latitudesh_python_sdk/utils/forms.py +202 -0
  191. latitudesh_python_sdk/utils/headers.py +136 -0
  192. latitudesh_python_sdk/utils/logger.py +27 -0
  193. latitudesh_python_sdk/utils/metadata.py +118 -0
  194. latitudesh_python_sdk/utils/queryparams.py +205 -0
  195. latitudesh_python_sdk/utils/requestbodies.py +66 -0
  196. latitudesh_python_sdk/utils/retries.py +217 -0
  197. latitudesh_python_sdk/utils/security.py +192 -0
  198. latitudesh_python_sdk/utils/serializers.py +219 -0
  199. latitudesh_python_sdk/utils/url.py +155 -0
  200. latitudesh_python_sdk/utils/values.py +137 -0
  201. latitudesh_python_sdk/virtualmachines.py +772 -0
  202. latitudesh_python_sdk/vpnsessions.py +818 -0
  203. latitudesh_python_sdk-0.0.6.dist-info/LICENSE +21 -0
  204. latitudesh_python_sdk-0.0.6.dist-info/METADATA +730 -0
  205. latitudesh_python_sdk-0.0.6.dist-info/RECORD +206 -0
  206. latitudesh_python_sdk-0.0.6.dist-info/WHEEL +4 -0
@@ -0,0 +1,192 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ import base64
4
+
5
+ from typing import (
6
+ Any,
7
+ Dict,
8
+ List,
9
+ Optional,
10
+ Tuple,
11
+ )
12
+ from pydantic import BaseModel
13
+ from pydantic.fields import FieldInfo
14
+
15
+ from .metadata import (
16
+ SecurityMetadata,
17
+ find_field_metadata,
18
+ )
19
+ import os
20
+
21
+
22
+ def get_security(security: Any) -> Tuple[Dict[str, str], Dict[str, List[str]]]:
23
+ headers: Dict[str, str] = {}
24
+ query_params: Dict[str, List[str]] = {}
25
+
26
+ if security is None:
27
+ return headers, query_params
28
+
29
+ if not isinstance(security, BaseModel):
30
+ raise TypeError("security must be a pydantic model")
31
+
32
+ sec_fields: Dict[str, FieldInfo] = security.__class__.model_fields
33
+ for name in sec_fields:
34
+ sec_field = sec_fields[name]
35
+
36
+ value = getattr(security, name)
37
+ if value is None:
38
+ continue
39
+
40
+ metadata = find_field_metadata(sec_field, SecurityMetadata)
41
+ if metadata is None:
42
+ continue
43
+ if metadata.option:
44
+ _parse_security_option(headers, query_params, value)
45
+ return headers, query_params
46
+ if metadata.scheme:
47
+ # Special case for basic auth or custom auth which could be a flattened model
48
+ if metadata.sub_type in ["basic", "custom"] and not isinstance(
49
+ value, BaseModel
50
+ ):
51
+ _parse_security_scheme(headers, query_params, metadata, name, security)
52
+ else:
53
+ _parse_security_scheme(headers, query_params, metadata, name, value)
54
+
55
+ return headers, query_params
56
+
57
+
58
+ def get_security_from_env(security: Any, security_class: Any) -> Optional[BaseModel]:
59
+ if security is not None:
60
+ return security
61
+
62
+ if not issubclass(security_class, BaseModel):
63
+ raise TypeError("security_class must be a pydantic model class")
64
+
65
+ security_dict: Any = {}
66
+
67
+ if os.getenv("LATITUDESH_BEARER"):
68
+ security_dict["bearer"] = os.getenv("LATITUDESH_BEARER")
69
+
70
+ return security_class(**security_dict) if security_dict else None
71
+
72
+
73
+ def _parse_security_option(
74
+ headers: Dict[str, str], query_params: Dict[str, List[str]], option: Any
75
+ ):
76
+ if not isinstance(option, BaseModel):
77
+ raise TypeError("security option must be a pydantic model")
78
+
79
+ opt_fields: Dict[str, FieldInfo] = option.__class__.model_fields
80
+ for name in opt_fields:
81
+ opt_field = opt_fields[name]
82
+
83
+ metadata = find_field_metadata(opt_field, SecurityMetadata)
84
+ if metadata is None or not metadata.scheme:
85
+ continue
86
+ _parse_security_scheme(
87
+ headers, query_params, metadata, name, getattr(option, name)
88
+ )
89
+
90
+
91
+ def _parse_security_scheme(
92
+ headers: Dict[str, str],
93
+ query_params: Dict[str, List[str]],
94
+ scheme_metadata: SecurityMetadata,
95
+ field_name: str,
96
+ scheme: Any,
97
+ ):
98
+ scheme_type = scheme_metadata.scheme_type
99
+ sub_type = scheme_metadata.sub_type
100
+
101
+ if isinstance(scheme, BaseModel):
102
+ if scheme_type == "http":
103
+ if sub_type == "basic":
104
+ _parse_basic_auth_scheme(headers, scheme)
105
+ return
106
+ if sub_type == "custom":
107
+ return
108
+
109
+ scheme_fields: Dict[str, FieldInfo] = scheme.__class__.model_fields
110
+ for name in scheme_fields:
111
+ scheme_field = scheme_fields[name]
112
+
113
+ metadata = find_field_metadata(scheme_field, SecurityMetadata)
114
+ if metadata is None or metadata.field_name is None:
115
+ continue
116
+
117
+ value = getattr(scheme, name)
118
+
119
+ _parse_security_scheme_value(
120
+ headers, query_params, scheme_metadata, metadata, name, value
121
+ )
122
+ else:
123
+ _parse_security_scheme_value(
124
+ headers, query_params, scheme_metadata, scheme_metadata, field_name, scheme
125
+ )
126
+
127
+
128
+ def _parse_security_scheme_value(
129
+ headers: Dict[str, str],
130
+ query_params: Dict[str, List[str]],
131
+ scheme_metadata: SecurityMetadata,
132
+ security_metadata: SecurityMetadata,
133
+ field_name: str,
134
+ value: Any,
135
+ ):
136
+ scheme_type = scheme_metadata.scheme_type
137
+ sub_type = scheme_metadata.sub_type
138
+
139
+ header_name = security_metadata.get_field_name(field_name)
140
+
141
+ if scheme_type == "apiKey":
142
+ if sub_type == "header":
143
+ headers[header_name] = value
144
+ elif sub_type == "query":
145
+ query_params[header_name] = [value]
146
+ else:
147
+ raise ValueError("sub type {sub_type} not supported")
148
+ elif scheme_type == "openIdConnect":
149
+ headers[header_name] = _apply_bearer(value)
150
+ elif scheme_type == "oauth2":
151
+ if sub_type != "client_credentials":
152
+ headers[header_name] = _apply_bearer(value)
153
+ elif scheme_type == "http":
154
+ if sub_type == "bearer":
155
+ headers[header_name] = _apply_bearer(value)
156
+ elif sub_type == "custom":
157
+ return
158
+ else:
159
+ raise ValueError("sub type {sub_type} not supported")
160
+ else:
161
+ raise ValueError("scheme type {scheme_type} not supported")
162
+
163
+
164
+ def _apply_bearer(token: str) -> str:
165
+ return token.lower().startswith("bearer ") and token or f"Bearer {token}"
166
+
167
+
168
+ def _parse_basic_auth_scheme(headers: Dict[str, str], scheme: Any):
169
+ username = ""
170
+ password = ""
171
+
172
+ if not isinstance(scheme, BaseModel):
173
+ raise TypeError("basic auth scheme must be a pydantic model")
174
+
175
+ scheme_fields: Dict[str, FieldInfo] = scheme.__class__.model_fields
176
+ for name in scheme_fields:
177
+ scheme_field = scheme_fields[name]
178
+
179
+ metadata = find_field_metadata(scheme_field, SecurityMetadata)
180
+ if metadata is None or metadata.field_name is None:
181
+ continue
182
+
183
+ field_name = metadata.field_name
184
+ value = getattr(scheme, name)
185
+
186
+ if field_name == "username":
187
+ username = value
188
+ if field_name == "password":
189
+ password = value
190
+
191
+ data = f"{username}:{password}".encode()
192
+ headers["Authorization"] = f"Basic {base64.b64encode(data).decode()}"
@@ -0,0 +1,219 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from decimal import Decimal
4
+ import json
5
+ from typing import Any, Dict, List, Union, get_args
6
+ import httpx
7
+ from typing_extensions import get_origin
8
+ from pydantic import ConfigDict, create_model
9
+ from pydantic_core import from_json
10
+ from typing_inspection.typing_objects import is_union
11
+
12
+ from ..types.basemodel import BaseModel, Nullable, OptionalNullable, Unset
13
+
14
+
15
+ def serialize_decimal(as_str: bool):
16
+ def serialize(d):
17
+ # Optional[T] is a Union[T, None]
18
+ if is_union(type(d)) and type(None) in get_args(type(d)) and d is None:
19
+ return None
20
+ if isinstance(d, Unset):
21
+ return d
22
+
23
+ if not isinstance(d, Decimal):
24
+ raise ValueError("Expected Decimal object")
25
+
26
+ return str(d) if as_str else float(d)
27
+
28
+ return serialize
29
+
30
+
31
+ def validate_decimal(d):
32
+ if d is None:
33
+ return None
34
+
35
+ if isinstance(d, (Decimal, Unset)):
36
+ return d
37
+
38
+ if not isinstance(d, (str, int, float)):
39
+ raise ValueError("Expected string, int or float")
40
+
41
+ return Decimal(str(d))
42
+
43
+
44
+ def serialize_float(as_str: bool):
45
+ def serialize(f):
46
+ # Optional[T] is a Union[T, None]
47
+ if is_union(type(f)) and type(None) in get_args(type(f)) and f is None:
48
+ return None
49
+ if isinstance(f, Unset):
50
+ return f
51
+
52
+ if not isinstance(f, float):
53
+ raise ValueError("Expected float")
54
+
55
+ return str(f) if as_str else f
56
+
57
+ return serialize
58
+
59
+
60
+ def validate_float(f):
61
+ if f is None:
62
+ return None
63
+
64
+ if isinstance(f, (float, Unset)):
65
+ return f
66
+
67
+ if not isinstance(f, str):
68
+ raise ValueError("Expected string")
69
+
70
+ return float(f)
71
+
72
+
73
+ def serialize_int(as_str: bool):
74
+ def serialize(i):
75
+ # Optional[T] is a Union[T, None]
76
+ if is_union(type(i)) and type(None) in get_args(type(i)) and i is None:
77
+ return None
78
+ if isinstance(i, Unset):
79
+ return i
80
+
81
+ if not isinstance(i, int):
82
+ raise ValueError("Expected int")
83
+
84
+ return str(i) if as_str else i
85
+
86
+ return serialize
87
+
88
+
89
+ def validate_int(b):
90
+ if b is None:
91
+ return None
92
+
93
+ if isinstance(b, (int, Unset)):
94
+ return b
95
+
96
+ if not isinstance(b, str):
97
+ raise ValueError("Expected string")
98
+
99
+ return int(b)
100
+
101
+
102
+ def validate_open_enum(is_int: bool):
103
+ def validate(e):
104
+ if e is None:
105
+ return None
106
+
107
+ if isinstance(e, Unset):
108
+ return e
109
+
110
+ if is_int:
111
+ if not isinstance(e, int):
112
+ raise ValueError("Expected int")
113
+ else:
114
+ if not isinstance(e, str):
115
+ raise ValueError("Expected string")
116
+
117
+ return e
118
+
119
+ return validate
120
+
121
+
122
+ def validate_const(v):
123
+ def validate(c):
124
+ # Optional[T] is a Union[T, None]
125
+ if is_union(type(c)) and type(None) in get_args(type(c)) and c is None:
126
+ return None
127
+
128
+ if v != c:
129
+ raise ValueError(f"Expected {v}")
130
+
131
+ return c
132
+
133
+ return validate
134
+
135
+
136
+ def unmarshal_json(raw, typ: Any) -> Any:
137
+ return unmarshal(from_json(raw), typ)
138
+
139
+
140
+ def unmarshal(val, typ: Any) -> Any:
141
+ unmarshaller = create_model(
142
+ "Unmarshaller",
143
+ body=(typ, ...),
144
+ __config__=ConfigDict(populate_by_name=True, arbitrary_types_allowed=True),
145
+ )
146
+
147
+ m = unmarshaller(body=val)
148
+
149
+ # pyright: ignore[reportAttributeAccessIssue]
150
+ return m.body # type: ignore
151
+
152
+
153
+ def marshal_json(val, typ):
154
+ if is_nullable(typ) and val is None:
155
+ return "null"
156
+
157
+ marshaller = create_model(
158
+ "Marshaller",
159
+ body=(typ, ...),
160
+ __config__=ConfigDict(populate_by_name=True, arbitrary_types_allowed=True),
161
+ )
162
+
163
+ m = marshaller(body=val)
164
+
165
+ d = m.model_dump(by_alias=True, mode="json", exclude_none=True)
166
+
167
+ if len(d) == 0:
168
+ return ""
169
+
170
+ return json.dumps(d[next(iter(d))], separators=(",", ":"))
171
+
172
+
173
+ def is_nullable(field):
174
+ origin = get_origin(field)
175
+ if origin is Nullable or origin is OptionalNullable:
176
+ return True
177
+
178
+ if not origin is Union or type(None) not in get_args(field):
179
+ return False
180
+
181
+ for arg in get_args(field):
182
+ if get_origin(arg) is Nullable or get_origin(arg) is OptionalNullable:
183
+ return True
184
+
185
+ return False
186
+
187
+
188
+ def stream_to_text(stream: httpx.Response) -> str:
189
+ return "".join(stream.iter_text())
190
+
191
+
192
+ async def stream_to_text_async(stream: httpx.Response) -> str:
193
+ return "".join([chunk async for chunk in stream.aiter_text()])
194
+
195
+
196
+ def stream_to_bytes(stream: httpx.Response) -> bytes:
197
+ return stream.content
198
+
199
+
200
+ async def stream_to_bytes_async(stream: httpx.Response) -> bytes:
201
+ return await stream.aread()
202
+
203
+
204
+ def get_pydantic_model(data: Any, typ: Any) -> Any:
205
+ if not _contains_pydantic_model(data):
206
+ return unmarshal(data, typ)
207
+
208
+ return data
209
+
210
+
211
+ def _contains_pydantic_model(data: Any) -> bool:
212
+ if isinstance(data, BaseModel):
213
+ return True
214
+ if isinstance(data, List):
215
+ return any(_contains_pydantic_model(item) for item in data)
216
+ if isinstance(data, Dict):
217
+ return any(_contains_pydantic_model(value) for value in data.values())
218
+
219
+ return False
@@ -0,0 +1,155 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from decimal import Decimal
4
+ from typing import (
5
+ Any,
6
+ Dict,
7
+ get_type_hints,
8
+ List,
9
+ Optional,
10
+ Union,
11
+ get_args,
12
+ get_origin,
13
+ )
14
+ from pydantic import BaseModel
15
+ from pydantic.fields import FieldInfo
16
+
17
+ from .metadata import (
18
+ PathParamMetadata,
19
+ find_field_metadata,
20
+ )
21
+ from .values import (
22
+ _get_serialized_params,
23
+ _is_set,
24
+ _populate_from_globals,
25
+ _val_to_string,
26
+ )
27
+
28
+
29
+ def generate_url(
30
+ server_url: str,
31
+ path: str,
32
+ path_params: Any,
33
+ gbls: Optional[Any] = None,
34
+ ) -> str:
35
+ path_param_values: Dict[str, str] = {}
36
+
37
+ globals_already_populated = _populate_path_params(
38
+ path_params, gbls, path_param_values, []
39
+ )
40
+ if _is_set(gbls):
41
+ _populate_path_params(gbls, None, path_param_values, globals_already_populated)
42
+
43
+ for key, value in path_param_values.items():
44
+ path = path.replace("{" + key + "}", value, 1)
45
+
46
+ return remove_suffix(server_url, "/") + path
47
+
48
+
49
+ def _populate_path_params(
50
+ path_params: Any,
51
+ gbls: Any,
52
+ path_param_values: Dict[str, str],
53
+ skip_fields: List[str],
54
+ ) -> List[str]:
55
+ globals_already_populated: List[str] = []
56
+
57
+ if not isinstance(path_params, BaseModel):
58
+ return globals_already_populated
59
+
60
+ path_param_fields: Dict[str, FieldInfo] = path_params.__class__.model_fields
61
+ path_param_field_types = get_type_hints(path_params.__class__)
62
+ for name in path_param_fields:
63
+ if name in skip_fields:
64
+ continue
65
+
66
+ field = path_param_fields[name]
67
+
68
+ param_metadata = find_field_metadata(field, PathParamMetadata)
69
+ if param_metadata is None:
70
+ continue
71
+
72
+ param = getattr(path_params, name) if _is_set(path_params) else None
73
+ param, global_found = _populate_from_globals(
74
+ name, param, PathParamMetadata, gbls
75
+ )
76
+ if global_found:
77
+ globals_already_populated.append(name)
78
+
79
+ if not _is_set(param):
80
+ continue
81
+
82
+ f_name = field.alias if field.alias is not None else name
83
+ serialization = param_metadata.serialization
84
+ if serialization is not None:
85
+ serialized_params = _get_serialized_params(
86
+ param_metadata, f_name, param, path_param_field_types[name]
87
+ )
88
+ for key, value in serialized_params.items():
89
+ path_param_values[key] = value
90
+ else:
91
+ pp_vals: List[str] = []
92
+ if param_metadata.style == "simple":
93
+ if isinstance(param, List):
94
+ for pp_val in param:
95
+ if not _is_set(pp_val):
96
+ continue
97
+ pp_vals.append(_val_to_string(pp_val))
98
+ path_param_values[f_name] = ",".join(pp_vals)
99
+ elif isinstance(param, Dict):
100
+ for pp_key in param:
101
+ if not _is_set(param[pp_key]):
102
+ continue
103
+ if param_metadata.explode:
104
+ pp_vals.append(f"{pp_key}={_val_to_string(param[pp_key])}")
105
+ else:
106
+ pp_vals.append(f"{pp_key},{_val_to_string(param[pp_key])}")
107
+ path_param_values[f_name] = ",".join(pp_vals)
108
+ elif not isinstance(param, (str, int, float, complex, bool, Decimal)):
109
+ param_fields: Dict[str, FieldInfo] = param.__class__.model_fields
110
+ for name in param_fields:
111
+ param_field = param_fields[name]
112
+
113
+ param_value_metadata = find_field_metadata(
114
+ param_field, PathParamMetadata
115
+ )
116
+ if param_value_metadata is None:
117
+ continue
118
+
119
+ param_name = (
120
+ param_field.alias if param_field.alias is not None else name
121
+ )
122
+
123
+ param_field_val = getattr(param, name)
124
+ if not _is_set(param_field_val):
125
+ continue
126
+ if param_metadata.explode:
127
+ pp_vals.append(
128
+ f"{param_name}={_val_to_string(param_field_val)}"
129
+ )
130
+ else:
131
+ pp_vals.append(
132
+ f"{param_name},{_val_to_string(param_field_val)}"
133
+ )
134
+ path_param_values[f_name] = ",".join(pp_vals)
135
+ elif _is_set(param):
136
+ path_param_values[f_name] = _val_to_string(param)
137
+
138
+ return globals_already_populated
139
+
140
+
141
+ def is_optional(field):
142
+ return get_origin(field) is Union and type(None) in get_args(field)
143
+
144
+
145
+ def template_url(url_with_params: str, params: Dict[str, str]) -> str:
146
+ for key, value in params.items():
147
+ url_with_params = url_with_params.replace("{" + key + "}", value)
148
+
149
+ return url_with_params
150
+
151
+
152
+ def remove_suffix(input_string, suffix):
153
+ if suffix and input_string.endswith(suffix):
154
+ return input_string[: -len(suffix)]
155
+ return input_string
@@ -0,0 +1,137 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from datetime import datetime
4
+ from enum import Enum
5
+ from email.message import Message
6
+ from functools import partial
7
+ import os
8
+ from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, Union, cast
9
+
10
+ from httpx import Response
11
+ from pydantic import BaseModel
12
+ from pydantic.fields import FieldInfo
13
+
14
+ from ..types.basemodel import Unset
15
+
16
+ from .serializers import marshal_json
17
+
18
+ from .metadata import ParamMetadata, find_field_metadata
19
+
20
+
21
+ def match_content_type(content_type: str, pattern: str) -> bool:
22
+ if pattern in (content_type, "*", "*/*"):
23
+ return True
24
+
25
+ msg = Message()
26
+ msg["content-type"] = content_type
27
+ media_type = msg.get_content_type()
28
+
29
+ if media_type == pattern:
30
+ return True
31
+
32
+ parts = media_type.split("/")
33
+ if len(parts) == 2:
34
+ if pattern in (f"{parts[0]}/*", f"*/{parts[1]}"):
35
+ return True
36
+
37
+ return False
38
+
39
+
40
+ def match_status_codes(status_codes: List[str], status_code: int) -> bool:
41
+ if "default" in status_codes:
42
+ return True
43
+
44
+ for code in status_codes:
45
+ if code == str(status_code):
46
+ return True
47
+
48
+ if code.endswith("XX") and code.startswith(str(status_code)[:1]):
49
+ return True
50
+ return False
51
+
52
+
53
+ T = TypeVar("T")
54
+
55
+ def cast_partial(typ):
56
+ return partial(cast, typ)
57
+
58
+ def get_global_from_env(
59
+ value: Optional[T], env_key: str, type_cast: Callable[[str], T]
60
+ ) -> Optional[T]:
61
+ if value is not None:
62
+ return value
63
+ env_value = os.getenv(env_key)
64
+ if env_value is not None:
65
+ try:
66
+ return type_cast(env_value)
67
+ except ValueError:
68
+ pass
69
+ return None
70
+
71
+
72
+ def match_response(
73
+ response: Response, code: Union[str, List[str]], content_type: str
74
+ ) -> bool:
75
+ codes = code if isinstance(code, list) else [code]
76
+ return match_status_codes(codes, response.status_code) and match_content_type(
77
+ response.headers.get("content-type", "application/octet-stream"), content_type
78
+ )
79
+
80
+
81
+ def _populate_from_globals(
82
+ param_name: str, value: Any, param_metadata_type: type, gbls: Any
83
+ ) -> Tuple[Any, bool]:
84
+ if gbls is None:
85
+ return value, False
86
+
87
+ if not isinstance(gbls, BaseModel):
88
+ raise TypeError("globals must be a pydantic model")
89
+
90
+ global_fields: Dict[str, FieldInfo] = gbls.__class__.model_fields
91
+ found = False
92
+ for name in global_fields:
93
+ field = global_fields[name]
94
+ if name is not param_name:
95
+ continue
96
+
97
+ found = True
98
+
99
+ if value is not None:
100
+ return value, True
101
+
102
+ global_value = getattr(gbls, name)
103
+
104
+ param_metadata = find_field_metadata(field, param_metadata_type)
105
+ if param_metadata is None:
106
+ return value, True
107
+
108
+ return global_value, True
109
+
110
+ return value, found
111
+
112
+
113
+ def _val_to_string(val) -> str:
114
+ if isinstance(val, bool):
115
+ return str(val).lower()
116
+ if isinstance(val, datetime):
117
+ return str(val.isoformat().replace("+00:00", "Z"))
118
+ if isinstance(val, Enum):
119
+ return str(val.value)
120
+
121
+ return str(val)
122
+
123
+
124
+ def _get_serialized_params(
125
+ metadata: ParamMetadata, field_name: str, obj: Any, typ: type
126
+ ) -> Dict[str, str]:
127
+ params: Dict[str, str] = {}
128
+
129
+ serialization = metadata.serialization
130
+ if serialization == "json":
131
+ params[field_name] = marshal_json(obj, typ)
132
+
133
+ return params
134
+
135
+
136
+ def _is_set(value: Any) -> bool:
137
+ return value is not None and not isinstance(value, Unset)