reflex-build-sdk 0.0.1__tar.gz

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.
Files changed (46) hide show
  1. reflex_build_sdk-0.0.1/.gitignore +35 -0
  2. reflex_build_sdk-0.0.1/CHANGELOG.md +19 -0
  3. reflex_build_sdk-0.0.1/PKG-INFO +245 -0
  4. reflex_build_sdk-0.0.1/README.md +232 -0
  5. reflex_build_sdk-0.0.1/pyproject.toml +32 -0
  6. reflex_build_sdk-0.0.1/src/reflex_build_sdk/__init__.py +53 -0
  7. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_async/__init__.py +1 -0
  8. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_async/_client.py +228 -0
  9. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_async/resources/__init__.py +1 -0
  10. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_async/resources/apps.py +874 -0
  11. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_async/resources/auth.py +247 -0
  12. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_async/resources/connections.py +207 -0
  13. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_async/resources/databases.py +101 -0
  14. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_async/resources/deployments.py +410 -0
  15. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_async/resources/environments.py +268 -0
  16. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_async/resources/projects.py +533 -0
  17. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_async/resources/providers.py +458 -0
  18. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_async/resources/security_reviews.py +141 -0
  19. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_async/resources/sign_in.py +293 -0
  20. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_async/resources/usage.py +100 -0
  21. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_base.py +331 -0
  22. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_decode.py +395 -0
  23. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_deploy.py +308 -0
  24. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_errors.py +217 -0
  25. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_sync/__init__.py +2 -0
  26. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_sync/_client.py +229 -0
  27. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_sync/resources/__init__.py +2 -0
  28. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_sync/resources/apps.py +867 -0
  29. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_sync/resources/auth.py +248 -0
  30. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_sync/resources/connections.py +208 -0
  31. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_sync/resources/databases.py +102 -0
  32. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_sync/resources/deployments.py +411 -0
  33. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_sync/resources/environments.py +267 -0
  34. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_sync/resources/projects.py +526 -0
  35. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_sync/resources/providers.py +455 -0
  36. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_sync/resources/security_reviews.py +142 -0
  37. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_sync/resources/sign_in.py +290 -0
  38. reflex_build_sdk-0.0.1/src/reflex_build_sdk/_sync/resources/usage.py +101 -0
  39. reflex_build_sdk-0.0.1/src/reflex_build_sdk/credentials.py +110 -0
  40. reflex_build_sdk-0.0.1/src/reflex_build_sdk/py.typed +0 -0
  41. reflex_build_sdk-0.0.1/src/reflex_build_sdk/transports/__init__.py +27 -0
  42. reflex_build_sdk-0.0.1/src/reflex_build_sdk/transports/_aiohttp.py +198 -0
  43. reflex_build_sdk-0.0.1/src/reflex_build_sdk/transports/_base.py +145 -0
  44. reflex_build_sdk-0.0.1/src/reflex_build_sdk/transports/_defaults.py +12 -0
  45. reflex_build_sdk-0.0.1/src/reflex_build_sdk/transports/_httpx.py +129 -0
  46. reflex_build_sdk-0.0.1/src/reflex_build_sdk/types.py +1048 -0
@@ -0,0 +1,35 @@
1
+ **/.DS_Store
2
+ **/*.pyc
3
+ **/__pycache__/
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ **/.ruff_cache/
7
+ .mypy_cache/
8
+ assets/external/*
9
+ dist/*
10
+ examples/
11
+ .web
12
+ .states
13
+ .idea
14
+ .vscode
15
+ .coverage
16
+ .coverage.*
17
+ .venv
18
+ venv
19
+ requirements.txt
20
+ .pyi_generator_last_run
21
+ .pyi_generator_diff
22
+ reflex.db
23
+ .codspeed
24
+ .env
25
+ .env.*
26
+ node_modules
27
+ package-lock.json
28
+ *.pyi
29
+ .pre-commit-config.yaml
30
+ .claude/.worktrees
31
+ .claude/settings.local.json
32
+ CLAUDE.local.md
33
+
34
+ # Backups written by scripts/delete_automated_releases.sh
35
+ automated-releases-backup-*.json
@@ -0,0 +1,19 @@
1
+
2
+
3
+ <!-- towncrier release notes start -->
4
+
5
+ ## v0.0.1 (2026-09-18)
6
+
7
+ ### Features
8
+
9
+ - Add the `reflex-build-sdk` package: `ReflexCloud` and `AsyncReflexCloud` clients for the Reflex Cloud API, starting with `auth.me()` and access token management (`auth.tokens.create/list/delete`), with typed models, typed errors, and retries for requests that are safe to repeat. The async client sends requests with aiohttp and the sync client with httpx; pass a transport from `reflex_build_sdk.transports` to configure or replace the HTTP library. ([#7166](https://github.com/reflex-dev/reflex/issues/7166))
10
+ - Add app, secret and project management to `reflex-build-sdk`: `client.apps` (list, search, get, create, delete, start, stop, pause, scale, rollback, deployment history, and runtime logs as an iterator), `client.apps.secrets`, and `client.projects` with its roles and members. ([#7169](https://github.com/reflex-dev/reflex/issues/7169))
11
+ - Deploy apps with `reflex-build-sdk`: `client.deployments.create` streams a build's archives to storage and submits the deployment, and `client.deployments.wait` follows it until it is running or awaiting approval, raising `DeploymentFailedError` with the failure report if it fails, or `DeploymentTimeoutError` when the timeout passes first. The client also reads deployment status, reports and build logs, lists regions and machine sizes, and reserves hostnames with `client.apps.reserve_hostname`. ([#7172](https://github.com/reflex-dev/reflex/issues/7172))
12
+ - Log in and review code with `reflex-build-sdk`: `client.auth.begin_login` and `finish_login` run the browser login, and the public `reflex_build_sdk.credentials` module loads, saves and deletes the token `reflex login` shares. `client.security_reviews` submits source code for a security review and waits for the result. `client.providers` reads Google Cloud deploy status, connected provider accounts and the Cloud Run manifest, `client.apps` sets an app's hosting provider, full deploy and instance bounds, `client.deployments.check` validates deployment settings before a build, and `client.auth.me` takes a `source` for login analytics. ([#7175](https://github.com/reflex-dev/reflex/issues/7175))
13
+ - Manage more of an app with `reflex-build-sdk`: `client.apps` renames, describes and moves apps, sets instance persistence, the rollout strategy, the Cloud Run service name and the weekly report, and reads an app's lifecycle status and running deployment. `client.apps.domains` adds, checks and removes custom domains. ([#7180](https://github.com/reflex-dev/reflex/issues/7180))
14
+ - Deploy through environments with `reflex-build-sdk`: `client.apps.environments` enables, lists, creates, updates, reorders and deletes an app's environments, promotes a version to the next one and copies missing secrets. `client.apps.database` creates, reads and deletes an app's managed Postgres database. ([#7181](https://github.com/reflex-dev/reflex/issues/7181))
15
+ - Sign an app's users in with `reflex-build-sdk`: `client.apps.sign_in` enables and disables sign-in with Reflex accounts, sets who may sign in, manages invitations, and lists, exports, blocks and unblocks the app's users. ([#7182](https://github.com/reflex-dev/reflex/issues/7182))
16
+ - Manage project access with `reflex-build-sdk`: `client.projects` renames and deletes projects and reads audit logs, `projects.roles` creates, updates, previews and deletes custom roles, `projects.members` removes members and reads a member's effective permissions, and `projects.teams` lists, grants and revokes organization teams' roles. ([#7183](https://github.com/reflex-dev/reflex/issues/7183))
17
+ - Manage an organization's Google Cloud and your tokens with `reflex-build-sdk`: `client.providers` connects and disconnects Google Cloud and lists the apps blocking removal, and `providers.gcp_connections` adds, updates, verifies, rotates keys of, sets the default of and removes connections. `client.auth.tokens` revokes and refreshes tokens and assigns them to service accounts, and `client.usage` reads the plan allowance balance and usage history. ([#7184](https://github.com/reflex-dev/reflex/issues/7184))
18
+ - Publish the SDK as `reflex-build-sdk`, imported as `reflex_build_sdk`. ([#7191](https://github.com/reflex-dev/reflex/issues/7191))
19
+ - Call third-party services from an app with `reflex-build-sdk`: `client.apps.connections` reads a live credential for the app or for one of its users, lists what is connected, starts a connection and disconnects it, without the app ever holding the provider's key. `APIStatusError.code` now carries the condition the API names for a refusal, such as `not_connected`. ([#7192](https://github.com/reflex-dev/reflex/issues/7192))
@@ -0,0 +1,245 @@
1
+ Metadata-Version: 2.5
2
+ Name: reflex-build-sdk
3
+ Version: 0.0.1
4
+ Summary: Python client for the Reflex Cloud API.
5
+ Author-email: Khaleel Al-Adhami <khaleel@reflex.dev>
6
+ Maintainer-email: Khaleel Al-Adhami <khaleel@reflex.dev>
7
+ License: Apache-2.0
8
+ Requires-Python: >=3.10
9
+ Requires-Dist: aiohttp<4.0,>=3.10.0
10
+ Requires-Dist: httpx<1.0,>=0.25.1
11
+ Requires-Dist: platformdirs<5.0,>=3.10.0
12
+ Description-Content-Type: text/markdown
13
+
14
+ # reflex-build-sdk
15
+
16
+ Python client for the [Reflex Cloud](https://build.reflex.dev) API, with synchronous and asynchronous interfaces.
17
+
18
+ ```python
19
+ from reflex_build_sdk import ReflexCloud
20
+
21
+ with ReflexCloud() as client:
22
+ me = client.auth.me()
23
+ print(me.email, me.tier)
24
+ ```
25
+
26
+ ```python
27
+ from reflex_build_sdk import AsyncReflexCloud
28
+
29
+ async with AsyncReflexCloud() as client:
30
+ me = await client.auth.me()
31
+ ```
32
+
33
+ ## Apps and projects
34
+
35
+ ```python
36
+ from reflex_build_sdk import ReflexCloud
37
+
38
+ with ReflexCloud() as client:
39
+ projects = client.projects.search("default")
40
+ project = projects[0] if projects else client.projects.create("default")
41
+ app = client.apps.create("dashboard", project_id=project.id)
42
+ client.apps.secrets.set(app.id, {"OPENAI_API_KEY": "sk-..."})
43
+
44
+ for deployment in client.apps.history(app.id):
45
+ print(deployment.status, deployment.url)
46
+
47
+ for record in client.apps.logs(app.id, search="error"):
48
+ print(record.timestamp, record.message)
49
+ ```
50
+
51
+ `client.apps` lists, creates, renames, moves, starts, stops, pauses, scales, rolls back and deletes apps, changes their settings, and reads their status, running deployment, deployment history and runtime logs; `client.apps.secrets` manages their secrets. `client.projects` lists, searches, creates, renames and deletes projects and reads their audit logs, with `projects.roles` (including custom roles), `projects.members` and `projects.teams` for access control. `AsyncReflexCloud` has the same methods as coroutines, with `logs` as an async iterator.
52
+
53
+ ### Custom domains
54
+
55
+ ```python
56
+ for record in client.apps.domains.add(app.id, "app.example.com").values():
57
+ print(record.type, record.name, record.value)
58
+
59
+ domain = client.apps.domains.get(app.id)
60
+ print(domain.status, domain.status_detail)
61
+ ```
62
+
63
+ `domains.add` returns the DNS records to create, and `domains.get` checks them and reports whether the domain is ready to serve the app. Custom domains need the Pro or Enterprise plan.
64
+
65
+ ## Deploying
66
+
67
+ ```python
68
+ from reflex_build_sdk import DeploymentFailedError, ReflexCloud
69
+
70
+ with ReflexCloud() as client:
71
+ urls = client.apps.reserve_hostname(app.id, app.name)
72
+ # Export the app against urls.frontend_url and urls.backend_url, e.g. with
73
+ # `reflex export`, producing backend.zip and frontend.zip.
74
+ deployment_id = client.deployments.create(
75
+ app.id,
76
+ backend="backend.zip",
77
+ frontend="frontend.zip",
78
+ regions={"sjc": 1},
79
+ on_upload_progress=lambda sent, total: print(f"{sent}/{total} bytes"),
80
+ )
81
+ try:
82
+ report = client.deployments.wait(deployment_id, on_status=print, timeout=900)
83
+ except DeploymentFailedError as error:
84
+ print(error.report.reason, error.report.guidance)
85
+ print(error.report.build_log_excerpt)
86
+ raise
87
+ ```
88
+
89
+ `deployments.create` streams the archives straight to storage, then submits the deployment. `deployments.wait` returns the deployment's report once it is running, or awaiting approval (`report.status == "AwaitingApproval"`), and raises `DeploymentFailedError` if it fails. `deployments.status`, `report` and `build_logs` read a deployment's progress, and `regions` and `vm_types` list what can be deployed to.
90
+
91
+ ### Environments
92
+
93
+ Give an app a pipeline of a dev and a production environment:
94
+
95
+ ```python
96
+ pipeline = client.apps.environments.enable(app.id)
97
+ production_id = pipeline.production_environment_id
98
+ ```
99
+
100
+ An app that has a pipeline already is read rather than enabled again, which fails:
101
+
102
+ ```python
103
+ dev, production = client.apps.environments.list(app.id)
104
+ production_id = production.id
105
+ ```
106
+
107
+ Deployments go to the first environment, and later ones run a version promoted from the one before:
108
+
109
+ ```python
110
+ deployment_id = client.deployments.create(
111
+ app.id, backend="backend.zip", frontend="frontend.zip"
112
+ )
113
+ client.deployments.wait(deployment_id)
114
+ promotion = client.apps.environments.promote(app.id, production_id)
115
+ client.deployments.wait(promotion.deployment_id)
116
+ ```
117
+
118
+ Each environment has its own secrets and URL, and production keeps the app's own id and history. `environments.create`, `update`, `reorder`, `copy_missing_secrets` and `delete` manage the rest of the pipeline. Pipelines need the Enterprise plan.
119
+
120
+ ### Managed database
121
+
122
+ ```python
123
+ database = client.apps.database.create(app.id)
124
+ print(database.masked_connection_string)
125
+ ```
126
+
127
+ `client.apps.database` creates a Postgres database for an app, shared by all of its environments, and sets its connection strings as secrets, `DATABASE_URL` among them, which each environment picks up on its next deployment. Creating or deleting a database needs a token with full access, which `reflex login` tokens are not, and an app with its own `DATABASE_URL` secret is refused.
128
+
129
+ ### Signing users in
130
+
131
+ ```python
132
+ client.apps.sign_in.enable(app.id)
133
+ client.apps.sign_in.set_audience(app.id, "invited")
134
+ client.apps.sign_in.invite(app.id, "someone@example.com")
135
+ ```
136
+
137
+ `client.apps.sign_in` lets an app's users sign in with their Reflex accounts, through `rxe.AuthPlugin` from `reflex-enterprise`. It sets the app's sign-in settings as secrets, which take effect when the app is next deployed with `rxe.AuthPlugin`, chooses who may sign in, and lists, exports and blocks the app's users. Restricting who may sign in and inviting addresses need the Pro or Enterprise plan. Changing sign-in needs a token with full access; tokens from `reflex login` are refused.
138
+
139
+ ### Third-party connections
140
+
141
+ ```python
142
+ # Inside a deployed app, which is started with its own access token.
143
+ with ReflexCloud() as client:
144
+ token = client.apps.connections.credential(app_id, "openai").access_token
145
+ # ... and for one of the app's users:
146
+ token = client.apps.connections.credential(
147
+ app_id, "openai", end_user=user_id
148
+ ).access_token
149
+ ```
150
+
151
+ `client.apps.connections` calls third-party services an app is connected to without the app holding their keys: Reflex Cloud stores the credentials and hands out a live one per call, so read one for each call rather than storing it. `connect_link` starts a connection and returns the page to send someone to, `status` and `list` report what is connected, and `disconnect` ends it. A connection belongs either to the app or to one of its users, named with `end_user`. These need the app's own token, so a client built with no arguments inside a deployed app is already the right one.
152
+
153
+ ## Authentication
154
+
155
+ The client uses the first access token it finds:
156
+
157
+ 1. The `token` argument.
158
+ 2. The `REFLEX_ACCESS_TOKEN` environment variable.
159
+ 3. The token saved on this machine, shared with `reflex login`.
160
+
161
+ To log in through the browser and save the token for later clients:
162
+
163
+ ```python
164
+ import webbrowser
165
+
166
+ from reflex_build_sdk import ReflexCloud, credentials
167
+
168
+ with ReflexCloud() as client:
169
+ login = client.auth.begin_login()
170
+ print(f"Approve the login at {login.url}")
171
+ webbrowser.open(login.url)
172
+ credentials.save_token(client.auth.finish_login(login, timeout=600))
173
+ ```
174
+
175
+ `credentials.delete_token()` removes the saved token. Create a token for CI with `client.auth.tokens.create("ci", expires_in_days=30)`, and rotate or revoke one with `client.auth.tokens.refresh(token)` and `client.auth.tokens.revoke(token)`. Managing tokens needs a token with full access, which `reflex login` tokens are not.
176
+
177
+ `client.usage.balance()` reports how much of the organization's plan allowance is used, and `client.usage.history()` iterates over its charges and credits.
178
+
179
+ ## Security reviews
180
+
181
+ ```python
182
+ review_id = client.security_reviews.submit("source.zip")
183
+ result = client.security_reviews.wait(review_id, timeout=600)
184
+ for violation in result.violations:
185
+ print(violation.severity, violation.file_path, violation.line, violation.message)
186
+ ```
187
+
188
+ Security reviews need the Pro or Enterprise plan.
189
+
190
+ ## Google Cloud
191
+
192
+ Apps can run on an organization's own Google Cloud instead of Reflex Cloud:
193
+
194
+ ```python
195
+ status = client.providers.gcp_status(client.auth.me().org_id)
196
+ if status.configured and status.allowed:
197
+ client.apps.set_provider(app.id, "gcp")
198
+ client.apps.set_instance_bounds(app.id, min_instances=1, max_instances=10)
199
+ ```
200
+
201
+ Running on Google Cloud needs the Enterprise plan. `client.apps.set_full_deploy` also serves an app's frontend from Google Cloud, and `client.providers.cloud_run_manifest()` returns the Dockerfile and script to deploy to Cloud Run yourself.
202
+
203
+ Organization admins connect Google Cloud projects with a service account key:
204
+
205
+ ```python
206
+ with open("key.json") as key_file:
207
+ client.providers.connect_gcp(
208
+ client.auth.me().org_id,
209
+ service_account_key=key_file.read(),
210
+ project_number="123456789012",
211
+ region="us-central1",
212
+ )
213
+ ```
214
+
215
+ `client.providers.gcp_connections` adds, updates, verifies and removes further projects, rotates their keys and chooses the default, and `client.providers.disconnect_gcp` removes them all. These need a token with full access.
216
+
217
+ ## Errors
218
+
219
+ Every exception derives from `reflex_build_sdk.ReflexCloudError`. Error responses raise a subclass of `APIStatusError` matching the status code (`AuthenticationError`, `NotFoundError`, ...), carrying `status_code`, the server's `detail`, the `code` naming the condition where the API names one (e.g. `"not_connected"`), and the `request_id` to quote to support. Failed requests are retried up to `max_retries` times when repeating them cannot apply them twice: requests that never reached the server or were turned away with 408 or 429, and requests that are harmless to repeat (`GET`, `HEAD`, `OPTIONS` and `PUT` requests, and calls such as `apps.environments.update` that settle on the same result) that timed out, lost their connection, or got a 500, 502, 503 or 504 response.
220
+
221
+ ## Transports
222
+
223
+ `AsyncReflexCloud` sends requests with [aiohttp](https://docs.aiohttp.org) and `ReflexCloud` with [httpx](https://www.python-httpx.org). Pass a transport from `reflex_build_sdk.transports` to configure the HTTP client, e.g. for proxies, or to use httpx asynchronously:
224
+
225
+ ```python
226
+ import aiohttp
227
+ import httpx
228
+ from reflex_build_sdk import AsyncReflexCloud, ReflexCloud
229
+ from reflex_build_sdk.transports import (
230
+ AiohttpTransport,
231
+ AsyncHttpxTransport,
232
+ HttpxTransport,
233
+ )
234
+
235
+ # Reads HTTP_PROXY, HTTPS_PROXY and NO_PROXY from the environment.
236
+ async with aiohttp.ClientSession(trust_env=True) as session:
237
+ async with AsyncReflexCloud(transport=AiohttpTransport(session)) as client:
238
+ ...
239
+
240
+ client = AsyncReflexCloud(transport=AsyncHttpxTransport())
241
+ client = ReflexCloud(transport=HttpxTransport(httpx.Client(proxy="http://proxy:8080")))
242
+ ```
243
+
244
+ To use another HTTP library, implement the `Transport` or `AsyncTransport` protocol.
245
+
@@ -0,0 +1,232 @@
1
+ # reflex-build-sdk
2
+
3
+ Python client for the [Reflex Cloud](https://build.reflex.dev) API, with synchronous and asynchronous interfaces.
4
+
5
+ ```python
6
+ from reflex_build_sdk import ReflexCloud
7
+
8
+ with ReflexCloud() as client:
9
+ me = client.auth.me()
10
+ print(me.email, me.tier)
11
+ ```
12
+
13
+ ```python
14
+ from reflex_build_sdk import AsyncReflexCloud
15
+
16
+ async with AsyncReflexCloud() as client:
17
+ me = await client.auth.me()
18
+ ```
19
+
20
+ ## Apps and projects
21
+
22
+ ```python
23
+ from reflex_build_sdk import ReflexCloud
24
+
25
+ with ReflexCloud() as client:
26
+ projects = client.projects.search("default")
27
+ project = projects[0] if projects else client.projects.create("default")
28
+ app = client.apps.create("dashboard", project_id=project.id)
29
+ client.apps.secrets.set(app.id, {"OPENAI_API_KEY": "sk-..."})
30
+
31
+ for deployment in client.apps.history(app.id):
32
+ print(deployment.status, deployment.url)
33
+
34
+ for record in client.apps.logs(app.id, search="error"):
35
+ print(record.timestamp, record.message)
36
+ ```
37
+
38
+ `client.apps` lists, creates, renames, moves, starts, stops, pauses, scales, rolls back and deletes apps, changes their settings, and reads their status, running deployment, deployment history and runtime logs; `client.apps.secrets` manages their secrets. `client.projects` lists, searches, creates, renames and deletes projects and reads their audit logs, with `projects.roles` (including custom roles), `projects.members` and `projects.teams` for access control. `AsyncReflexCloud` has the same methods as coroutines, with `logs` as an async iterator.
39
+
40
+ ### Custom domains
41
+
42
+ ```python
43
+ for record in client.apps.domains.add(app.id, "app.example.com").values():
44
+ print(record.type, record.name, record.value)
45
+
46
+ domain = client.apps.domains.get(app.id)
47
+ print(domain.status, domain.status_detail)
48
+ ```
49
+
50
+ `domains.add` returns the DNS records to create, and `domains.get` checks them and reports whether the domain is ready to serve the app. Custom domains need the Pro or Enterprise plan.
51
+
52
+ ## Deploying
53
+
54
+ ```python
55
+ from reflex_build_sdk import DeploymentFailedError, ReflexCloud
56
+
57
+ with ReflexCloud() as client:
58
+ urls = client.apps.reserve_hostname(app.id, app.name)
59
+ # Export the app against urls.frontend_url and urls.backend_url, e.g. with
60
+ # `reflex export`, producing backend.zip and frontend.zip.
61
+ deployment_id = client.deployments.create(
62
+ app.id,
63
+ backend="backend.zip",
64
+ frontend="frontend.zip",
65
+ regions={"sjc": 1},
66
+ on_upload_progress=lambda sent, total: print(f"{sent}/{total} bytes"),
67
+ )
68
+ try:
69
+ report = client.deployments.wait(deployment_id, on_status=print, timeout=900)
70
+ except DeploymentFailedError as error:
71
+ print(error.report.reason, error.report.guidance)
72
+ print(error.report.build_log_excerpt)
73
+ raise
74
+ ```
75
+
76
+ `deployments.create` streams the archives straight to storage, then submits the deployment. `deployments.wait` returns the deployment's report once it is running, or awaiting approval (`report.status == "AwaitingApproval"`), and raises `DeploymentFailedError` if it fails. `deployments.status`, `report` and `build_logs` read a deployment's progress, and `regions` and `vm_types` list what can be deployed to.
77
+
78
+ ### Environments
79
+
80
+ Give an app a pipeline of a dev and a production environment:
81
+
82
+ ```python
83
+ pipeline = client.apps.environments.enable(app.id)
84
+ production_id = pipeline.production_environment_id
85
+ ```
86
+
87
+ An app that has a pipeline already is read rather than enabled again, which fails:
88
+
89
+ ```python
90
+ dev, production = client.apps.environments.list(app.id)
91
+ production_id = production.id
92
+ ```
93
+
94
+ Deployments go to the first environment, and later ones run a version promoted from the one before:
95
+
96
+ ```python
97
+ deployment_id = client.deployments.create(
98
+ app.id, backend="backend.zip", frontend="frontend.zip"
99
+ )
100
+ client.deployments.wait(deployment_id)
101
+ promotion = client.apps.environments.promote(app.id, production_id)
102
+ client.deployments.wait(promotion.deployment_id)
103
+ ```
104
+
105
+ Each environment has its own secrets and URL, and production keeps the app's own id and history. `environments.create`, `update`, `reorder`, `copy_missing_secrets` and `delete` manage the rest of the pipeline. Pipelines need the Enterprise plan.
106
+
107
+ ### Managed database
108
+
109
+ ```python
110
+ database = client.apps.database.create(app.id)
111
+ print(database.masked_connection_string)
112
+ ```
113
+
114
+ `client.apps.database` creates a Postgres database for an app, shared by all of its environments, and sets its connection strings as secrets, `DATABASE_URL` among them, which each environment picks up on its next deployment. Creating or deleting a database needs a token with full access, which `reflex login` tokens are not, and an app with its own `DATABASE_URL` secret is refused.
115
+
116
+ ### Signing users in
117
+
118
+ ```python
119
+ client.apps.sign_in.enable(app.id)
120
+ client.apps.sign_in.set_audience(app.id, "invited")
121
+ client.apps.sign_in.invite(app.id, "someone@example.com")
122
+ ```
123
+
124
+ `client.apps.sign_in` lets an app's users sign in with their Reflex accounts, through `rxe.AuthPlugin` from `reflex-enterprise`. It sets the app's sign-in settings as secrets, which take effect when the app is next deployed with `rxe.AuthPlugin`, chooses who may sign in, and lists, exports and blocks the app's users. Restricting who may sign in and inviting addresses need the Pro or Enterprise plan. Changing sign-in needs a token with full access; tokens from `reflex login` are refused.
125
+
126
+ ### Third-party connections
127
+
128
+ ```python
129
+ # Inside a deployed app, which is started with its own access token.
130
+ with ReflexCloud() as client:
131
+ token = client.apps.connections.credential(app_id, "openai").access_token
132
+ # ... and for one of the app's users:
133
+ token = client.apps.connections.credential(
134
+ app_id, "openai", end_user=user_id
135
+ ).access_token
136
+ ```
137
+
138
+ `client.apps.connections` calls third-party services an app is connected to without the app holding their keys: Reflex Cloud stores the credentials and hands out a live one per call, so read one for each call rather than storing it. `connect_link` starts a connection and returns the page to send someone to, `status` and `list` report what is connected, and `disconnect` ends it. A connection belongs either to the app or to one of its users, named with `end_user`. These need the app's own token, so a client built with no arguments inside a deployed app is already the right one.
139
+
140
+ ## Authentication
141
+
142
+ The client uses the first access token it finds:
143
+
144
+ 1. The `token` argument.
145
+ 2. The `REFLEX_ACCESS_TOKEN` environment variable.
146
+ 3. The token saved on this machine, shared with `reflex login`.
147
+
148
+ To log in through the browser and save the token for later clients:
149
+
150
+ ```python
151
+ import webbrowser
152
+
153
+ from reflex_build_sdk import ReflexCloud, credentials
154
+
155
+ with ReflexCloud() as client:
156
+ login = client.auth.begin_login()
157
+ print(f"Approve the login at {login.url}")
158
+ webbrowser.open(login.url)
159
+ credentials.save_token(client.auth.finish_login(login, timeout=600))
160
+ ```
161
+
162
+ `credentials.delete_token()` removes the saved token. Create a token for CI with `client.auth.tokens.create("ci", expires_in_days=30)`, and rotate or revoke one with `client.auth.tokens.refresh(token)` and `client.auth.tokens.revoke(token)`. Managing tokens needs a token with full access, which `reflex login` tokens are not.
163
+
164
+ `client.usage.balance()` reports how much of the organization's plan allowance is used, and `client.usage.history()` iterates over its charges and credits.
165
+
166
+ ## Security reviews
167
+
168
+ ```python
169
+ review_id = client.security_reviews.submit("source.zip")
170
+ result = client.security_reviews.wait(review_id, timeout=600)
171
+ for violation in result.violations:
172
+ print(violation.severity, violation.file_path, violation.line, violation.message)
173
+ ```
174
+
175
+ Security reviews need the Pro or Enterprise plan.
176
+
177
+ ## Google Cloud
178
+
179
+ Apps can run on an organization's own Google Cloud instead of Reflex Cloud:
180
+
181
+ ```python
182
+ status = client.providers.gcp_status(client.auth.me().org_id)
183
+ if status.configured and status.allowed:
184
+ client.apps.set_provider(app.id, "gcp")
185
+ client.apps.set_instance_bounds(app.id, min_instances=1, max_instances=10)
186
+ ```
187
+
188
+ Running on Google Cloud needs the Enterprise plan. `client.apps.set_full_deploy` also serves an app's frontend from Google Cloud, and `client.providers.cloud_run_manifest()` returns the Dockerfile and script to deploy to Cloud Run yourself.
189
+
190
+ Organization admins connect Google Cloud projects with a service account key:
191
+
192
+ ```python
193
+ with open("key.json") as key_file:
194
+ client.providers.connect_gcp(
195
+ client.auth.me().org_id,
196
+ service_account_key=key_file.read(),
197
+ project_number="123456789012",
198
+ region="us-central1",
199
+ )
200
+ ```
201
+
202
+ `client.providers.gcp_connections` adds, updates, verifies and removes further projects, rotates their keys and chooses the default, and `client.providers.disconnect_gcp` removes them all. These need a token with full access.
203
+
204
+ ## Errors
205
+
206
+ Every exception derives from `reflex_build_sdk.ReflexCloudError`. Error responses raise a subclass of `APIStatusError` matching the status code (`AuthenticationError`, `NotFoundError`, ...), carrying `status_code`, the server's `detail`, the `code` naming the condition where the API names one (e.g. `"not_connected"`), and the `request_id` to quote to support. Failed requests are retried up to `max_retries` times when repeating them cannot apply them twice: requests that never reached the server or were turned away with 408 or 429, and requests that are harmless to repeat (`GET`, `HEAD`, `OPTIONS` and `PUT` requests, and calls such as `apps.environments.update` that settle on the same result) that timed out, lost their connection, or got a 500, 502, 503 or 504 response.
207
+
208
+ ## Transports
209
+
210
+ `AsyncReflexCloud` sends requests with [aiohttp](https://docs.aiohttp.org) and `ReflexCloud` with [httpx](https://www.python-httpx.org). Pass a transport from `reflex_build_sdk.transports` to configure the HTTP client, e.g. for proxies, or to use httpx asynchronously:
211
+
212
+ ```python
213
+ import aiohttp
214
+ import httpx
215
+ from reflex_build_sdk import AsyncReflexCloud, ReflexCloud
216
+ from reflex_build_sdk.transports import (
217
+ AiohttpTransport,
218
+ AsyncHttpxTransport,
219
+ HttpxTransport,
220
+ )
221
+
222
+ # Reads HTTP_PROXY, HTTPS_PROXY and NO_PROXY from the environment.
223
+ async with aiohttp.ClientSession(trust_env=True) as session:
224
+ async with AsyncReflexCloud(transport=AiohttpTransport(session)) as client:
225
+ ...
226
+
227
+ client = AsyncReflexCloud(transport=AsyncHttpxTransport())
228
+ client = ReflexCloud(transport=HttpxTransport(httpx.Client(proxy="http://proxy:8080")))
229
+ ```
230
+
231
+ To use another HTTP library, implement the `Transport` or `AsyncTransport` protocol.
232
+
@@ -0,0 +1,32 @@
1
+ [project]
2
+ name = "reflex-build-sdk"
3
+ dynamic = ["version"]
4
+ description = "Python client for the Reflex Cloud API."
5
+ license.text = "Apache-2.0"
6
+ readme = "README.md"
7
+ authors = [{ name = "Khaleel Al-Adhami", email = "khaleel@reflex.dev" }]
8
+ maintainers = [{ name = "Khaleel Al-Adhami", email = "khaleel@reflex.dev" }]
9
+ requires-python = ">=3.10"
10
+ dependencies = [
11
+ "aiohttp >=3.10.0,<4.0",
12
+ "httpx >=0.25.1,<1.0",
13
+ "platformdirs >=3.10.0,<5.0",
14
+ ]
15
+
16
+ [tool.hatch.version]
17
+ source = "uv-dynamic-versioning"
18
+
19
+ [tool.uv-dynamic-versioning]
20
+ pattern-prefix = "reflex-build-sdk-"
21
+ fallback-version = "0.0.0dev0"
22
+
23
+ [tool.hatch.build.targets.wheel]
24
+ packages = ["src/reflex_build_sdk"]
25
+
26
+ [tool.hatch.build.targets.sdist]
27
+ # The API schema snapshot and its maintenance scripts are for the monorepo.
28
+ exclude = ["/openapi.json", "/scripts"]
29
+
30
+ [build-system]
31
+ requires = ["hatchling", "uv-dynamic-versioning"]
32
+ build-backend = "hatchling.build"
@@ -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."""