reflex-build-sdk 0.0.1__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.
- reflex_build_sdk/__init__.py +53 -0
- reflex_build_sdk/_async/__init__.py +1 -0
- reflex_build_sdk/_async/_client.py +228 -0
- reflex_build_sdk/_async/resources/__init__.py +1 -0
- reflex_build_sdk/_async/resources/apps.py +874 -0
- reflex_build_sdk/_async/resources/auth.py +247 -0
- reflex_build_sdk/_async/resources/connections.py +207 -0
- reflex_build_sdk/_async/resources/databases.py +101 -0
- reflex_build_sdk/_async/resources/deployments.py +410 -0
- reflex_build_sdk/_async/resources/environments.py +268 -0
- reflex_build_sdk/_async/resources/projects.py +533 -0
- reflex_build_sdk/_async/resources/providers.py +458 -0
- reflex_build_sdk/_async/resources/security_reviews.py +141 -0
- reflex_build_sdk/_async/resources/sign_in.py +293 -0
- reflex_build_sdk/_async/resources/usage.py +100 -0
- reflex_build_sdk/_base.py +331 -0
- reflex_build_sdk/_decode.py +395 -0
- reflex_build_sdk/_deploy.py +308 -0
- reflex_build_sdk/_errors.py +217 -0
- reflex_build_sdk/_sync/__init__.py +2 -0
- reflex_build_sdk/_sync/_client.py +229 -0
- reflex_build_sdk/_sync/resources/__init__.py +2 -0
- reflex_build_sdk/_sync/resources/apps.py +867 -0
- reflex_build_sdk/_sync/resources/auth.py +248 -0
- reflex_build_sdk/_sync/resources/connections.py +208 -0
- reflex_build_sdk/_sync/resources/databases.py +102 -0
- reflex_build_sdk/_sync/resources/deployments.py +411 -0
- reflex_build_sdk/_sync/resources/environments.py +267 -0
- reflex_build_sdk/_sync/resources/projects.py +526 -0
- reflex_build_sdk/_sync/resources/providers.py +455 -0
- reflex_build_sdk/_sync/resources/security_reviews.py +142 -0
- reflex_build_sdk/_sync/resources/sign_in.py +290 -0
- reflex_build_sdk/_sync/resources/usage.py +101 -0
- reflex_build_sdk/credentials.py +110 -0
- reflex_build_sdk/py.typed +0 -0
- reflex_build_sdk/transports/__init__.py +27 -0
- reflex_build_sdk/transports/_aiohttp.py +198 -0
- reflex_build_sdk/transports/_base.py +145 -0
- reflex_build_sdk/transports/_defaults.py +12 -0
- reflex_build_sdk/transports/_httpx.py +129 -0
- reflex_build_sdk/types.py +1048 -0
- reflex_build_sdk-0.0.1.dist-info/METADATA +245 -0
- reflex_build_sdk-0.0.1.dist-info/RECORD +44 -0
- reflex_build_sdk-0.0.1.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Python client for the Reflex Cloud API."""
|
|
2
|
+
|
|
3
|
+
from reflex_build_sdk._async._client import AsyncReflexCloud
|
|
4
|
+
from reflex_build_sdk._errors import (
|
|
5
|
+
APIConnectionError,
|
|
6
|
+
APIError,
|
|
7
|
+
APIResponseValidationError,
|
|
8
|
+
APIStatusError,
|
|
9
|
+
APITimeoutError,
|
|
10
|
+
AuthenticationError,
|
|
11
|
+
BadRequestError,
|
|
12
|
+
ConflictError,
|
|
13
|
+
DeploymentFailedError,
|
|
14
|
+
DeploymentTimeoutError,
|
|
15
|
+
InternalServerError,
|
|
16
|
+
LoginDeniedError,
|
|
17
|
+
LoginTimeoutError,
|
|
18
|
+
MissingTokenError,
|
|
19
|
+
NotFoundError,
|
|
20
|
+
PermissionDeniedError,
|
|
21
|
+
RateLimitError,
|
|
22
|
+
ReflexCloudError,
|
|
23
|
+
SecurityReviewFailedError,
|
|
24
|
+
SecurityReviewTimeoutError,
|
|
25
|
+
UnprocessableEntityError,
|
|
26
|
+
)
|
|
27
|
+
from reflex_build_sdk._sync._client import ReflexCloud
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"APIConnectionError",
|
|
31
|
+
"APIError",
|
|
32
|
+
"APIResponseValidationError",
|
|
33
|
+
"APIStatusError",
|
|
34
|
+
"APITimeoutError",
|
|
35
|
+
"AsyncReflexCloud",
|
|
36
|
+
"AuthenticationError",
|
|
37
|
+
"BadRequestError",
|
|
38
|
+
"ConflictError",
|
|
39
|
+
"DeploymentFailedError",
|
|
40
|
+
"DeploymentTimeoutError",
|
|
41
|
+
"InternalServerError",
|
|
42
|
+
"LoginDeniedError",
|
|
43
|
+
"LoginTimeoutError",
|
|
44
|
+
"MissingTokenError",
|
|
45
|
+
"NotFoundError",
|
|
46
|
+
"PermissionDeniedError",
|
|
47
|
+
"RateLimitError",
|
|
48
|
+
"ReflexCloud",
|
|
49
|
+
"ReflexCloudError",
|
|
50
|
+
"SecurityReviewFailedError",
|
|
51
|
+
"SecurityReviewTimeoutError",
|
|
52
|
+
"UnprocessableEntityError",
|
|
53
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""The asynchronous Reflex Cloud client."""
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"""The asynchronous Reflex Cloud client."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from collections.abc import Mapping
|
|
7
|
+
from types import TracebackType
|
|
8
|
+
from typing import Any, TypeVar, overload
|
|
9
|
+
|
|
10
|
+
from reflex_build_sdk._async.resources.apps import AsyncApps
|
|
11
|
+
from reflex_build_sdk._async.resources.auth import AsyncAuth
|
|
12
|
+
from reflex_build_sdk._async.resources.deployments import AsyncDeployments
|
|
13
|
+
from reflex_build_sdk._async.resources.projects import AsyncProjects
|
|
14
|
+
from reflex_build_sdk._async.resources.providers import AsyncProviders
|
|
15
|
+
from reflex_build_sdk._async.resources.security_reviews import AsyncSecurityReviews
|
|
16
|
+
from reflex_build_sdk._async.resources.usage import AsyncUsage
|
|
17
|
+
from reflex_build_sdk._base import (
|
|
18
|
+
DEFAULT_MAX_RETRIES,
|
|
19
|
+
BaseClient,
|
|
20
|
+
connection_error,
|
|
21
|
+
decode_response,
|
|
22
|
+
logger,
|
|
23
|
+
)
|
|
24
|
+
from reflex_build_sdk._errors import status_error_from_response
|
|
25
|
+
from reflex_build_sdk.transports._base import AsyncTransport, TransportError
|
|
26
|
+
from reflex_build_sdk.transports._defaults import AsyncDefaultTransport
|
|
27
|
+
|
|
28
|
+
T = TypeVar("T")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class AsyncReflexCloud(BaseClient):
|
|
32
|
+
"""Client for the Reflex Cloud API.
|
|
33
|
+
|
|
34
|
+
Use it as a context manager, or call ``aclose()``, to release its connections.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
# Manage apps, their lifecycle, deployment history, logs and secrets.
|
|
38
|
+
apps: AsyncApps
|
|
39
|
+
# The identity of the access token, and the token management endpoints.
|
|
40
|
+
auth: AsyncAuth
|
|
41
|
+
# Deploy apps and follow their deployments.
|
|
42
|
+
deployments: AsyncDeployments
|
|
43
|
+
# Manage projects and who has access to them.
|
|
44
|
+
projects: AsyncProjects
|
|
45
|
+
# Read the cloud providers an organization deploys apps to.
|
|
46
|
+
providers: AsyncProviders
|
|
47
|
+
# Review an app's source code for security and logic issues.
|
|
48
|
+
security_reviews: AsyncSecurityReviews
|
|
49
|
+
# Read an organization's use of its plan allowance.
|
|
50
|
+
usage: AsyncUsage
|
|
51
|
+
|
|
52
|
+
def __init__(
|
|
53
|
+
self,
|
|
54
|
+
*,
|
|
55
|
+
token: str | None = None,
|
|
56
|
+
base_url: str | None = None,
|
|
57
|
+
timeout: float | None = None,
|
|
58
|
+
max_retries: int = DEFAULT_MAX_RETRIES,
|
|
59
|
+
transport: AsyncTransport | None = None,
|
|
60
|
+
) -> None:
|
|
61
|
+
"""Create a client.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
token: The access token. Defaults to the ``REFLEX_ACCESS_TOKEN`` environment
|
|
65
|
+
variable, then to the token saved by ``reflex login``.
|
|
66
|
+
base_url: The Reflex Cloud URL. Defaults to the ``REFLEX_CLOUD_BACKEND_URL``
|
|
67
|
+
environment variable, then to ``https://build.reflex.dev``.
|
|
68
|
+
timeout: The timeout of each network operation (connecting, or any single
|
|
69
|
+
read or write), in seconds. Defaults to the transport's timeouts: 10
|
|
70
|
+
seconds to connect and 60 for a read or write for the transports the
|
|
71
|
+
SDK creates.
|
|
72
|
+
max_retries: How many times a failed request is retried. Only requests that
|
|
73
|
+
cannot be applied twice are retried: those the server never received or
|
|
74
|
+
turned away with 408 or 429, and requests that are harmless to repeat
|
|
75
|
+
(``GET``, ``HEAD``, ``OPTIONS`` and ``PUT`` requests, and calls such as
|
|
76
|
+
``apps.environments.update`` that settle on the same result) that
|
|
77
|
+
timed out, lost their connection, or got a 500, 502, 503 or 504
|
|
78
|
+
response.
|
|
79
|
+
transport: Sends the requests, e.g. a transport wrapping a preconfigured
|
|
80
|
+
HTTP client. The caller keeps ownership of it: closing this client
|
|
81
|
+
leaves it open. Defaults to a transport the client creates and closes.
|
|
82
|
+
"""
|
|
83
|
+
super().__init__(
|
|
84
|
+
token=token, base_url=base_url, timeout=timeout, max_retries=max_retries
|
|
85
|
+
)
|
|
86
|
+
self._owns_transport = transport is None
|
|
87
|
+
self._transport = AsyncDefaultTransport() if transport is None else transport
|
|
88
|
+
self.apps = AsyncApps(self)
|
|
89
|
+
self.auth = AsyncAuth(self)
|
|
90
|
+
self.deployments = AsyncDeployments(self)
|
|
91
|
+
self.projects = AsyncProjects(self)
|
|
92
|
+
self.providers = AsyncProviders(self)
|
|
93
|
+
self.security_reviews = AsyncSecurityReviews(self)
|
|
94
|
+
self.usage = AsyncUsage(self)
|
|
95
|
+
|
|
96
|
+
async def __aenter__(self) -> AsyncReflexCloud:
|
|
97
|
+
"""Enter the client's context.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
The client.
|
|
101
|
+
"""
|
|
102
|
+
return self
|
|
103
|
+
|
|
104
|
+
async def __aexit__(
|
|
105
|
+
self,
|
|
106
|
+
exc_type: type[BaseException] | None,
|
|
107
|
+
exc: BaseException | None,
|
|
108
|
+
traceback: TracebackType | None,
|
|
109
|
+
) -> None:
|
|
110
|
+
"""Close the client when leaving its context.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
exc_type: The type of the exception raised in the context, if any.
|
|
114
|
+
exc: The exception raised in the context, if any.
|
|
115
|
+
traceback: The traceback of that exception, if any.
|
|
116
|
+
"""
|
|
117
|
+
await self.aclose()
|
|
118
|
+
|
|
119
|
+
async def aclose(self) -> None:
|
|
120
|
+
"""Close the transport, unless it was passed in."""
|
|
121
|
+
if self._owns_transport:
|
|
122
|
+
await self._transport.aclose()
|
|
123
|
+
|
|
124
|
+
@overload
|
|
125
|
+
async def _request(
|
|
126
|
+
self,
|
|
127
|
+
method: str,
|
|
128
|
+
path: str,
|
|
129
|
+
cast: type[T],
|
|
130
|
+
*,
|
|
131
|
+
params: dict[str, Any] | None = None,
|
|
132
|
+
json: Any = None,
|
|
133
|
+
form: Mapping[str, str] | None = None,
|
|
134
|
+
authenticated: bool = True,
|
|
135
|
+
idempotent: bool | None = None,
|
|
136
|
+
extra_headers: Mapping[str, str] | None = None,
|
|
137
|
+
) -> T: ...
|
|
138
|
+
|
|
139
|
+
@overload
|
|
140
|
+
async def _request(
|
|
141
|
+
self,
|
|
142
|
+
method: str,
|
|
143
|
+
path: str,
|
|
144
|
+
cast: None,
|
|
145
|
+
*,
|
|
146
|
+
params: dict[str, Any] | None = None,
|
|
147
|
+
json: Any = None,
|
|
148
|
+
form: Mapping[str, str] | None = None,
|
|
149
|
+
authenticated: bool = True,
|
|
150
|
+
idempotent: bool | None = None,
|
|
151
|
+
extra_headers: Mapping[str, str] | None = None,
|
|
152
|
+
) -> None: ...
|
|
153
|
+
|
|
154
|
+
async def _request(
|
|
155
|
+
self,
|
|
156
|
+
method: str,
|
|
157
|
+
path: str,
|
|
158
|
+
cast: Any,
|
|
159
|
+
*,
|
|
160
|
+
params: dict[str, Any] | None = None,
|
|
161
|
+
json: Any = None,
|
|
162
|
+
form: Mapping[str, str] | None = None,
|
|
163
|
+
authenticated: bool = True,
|
|
164
|
+
idempotent: bool | None = None,
|
|
165
|
+
extra_headers: Mapping[str, str] | None = None,
|
|
166
|
+
) -> Any:
|
|
167
|
+
"""Send an API request, retrying transient failures that are safe to retry.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
method: The HTTP method.
|
|
171
|
+
path: The endpoint path relative to ``/api/v1/``, with path parameters
|
|
172
|
+
already quoted.
|
|
173
|
+
cast: The type to decode the JSON response into, None to ignore it, or
|
|
174
|
+
``Response`` for the response itself.
|
|
175
|
+
params: The query parameters; None values are left out.
|
|
176
|
+
json: The JSON body, if any.
|
|
177
|
+
form: A form-encoded body, sent instead of ``json``.
|
|
178
|
+
authenticated: Whether to send the access token.
|
|
179
|
+
idempotent: Whether repeating the request is harmless, which decides
|
|
180
|
+
whether it is retried after it may have reached the server. Defaults
|
|
181
|
+
to whether the method is idempotent.
|
|
182
|
+
extra_headers: Headers to send beside the ones every request carries.
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
The decoded response body.
|
|
186
|
+
|
|
187
|
+
Raises:
|
|
188
|
+
APITimeoutError: If the last attempt timed out.
|
|
189
|
+
APIConnectionError: If the last attempt failed without a response.
|
|
190
|
+
APIStatusError: If the API responded with an error status.
|
|
191
|
+
"""
|
|
192
|
+
request = self._build_request(
|
|
193
|
+
method,
|
|
194
|
+
path,
|
|
195
|
+
params=params,
|
|
196
|
+
json=json,
|
|
197
|
+
form=form,
|
|
198
|
+
authenticated=authenticated,
|
|
199
|
+
extra_headers=extra_headers,
|
|
200
|
+
)
|
|
201
|
+
attempt = 0
|
|
202
|
+
while True:
|
|
203
|
+
try:
|
|
204
|
+
response = await self._transport.send(request)
|
|
205
|
+
except TransportError as ex:
|
|
206
|
+
delay = self._retry_delay(
|
|
207
|
+
request, attempt, sent=ex.sent, idempotent=idempotent
|
|
208
|
+
)
|
|
209
|
+
if delay is None:
|
|
210
|
+
raise connection_error(ex) from ex
|
|
211
|
+
else:
|
|
212
|
+
if response.is_success:
|
|
213
|
+
return decode_response(response, cast)
|
|
214
|
+
delay = self._retry_delay(
|
|
215
|
+
request, attempt, response, idempotent=idempotent
|
|
216
|
+
)
|
|
217
|
+
if delay is None:
|
|
218
|
+
raise status_error_from_response(response)
|
|
219
|
+
attempt += 1
|
|
220
|
+
logger.debug(
|
|
221
|
+
"Retrying %s %s in %.2fs (retry %d of %d)",
|
|
222
|
+
method,
|
|
223
|
+
request.url,
|
|
224
|
+
delay,
|
|
225
|
+
attempt,
|
|
226
|
+
self.max_retries,
|
|
227
|
+
)
|
|
228
|
+
await asyncio.sleep(delay)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""API resources of the asynchronous Reflex Cloud client."""
|