vertracloud-api 0.4.2__tar.gz → 0.4.4__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 (28) hide show
  1. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/CHANGELOG.md +17 -0
  2. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/PKG-INFO +120 -9
  3. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/README.md +119 -8
  4. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/pyproject.toml +1 -1
  5. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/__init__.py +10 -0
  6. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/client.py +162 -7
  7. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/errcodes.py +26 -1
  8. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/errors.py +71 -1
  9. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/resources/apps.py +131 -18
  10. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/resources/databases.py +41 -11
  11. vertracloud_api-0.4.4/src/vertracloud/resources/snapshot_jobs.py +107 -0
  12. vertracloud_api-0.4.4/src/vertracloud/resources/snapshots.py +209 -0
  13. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/resources/stacks.py +172 -16
  14. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/sse.py +11 -1
  15. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/transport.py +36 -2
  16. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/types.py +293 -27
  17. vertracloud_api-0.4.2/src/vertracloud/resources/snapshots.py +0 -80
  18. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/.gitignore +0 -0
  19. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/LICENSE +0 -0
  20. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/py.typed +0 -0
  21. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/resources/__init__.py +0 -0
  22. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/resources/account.py +0 -0
  23. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/resources/billing.py +0 -0
  24. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/resources/blob.py +0 -0
  25. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/resources/images.py +0 -0
  26. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/resources/plans.py +0 -0
  27. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/resources/templates.py +0 -0
  28. {vertracloud_api-0.4.2 → vertracloud_api-0.4.4}/src/vertracloud/resources/workspaces.py +0 -0
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.4.4](https://github.com/vertracloud/sdk-api-py/compare/v0.4.3...v0.4.4) (2026-11-24)
4
+
5
+
6
+ ### Features
7
+
8
+ * auto restart, one-time database passwords, live metrics and metric events ([fca97c0](https://github.com/vertracloud/sdk-api-py/commit/fca97c0894f228c1f9a7dc17afbb5ab549f3284f))
9
+
10
+ ## [0.4.3](https://github.com/vertracloud/sdk-api-py/compare/v0.4.2...v0.4.3) (2026-11-20)
11
+
12
+
13
+ ### Features
14
+
15
+ * **apps:** download an app as a snapshot and stream it to disk ([fe517aa](https://github.com/vertracloud/sdk-api-py/commit/fe517aa66340fdd8012a029863f2300589018c1a))
16
+ * **databases:** reset and delete run right away ([25a1635](https://github.com/vertracloud/sdk-api-py/commit/25a163521993b41f8c90f1f5165a1caa11477afe))
17
+ * **snapshots:** follow snapshot jobs and stream downloads to a file ([3818624](https://github.com/vertracloud/sdk-api-py/commit/381862465befbe645ada8f818fb670441e42d54f))
18
+ * **transport:** read response bodies in chunks ([22d4251](https://github.com/vertracloud/sdk-api-py/commit/22d4251f3761830b14826e7d4d0ceda72f6578eb))
19
+
3
20
  ## [0.4.2](https://github.com/vertracloud/sdk-api-py/compare/v0.4.1...v0.4.2) (2026-11-11)
4
21
 
5
22
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: vertracloud-api
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: Official Python SDK for the public API of Vertra Cloud, a Brazilian application hosting platform (PaaS).
5
5
  Project-URL: Homepage, https://vertracloud.app
6
6
  Project-URL: Documentation, https://docs.vertracloud.app/sdks
@@ -76,14 +76,14 @@ client = VertraClient(
76
76
 
77
77
  ### Per-call options
78
78
 
79
- Methods on apps, databases, images, templates and stacks take a keyword-only `workspace_id`; downloads, uploads and streams also take `timeout`:
79
+ Methods on apps, databases, images, templates and stacks take a keyword-only `workspace_id`; downloads, uploads and streams also take `timeout` (the limit of each request, never a total wait; the `wait_timeout` of the `*_and_wait` and `wait_for_*` helpers is the total):
80
80
 
81
81
  ```python
82
82
  # Act on a resource that belongs to a workspace
83
83
  app = client.apps.get(app_id, workspace_id=workspace_id)
84
84
 
85
85
  # Give one slow call more time
86
- zip_bytes = client.apps.download(app_id, timeout=300)
86
+ zip_bytes = client.apps.download(app_id, timeout=300) # per request; the wait for the snapshot is `wait_timeout`
87
87
  ```
88
88
 
89
89
  Nested resources are attributes: `client.apps.deploys`, `client.apps.releases`, `client.apps.envs`, `client.workspaces.members`, `client.billing.orders`, …
@@ -148,6 +148,14 @@ client.apps.update_config(app_id, {"deploy": {"health_check_path": None}}) # cl
148
148
 
149
149
  `client.apps.files.upload(..., message="...")` sets the message shown in the release history.
150
150
 
151
+ Automatic restart is set at creation (`client.apps.create({"name": "x", "auto_restart": False}, file=zip_bytes)`; omitted, it is on) and afterwards with `update_config`, applied right away without a restart or reinstall:
152
+
153
+ ```python
154
+ client.apps.update_config(app_id, {"auto_restart": False})
155
+ ```
156
+
157
+ `client.apps.files.delete` answers `{"space_released": "now" | "on_restart"}`: `on_restart` means the file was still open and the space returns at the next restart.
158
+
151
159
  ### Web Analytics
152
160
 
153
161
  Traffic, errors, performance and the request log of an app's site (scope `apps:read`). Every call takes a window (`start`, `end`, ISO 8601; at most 30 days, within the plan's `limits.web_analytics_history_days`) and one keyword per dimension to filter by (`country`, `edge_location`, `host`, `path` as a prefix, `method`, `status` or a class such as `5xx`, `protocol`, `device`, `os`, `browser`, `referer`, `asn`, `ip`, `content_type`, `cache_status`, `bot`). A `value` of a breakdown entry can be sent back as the filter unchanged; `"(none)"` filters the requests that had no value.
@@ -174,17 +182,26 @@ An app with no site published answers `web_published: False` and empty data. `PL
174
182
 
175
183
  ### Uploading and downloading
176
184
 
177
- Uploads take `bytes`; downloads return `bytes`.
185
+ Uploads take `bytes`. To download, use `download_to_file`, which writes to disk as the bytes arrive and keeps memory constant whatever the size; `download` returns `bytes` and holds the whole file in memory, so keep it for small files.
178
186
 
179
187
  ```python
180
188
  with open("app.zip", "rb") as f:
181
189
  app = client.apps.create({"name": "my-app", "memory": 512}, file=f.read())
182
190
 
183
- with open("backup.zip", "wb") as f:
184
- f.write(client.apps.download(app_id))
191
+ written = client.apps.download_to_file(app_id, "backup.zip") # bytes written
192
+ ```
193
+
194
+ `client.snapshots.download(resource_id, snapshot_id, scope)` downloads one snapshot of an app or a database as `bytes`. It has no total deadline: `timeout` (30 s by default) is the wait of each socket operation, so a large file that keeps arriving completes however long it takes, and one that stops sending bytes fails after `timeout`.
195
+
196
+ `apps.download` downloads the whole app as a zip: it takes a manual snapshot (`snapshots.create_and_wait`, which waits for the job when the API answers 202) and downloads it. The snapshot stays in `snapshots.list` and counts on the manual snapshot quota. An API key needs the scopes `snapshots:write` (to take the snapshot) and `snapshots:read` (to download it); `apps:files` alone does not download. `wait_timeout` is the total wait for the snapshot (30 minutes by default), `interval` the poll interval and `timeout` the limit of each request; it raises what `snapshots.create_and_wait` raises. An account without a plan cannot take the snapshot, but can list and download the ones it has.
197
+
198
+ ```python
199
+ written = client.apps.download_to_file(
200
+ app_id, "backup.zip", wait_timeout=900, on_progress=lambda job: print(job["status"])
201
+ )
185
202
  ```
186
203
 
187
- `client.snapshots.download` works the same way.
204
+ `download_to_file` is the recommended form for anything that can be large (a snapshot of several GB is fine): the zip goes to a temporary file next to the destination, is renamed to the final name only when the download ends, and a failure, a stall (`timeout` without bytes), a connection cut before the announced `Content-Length` (`DownloadIncompleteError`, an `OSError`) or a `KeyboardInterrupt` removes the temporary file, so the destination never holds a partial file. The snapshot and app downloads take `workspace_id` like the rest, and send it on every call of the flow (take the snapshot, follow the job, download). `client.snapshots.download_to_file(resource_id, snapshot_id, scope, path)` does the same for an existing snapshot. `apps.download_stream` and `snapshots.download_stream` return an iterator of byte chunks (1 MiB at most) when you want to send the bytes somewhere other than a file; `apps.download` and `snapshots.download` return the whole zip as `bytes`.
188
205
 
189
206
  ### Waiting for the first build
190
207
 
@@ -216,6 +233,23 @@ finally:
216
233
 
217
234
  Stop the stream with `break` or `stream.close()`. Pass `since=` to resume. There is no automatic reconnection.
218
235
 
236
+ `event.event` is `logs`, `next_logs`, `system`, `metrics` or `heartbeat`. On a zero-downtime deploy, `next_logs` carries the output of the new version while it is prepared (same format as `logs`); the current version keeps writing to `logs`. Notes that already happened are sent again when the connection starts, as `<ISO 8601> <note>`; live notes have no prefix. New `system` notes: `install_note:build_oom` (the build ran out of memory) and `deploy_note:discarded:<release_id>[:<reason>]` (the new version was dropped and the current one keeps running; the reason is optional and new values may appear).
237
+
238
+ Pass `metrics=True` to also receive a `metrics` event about every 5 seconds while the app runs, with its live CPU, memory and network:
239
+
240
+ ```python
241
+ stream = client.apps.realtime(app_id, metrics=True)
242
+ try:
243
+ for event in stream:
244
+ if event.event == "metrics":
245
+ live = event.live_metrics() # APIApplicationLiveMetrics
246
+ print(live["cpu_percent"], live["memory_bytes"], live["net_rx_bps"])
247
+ finally:
248
+ stream.close()
249
+ ```
250
+
251
+ `client.apps.metrics` and `client.databases.metrics` return points with `events`: what happened between one point and the next (`restart`, `auto_restart` or `crash`, each with its `at` and `out_of_memory`).
252
+
219
253
  ### Blob Storage
220
254
 
221
255
  `client.blob` talks to the Blob Storage API (`blob_base_url`, default `https://blob.vertracloud.app/v1`) with the same API key (`blob:read` / `blob:write`). Every method accepts `workspace_id`.
@@ -332,7 +366,7 @@ if change["restart_required"]:
332
366
  print("restart:", change["apps_to_restart"])
333
367
  ```
334
368
 
335
- `delete` needs `confirm_name` equal to the stack name; mode `dissolve` removes only the stack, `delete_all` deletes the members too. `members`, `bindings` and `snapshots` group the routes of members, connections and whole-stack snapshots; `connection` returns code to connect an app to what it is linked to. Move a stack or a template to a workspace with `workspaces.stacks` and `workspaces.templates`. The error codes of both areas are constants in `vertracloud.errcodes`.
369
+ `delete` needs `confirm_name` equal to the stack name; mode `dissolve` removes only the stack (200). Mode `delete_all` deletes the members too. Both answer 200 right away with `{"deleted_apps", "deleted_databases", "deleted_blob"}` and are permanent: take a snapshot first (`stacks.snapshots.create`) if you may need the data again. `members`, `bindings` and `snapshots` group the routes of members, connections and whole-stack snapshots; `connection` returns code to connect an app to what it is linked to. Move a stack or a template to a workspace with `workspaces.stacks` and `workspaces.templates`. The error codes of both areas are constants in `vertracloud.errcodes`.
336
370
 
337
371
  ### Database versions
338
372
 
@@ -340,10 +374,17 @@ if change["restart_required"]:
340
374
  catalog = client.databases.versions() # keyed by engine type, as a string
341
375
  db = client.databases.create({"name": "meu-db", "type": 1, "ram": 512, "version": catalog["1"]["recommended"]})
342
376
  print(db["version"]) # major line, e.g. "18"
377
+ print(db["password"]) # returned only by this call
343
378
  ```
344
379
 
380
+ The password comes only in the `databases.create` response (and in `stacks.add_database`); afterwards `databases.credentials.password.reset` issues a new one.
381
+
382
+ A database with `legacy_host: True` still uses the previous address. Moving it to the current address (`databases.credentials.certificate.reset`) is done only from the dashboard: with an API key the call fails with 403 `WEBSITE_ONLY`.
383
+
345
384
  Omit `version` to get the recommended one; with `snapshot_id`, omit it to keep the snapshot's line (an older one fails with `SNAPSHOT_VERSION_NEWER`, an unknown one with `INVALID_DATABASE_VERSION`). A database's version cannot be changed after creation; security updates are applied when it is stopped and started.
346
385
 
386
+ With `snapshot_id` the database is created first (201) and the data comes back in the background: the answer has `restore_job_id`, to follow with `snapshot_jobs.wait(db["id"], db["restore_job_id"], "databases")`. If the restore fails, **the database is kept** (empty, or with what you wrote to it) and the job's `reason` says why. `apps.create` with `snapshot_id` also answers with `restore_job_id`; there an app of code whose restore fails is deleted by the API, while an app on a custom image is kept as it is.
387
+
347
388
  ### Plans and quotes
348
389
 
349
390
  ```python
@@ -358,6 +399,74 @@ print(quote["total"], quote["period_discount_percent"], quote["legacy_price"])
358
399
 
359
400
  `client.billing.orders.create` takes the same `plan` and `months`. `plan` is a `PlanName`: `starter-1`, `starter-2`, `pro-4`, `pro-6`, `pro-8`, `business-12`, `business-16`, `business-24` or `enterprise-32` up to `enterprise-512`.
360
401
 
402
+ ### Snapshots
403
+
404
+ Deleting an app (`apps.delete`) or a database (`databases.delete`), resetting a database (`databases.reset`) and restoring a snapshot (`snapshots.restore`) run right away and are permanent: they replace or remove the current data. If you may need it again, take a snapshot first. `apps.delete` returns `None`, `databases.delete` returns the database id, `databases.reset` returns `{"status": "success"}` and `snapshots.restore` returns `{"job_id": ..., "warning"?: ...}`.
405
+
406
+ ```python
407
+ client.snapshots.create_and_wait(db_id, "databases")
408
+ client.databases.reset(db_id)
409
+ ```
410
+
411
+ `snapshots.create` can take up to 90 seconds, so its timeout is 120 s (the client's, if larger) and `timeout=` overrides it per call. Creating snapshots is limited: a quota over a rolling 24 hours that depends on the plan's RAM, and a wait between snapshots of the same resource (and a 5 s pause per user, answered with a plain `RATE_LIMIT_EXCEEDED` 429). Over a snapshot limit the call fails with `SNAPSHOT_RATE_LIMITED` (429) and `RateLimitError.retry_after` is the number of seconds to wait; `err.details` has the `scope` (`resource` or `account`) and, for `account`, `resets_at`. A manual snapshot can also answer 202 (`OPERATION_IN_PROGRESS` carries `details.job_id` when one of the same resource is already running) with `{"job_id": ...}` instead of a snapshot: it is still being taken. `snapshots.create` makes one request and returns either; `snapshots.create_and_wait` follows the job (below) and returns the snapshot. Other codes are constants in `vertracloud.errcodes` (`SNAPSHOT_TOO_LARGE` carries `details.max_bytes`).
412
+
413
+ #### Restore as a job
414
+
415
+ `snapshots.restore` answers 202: the restore runs in the background, so it returns `{"job_id": ..., "warning"?: ...}` and the resource is not restored yet. Follow the job with `client.snapshot_jobs`:
416
+
417
+ ```python
418
+ from vertracloud import SnapshotJobFailedError, SnapshotJobSkippedError, SnapshotJobTimeoutError
419
+
420
+ accepted = client.snapshots.restore(app_id, snapshot_id, "applications", restore_image_version=True)
421
+ if accepted.get("warning"):
422
+ print(accepted["warning"]) # IMAGE_VERSION_NOT_FOUND: only the data is restored
423
+
424
+ job = client.snapshot_jobs.get(app_id, accepted["job_id"]) # one look; `scope` is optional here
425
+ print(job["status"]) # queued, running, ready, skipped or failed
426
+
427
+ # on_progress runs on every poll while the job has not ended; job["progress"] exists only while it is running
428
+ # (phase, percent?, done_bytes?, total_bytes?, eta_seconds?)
429
+ show = lambda job: print(job["status"], job.get("progress")) # noqa: E731
430
+
431
+ try:
432
+ job = client.snapshot_jobs.wait(
433
+ app_id, accepted["job_id"], "applications", wait_timeout=900, interval=2, on_progress=show
434
+ )
435
+ except (SnapshotJobFailedError, SnapshotJobSkippedError) as err:
436
+ print(err.code, err.details) # the job's public reason, e.g. SNAPSHOT_CORRUPTED; err.job is the last payload
437
+ except SnapshotJobTimeoutError:
438
+ ... # still running; the job is not cancelled
439
+
440
+ recent = client.snapshot_jobs.list(app_id, "applications", kind="restore", limit=5) # limit 1 to 50
441
+ ```
442
+
443
+ `stacks.snapshots.create` also answers 202, with `{"id": ..., "jobs": [{"resource_id", "resource_type", "job_id"}, ...]}`: one snapshot job per member (databases first), each a regular manual snapshot. The stack snapshot is listed as `pending` and becomes `ready` when the last job ends. Follow the jobs with `snapshot_jobs`, let `wait_for_create` do it under one `wait_timeout` (same outcomes as `wait_for_restore`) or call `stacks.snapshots.create_and_wait(stack_id)`, which resolves with the accepted answer plus `finished`, the final job of each member.
444
+
445
+ `stacks.snapshots.restore` also answers 202, with `{"jobs": [{"resource_id", "resource_type", "job_id", "warning"?}, ...]}`: one job per member (`warning` is `IMAGE_VERSION_NOT_FOUND` for an application whose recorded image version is gone), restored in series by the server (databases first). The stack is back when every job is `ready`; when a member fails, the jobs after it end `failed` with `STACK_RESTORE_MEMBER_FAILED`. A refusal before the queue keeps the code and `details` of the member. Follow each job with `snapshot_jobs` (scope `"databases"` or `"applications"` by `resource_type`) let `wait_for_restore` do it under one `wait_timeout`, or call `stacks.snapshots.restore_and_wait(stack_id, snapshot_id)`:
446
+
447
+ ```python
448
+ accepted = client.stacks.snapshots.restore(stack_id, snapshot_id)
449
+ try:
450
+ finished = client.stacks.snapshots.wait_for_restore(accepted, wait_timeout=1800, interval=2)
451
+ except SnapshotJobFailedError as err:
452
+ print(err.code, err.job) # the first failed member (STACK_RESTORE_MEMBER_FAILED for the ones behind it)
453
+ ```
454
+
455
+ `wait` is optional: it polls `get` until the job ends and returns the job when it is `ready`. It raises `SnapshotJobFailedError` or `SnapshotJobSkippedError` (`code` and `reason` = the job's `reason`, `details`, `job` = the last payload) when it ends any other way, and `SnapshotJobTimeoutError` (with the last `job`) after `wait_timeout`, the total wait (30 minutes by default); `timeout` is the limit of each request. `create_and_wait`, `wait_for_create`/`wait_for_restore`, `restore_and_wait` and `apps.download` behave the same. The `:id` of both routes is the resource the job acts on; `scope` is required to list and optional to get or wait for one job. While a restore runs every write to the resource fails with `RESTORE_IN_PROGRESS` (409); reads and deleting it still work. Before queueing, the API can refuse with `SNAPSHOT_EXCEEDS_STORAGE` (400; `err.snapshot_exceeds_storage` has `required_bytes`, `available_bytes` and, for databases, `required_ram_mb`), `APP_BUILDING` (409), `RESTORE_IN_PROGRESS` or `RESTORE_COOLDOWN` (429: the wait between restores or rollbacks, `RateLimitError.retry_after`, also in the `Retry-After` header). While a snapshot of an app is being taken, deploys, rollbacks, restarts, stops, environment changes and writes of the file manager fail with `OPERATION_IN_PROGRESS` (409): try again shortly.
456
+
457
+ #### Wait helpers
458
+
459
+ One pattern: `wait_for_<x>` follows something already started, `<verb>_and_wait` starts it and follows it. In all of them `wait_timeout` is the total wait (30 minutes by default), `timeout` the limit of each request and `interval` the poll interval; the work keeps running on the server after a timeout.
460
+
461
+ | Start | Follow | Both |
462
+ |---|---|---|
463
+ | `snapshots.create` | `snapshot_jobs.wait(resource_id, job_id)` | `snapshots.create_and_wait`, `apps.download` (also downloads the zip) |
464
+ | `snapshots.restore` | `snapshot_jobs.wait(resource_id, job_id)` | none |
465
+ | `stacks.snapshots.create` | `stacks.snapshots.wait_for_create(accepted)` | `stacks.snapshots.create_and_wait` |
466
+ | `stacks.snapshots.restore` | `stacks.snapshots.wait_for_restore(accepted)` | `stacks.snapshots.restore_and_wait` |
467
+
468
+ `apps.wait_until_ready(app_id, timeout=...)` keeps its `timeout` as the total wait for the build.
469
+
361
470
  ### Errors
362
471
 
363
472
  Every non-2xx response raises a `VertraAPIError` carrying the HTTP `status`, the API `code` (e.g. `APP_NOT_FOUND`) and `details`; `str(err)` includes the message. The API key is never part of the error, even when it is printed:
@@ -377,6 +486,8 @@ except VertraAPIError as err:
377
486
 
378
487
  A few errors carry a structured `details`; tolerant properties read them and give an empty value for any other error: `err.issues` (`DOCKERFILE_REFUSED`), `err.manifest_issues` (`TEMPLATE_MANIFEST_INVALID`), `err.secret_files` (`TEMPLATE_SECRET_IN_SOURCE`), `err.update_blocked` (`TEMPLATE_UPDATE_BLOCKED`) and `err.detach_action` (`TEMPLATE_DETACH_CONFIRMATION_REQUIRED`).
379
488
 
489
+ `apps.files.read` and `apps.files.write` handle files up to 10 MiB; above it the call fails with `FILE_TOO_LARGE` (413) and `details.max_bytes` is the limit.
490
+
380
491
  Other subclasses: `AuthenticationError` (401), `ScopeDeniedError` (403 — including a missing key scope) and `ValidationError` (400/422). The error codes are listed in the [API reference](https://docs.vertracloud.app/api-reference/introduction).
381
492
 
382
493
  ### Testing your code
@@ -396,7 +507,7 @@ client = VertraClient(api_key="test", transport=my_fake_transport)
396
507
  | Custom images | `client.images` | 13 |
397
508
  | Templates | `client.templates` (+ `.deploys`, `.share_links`, `.share`, `.updates`) | 32 |
398
509
  | Stacks | `client.stacks` (+ `.members`, `.bindings`, `.snapshots`) | 20 |
399
- | Snapshots | `client.snapshots` | 5 |
510
+ | Snapshots | `client.snapshots`, `client.snapshot_jobs` | 5 + 2 |
400
511
  | Account | `client.account` (+ `.sessions`, `.folders`, `.favorites`) | 10 |
401
512
  | Workspaces | `client.workspaces` (+ `.members`, `.roles`, `.invites`, `.action_requests`, `.apps`, `.databases`, `.templates`, `.stacks`, `.folders`, `.favorites`) | 34 |
402
513
  | Billing | `client.billing` (+ `.orders`, with `orders.quote`) | 8 |
@@ -57,14 +57,14 @@ client = VertraClient(
57
57
 
58
58
  ### Per-call options
59
59
 
60
- Methods on apps, databases, images, templates and stacks take a keyword-only `workspace_id`; downloads, uploads and streams also take `timeout`:
60
+ Methods on apps, databases, images, templates and stacks take a keyword-only `workspace_id`; downloads, uploads and streams also take `timeout` (the limit of each request, never a total wait; the `wait_timeout` of the `*_and_wait` and `wait_for_*` helpers is the total):
61
61
 
62
62
  ```python
63
63
  # Act on a resource that belongs to a workspace
64
64
  app = client.apps.get(app_id, workspace_id=workspace_id)
65
65
 
66
66
  # Give one slow call more time
67
- zip_bytes = client.apps.download(app_id, timeout=300)
67
+ zip_bytes = client.apps.download(app_id, timeout=300) # per request; the wait for the snapshot is `wait_timeout`
68
68
  ```
69
69
 
70
70
  Nested resources are attributes: `client.apps.deploys`, `client.apps.releases`, `client.apps.envs`, `client.workspaces.members`, `client.billing.orders`, …
@@ -129,6 +129,14 @@ client.apps.update_config(app_id, {"deploy": {"health_check_path": None}}) # cl
129
129
 
130
130
  `client.apps.files.upload(..., message="...")` sets the message shown in the release history.
131
131
 
132
+ Automatic restart is set at creation (`client.apps.create({"name": "x", "auto_restart": False}, file=zip_bytes)`; omitted, it is on) and afterwards with `update_config`, applied right away without a restart or reinstall:
133
+
134
+ ```python
135
+ client.apps.update_config(app_id, {"auto_restart": False})
136
+ ```
137
+
138
+ `client.apps.files.delete` answers `{"space_released": "now" | "on_restart"}`: `on_restart` means the file was still open and the space returns at the next restart.
139
+
132
140
  ### Web Analytics
133
141
 
134
142
  Traffic, errors, performance and the request log of an app's site (scope `apps:read`). Every call takes a window (`start`, `end`, ISO 8601; at most 30 days, within the plan's `limits.web_analytics_history_days`) and one keyword per dimension to filter by (`country`, `edge_location`, `host`, `path` as a prefix, `method`, `status` or a class such as `5xx`, `protocol`, `device`, `os`, `browser`, `referer`, `asn`, `ip`, `content_type`, `cache_status`, `bot`). A `value` of a breakdown entry can be sent back as the filter unchanged; `"(none)"` filters the requests that had no value.
@@ -155,17 +163,26 @@ An app with no site published answers `web_published: False` and empty data. `PL
155
163
 
156
164
  ### Uploading and downloading
157
165
 
158
- Uploads take `bytes`; downloads return `bytes`.
166
+ Uploads take `bytes`. To download, use `download_to_file`, which writes to disk as the bytes arrive and keeps memory constant whatever the size; `download` returns `bytes` and holds the whole file in memory, so keep it for small files.
159
167
 
160
168
  ```python
161
169
  with open("app.zip", "rb") as f:
162
170
  app = client.apps.create({"name": "my-app", "memory": 512}, file=f.read())
163
171
 
164
- with open("backup.zip", "wb") as f:
165
- f.write(client.apps.download(app_id))
172
+ written = client.apps.download_to_file(app_id, "backup.zip") # bytes written
173
+ ```
174
+
175
+ `client.snapshots.download(resource_id, snapshot_id, scope)` downloads one snapshot of an app or a database as `bytes`. It has no total deadline: `timeout` (30 s by default) is the wait of each socket operation, so a large file that keeps arriving completes however long it takes, and one that stops sending bytes fails after `timeout`.
176
+
177
+ `apps.download` downloads the whole app as a zip: it takes a manual snapshot (`snapshots.create_and_wait`, which waits for the job when the API answers 202) and downloads it. The snapshot stays in `snapshots.list` and counts on the manual snapshot quota. An API key needs the scopes `snapshots:write` (to take the snapshot) and `snapshots:read` (to download it); `apps:files` alone does not download. `wait_timeout` is the total wait for the snapshot (30 minutes by default), `interval` the poll interval and `timeout` the limit of each request; it raises what `snapshots.create_and_wait` raises. An account without a plan cannot take the snapshot, but can list and download the ones it has.
178
+
179
+ ```python
180
+ written = client.apps.download_to_file(
181
+ app_id, "backup.zip", wait_timeout=900, on_progress=lambda job: print(job["status"])
182
+ )
166
183
  ```
167
184
 
168
- `client.snapshots.download` works the same way.
185
+ `download_to_file` is the recommended form for anything that can be large (a snapshot of several GB is fine): the zip goes to a temporary file next to the destination, is renamed to the final name only when the download ends, and a failure, a stall (`timeout` without bytes), a connection cut before the announced `Content-Length` (`DownloadIncompleteError`, an `OSError`) or a `KeyboardInterrupt` removes the temporary file, so the destination never holds a partial file. The snapshot and app downloads take `workspace_id` like the rest, and send it on every call of the flow (take the snapshot, follow the job, download). `client.snapshots.download_to_file(resource_id, snapshot_id, scope, path)` does the same for an existing snapshot. `apps.download_stream` and `snapshots.download_stream` return an iterator of byte chunks (1 MiB at most) when you want to send the bytes somewhere other than a file; `apps.download` and `snapshots.download` return the whole zip as `bytes`.
169
186
 
170
187
  ### Waiting for the first build
171
188
 
@@ -197,6 +214,23 @@ finally:
197
214
 
198
215
  Stop the stream with `break` or `stream.close()`. Pass `since=` to resume. There is no automatic reconnection.
199
216
 
217
+ `event.event` is `logs`, `next_logs`, `system`, `metrics` or `heartbeat`. On a zero-downtime deploy, `next_logs` carries the output of the new version while it is prepared (same format as `logs`); the current version keeps writing to `logs`. Notes that already happened are sent again when the connection starts, as `<ISO 8601> <note>`; live notes have no prefix. New `system` notes: `install_note:build_oom` (the build ran out of memory) and `deploy_note:discarded:<release_id>[:<reason>]` (the new version was dropped and the current one keeps running; the reason is optional and new values may appear).
218
+
219
+ Pass `metrics=True` to also receive a `metrics` event about every 5 seconds while the app runs, with its live CPU, memory and network:
220
+
221
+ ```python
222
+ stream = client.apps.realtime(app_id, metrics=True)
223
+ try:
224
+ for event in stream:
225
+ if event.event == "metrics":
226
+ live = event.live_metrics() # APIApplicationLiveMetrics
227
+ print(live["cpu_percent"], live["memory_bytes"], live["net_rx_bps"])
228
+ finally:
229
+ stream.close()
230
+ ```
231
+
232
+ `client.apps.metrics` and `client.databases.metrics` return points with `events`: what happened between one point and the next (`restart`, `auto_restart` or `crash`, each with its `at` and `out_of_memory`).
233
+
200
234
  ### Blob Storage
201
235
 
202
236
  `client.blob` talks to the Blob Storage API (`blob_base_url`, default `https://blob.vertracloud.app/v1`) with the same API key (`blob:read` / `blob:write`). Every method accepts `workspace_id`.
@@ -313,7 +347,7 @@ if change["restart_required"]:
313
347
  print("restart:", change["apps_to_restart"])
314
348
  ```
315
349
 
316
- `delete` needs `confirm_name` equal to the stack name; mode `dissolve` removes only the stack, `delete_all` deletes the members too. `members`, `bindings` and `snapshots` group the routes of members, connections and whole-stack snapshots; `connection` returns code to connect an app to what it is linked to. Move a stack or a template to a workspace with `workspaces.stacks` and `workspaces.templates`. The error codes of both areas are constants in `vertracloud.errcodes`.
350
+ `delete` needs `confirm_name` equal to the stack name; mode `dissolve` removes only the stack (200). Mode `delete_all` deletes the members too. Both answer 200 right away with `{"deleted_apps", "deleted_databases", "deleted_blob"}` and are permanent: take a snapshot first (`stacks.snapshots.create`) if you may need the data again. `members`, `bindings` and `snapshots` group the routes of members, connections and whole-stack snapshots; `connection` returns code to connect an app to what it is linked to. Move a stack or a template to a workspace with `workspaces.stacks` and `workspaces.templates`. The error codes of both areas are constants in `vertracloud.errcodes`.
317
351
 
318
352
  ### Database versions
319
353
 
@@ -321,10 +355,17 @@ if change["restart_required"]:
321
355
  catalog = client.databases.versions() # keyed by engine type, as a string
322
356
  db = client.databases.create({"name": "meu-db", "type": 1, "ram": 512, "version": catalog["1"]["recommended"]})
323
357
  print(db["version"]) # major line, e.g. "18"
358
+ print(db["password"]) # returned only by this call
324
359
  ```
325
360
 
361
+ The password comes only in the `databases.create` response (and in `stacks.add_database`); afterwards `databases.credentials.password.reset` issues a new one.
362
+
363
+ A database with `legacy_host: True` still uses the previous address. Moving it to the current address (`databases.credentials.certificate.reset`) is done only from the dashboard: with an API key the call fails with 403 `WEBSITE_ONLY`.
364
+
326
365
  Omit `version` to get the recommended one; with `snapshot_id`, omit it to keep the snapshot's line (an older one fails with `SNAPSHOT_VERSION_NEWER`, an unknown one with `INVALID_DATABASE_VERSION`). A database's version cannot be changed after creation; security updates are applied when it is stopped and started.
327
366
 
367
+ With `snapshot_id` the database is created first (201) and the data comes back in the background: the answer has `restore_job_id`, to follow with `snapshot_jobs.wait(db["id"], db["restore_job_id"], "databases")`. If the restore fails, **the database is kept** (empty, or with what you wrote to it) and the job's `reason` says why. `apps.create` with `snapshot_id` also answers with `restore_job_id`; there an app of code whose restore fails is deleted by the API, while an app on a custom image is kept as it is.
368
+
328
369
  ### Plans and quotes
329
370
 
330
371
  ```python
@@ -339,6 +380,74 @@ print(quote["total"], quote["period_discount_percent"], quote["legacy_price"])
339
380
 
340
381
  `client.billing.orders.create` takes the same `plan` and `months`. `plan` is a `PlanName`: `starter-1`, `starter-2`, `pro-4`, `pro-6`, `pro-8`, `business-12`, `business-16`, `business-24` or `enterprise-32` up to `enterprise-512`.
341
382
 
383
+ ### Snapshots
384
+
385
+ Deleting an app (`apps.delete`) or a database (`databases.delete`), resetting a database (`databases.reset`) and restoring a snapshot (`snapshots.restore`) run right away and are permanent: they replace or remove the current data. If you may need it again, take a snapshot first. `apps.delete` returns `None`, `databases.delete` returns the database id, `databases.reset` returns `{"status": "success"}` and `snapshots.restore` returns `{"job_id": ..., "warning"?: ...}`.
386
+
387
+ ```python
388
+ client.snapshots.create_and_wait(db_id, "databases")
389
+ client.databases.reset(db_id)
390
+ ```
391
+
392
+ `snapshots.create` can take up to 90 seconds, so its timeout is 120 s (the client's, if larger) and `timeout=` overrides it per call. Creating snapshots is limited: a quota over a rolling 24 hours that depends on the plan's RAM, and a wait between snapshots of the same resource (and a 5 s pause per user, answered with a plain `RATE_LIMIT_EXCEEDED` 429). Over a snapshot limit the call fails with `SNAPSHOT_RATE_LIMITED` (429) and `RateLimitError.retry_after` is the number of seconds to wait; `err.details` has the `scope` (`resource` or `account`) and, for `account`, `resets_at`. A manual snapshot can also answer 202 (`OPERATION_IN_PROGRESS` carries `details.job_id` when one of the same resource is already running) with `{"job_id": ...}` instead of a snapshot: it is still being taken. `snapshots.create` makes one request and returns either; `snapshots.create_and_wait` follows the job (below) and returns the snapshot. Other codes are constants in `vertracloud.errcodes` (`SNAPSHOT_TOO_LARGE` carries `details.max_bytes`).
393
+
394
+ #### Restore as a job
395
+
396
+ `snapshots.restore` answers 202: the restore runs in the background, so it returns `{"job_id": ..., "warning"?: ...}` and the resource is not restored yet. Follow the job with `client.snapshot_jobs`:
397
+
398
+ ```python
399
+ from vertracloud import SnapshotJobFailedError, SnapshotJobSkippedError, SnapshotJobTimeoutError
400
+
401
+ accepted = client.snapshots.restore(app_id, snapshot_id, "applications", restore_image_version=True)
402
+ if accepted.get("warning"):
403
+ print(accepted["warning"]) # IMAGE_VERSION_NOT_FOUND: only the data is restored
404
+
405
+ job = client.snapshot_jobs.get(app_id, accepted["job_id"]) # one look; `scope` is optional here
406
+ print(job["status"]) # queued, running, ready, skipped or failed
407
+
408
+ # on_progress runs on every poll while the job has not ended; job["progress"] exists only while it is running
409
+ # (phase, percent?, done_bytes?, total_bytes?, eta_seconds?)
410
+ show = lambda job: print(job["status"], job.get("progress")) # noqa: E731
411
+
412
+ try:
413
+ job = client.snapshot_jobs.wait(
414
+ app_id, accepted["job_id"], "applications", wait_timeout=900, interval=2, on_progress=show
415
+ )
416
+ except (SnapshotJobFailedError, SnapshotJobSkippedError) as err:
417
+ print(err.code, err.details) # the job's public reason, e.g. SNAPSHOT_CORRUPTED; err.job is the last payload
418
+ except SnapshotJobTimeoutError:
419
+ ... # still running; the job is not cancelled
420
+
421
+ recent = client.snapshot_jobs.list(app_id, "applications", kind="restore", limit=5) # limit 1 to 50
422
+ ```
423
+
424
+ `stacks.snapshots.create` also answers 202, with `{"id": ..., "jobs": [{"resource_id", "resource_type", "job_id"}, ...]}`: one snapshot job per member (databases first), each a regular manual snapshot. The stack snapshot is listed as `pending` and becomes `ready` when the last job ends. Follow the jobs with `snapshot_jobs`, let `wait_for_create` do it under one `wait_timeout` (same outcomes as `wait_for_restore`) or call `stacks.snapshots.create_and_wait(stack_id)`, which resolves with the accepted answer plus `finished`, the final job of each member.
425
+
426
+ `stacks.snapshots.restore` also answers 202, with `{"jobs": [{"resource_id", "resource_type", "job_id", "warning"?}, ...]}`: one job per member (`warning` is `IMAGE_VERSION_NOT_FOUND` for an application whose recorded image version is gone), restored in series by the server (databases first). The stack is back when every job is `ready`; when a member fails, the jobs after it end `failed` with `STACK_RESTORE_MEMBER_FAILED`. A refusal before the queue keeps the code and `details` of the member. Follow each job with `snapshot_jobs` (scope `"databases"` or `"applications"` by `resource_type`) let `wait_for_restore` do it under one `wait_timeout`, or call `stacks.snapshots.restore_and_wait(stack_id, snapshot_id)`:
427
+
428
+ ```python
429
+ accepted = client.stacks.snapshots.restore(stack_id, snapshot_id)
430
+ try:
431
+ finished = client.stacks.snapshots.wait_for_restore(accepted, wait_timeout=1800, interval=2)
432
+ except SnapshotJobFailedError as err:
433
+ print(err.code, err.job) # the first failed member (STACK_RESTORE_MEMBER_FAILED for the ones behind it)
434
+ ```
435
+
436
+ `wait` is optional: it polls `get` until the job ends and returns the job when it is `ready`. It raises `SnapshotJobFailedError` or `SnapshotJobSkippedError` (`code` and `reason` = the job's `reason`, `details`, `job` = the last payload) when it ends any other way, and `SnapshotJobTimeoutError` (with the last `job`) after `wait_timeout`, the total wait (30 minutes by default); `timeout` is the limit of each request. `create_and_wait`, `wait_for_create`/`wait_for_restore`, `restore_and_wait` and `apps.download` behave the same. The `:id` of both routes is the resource the job acts on; `scope` is required to list and optional to get or wait for one job. While a restore runs every write to the resource fails with `RESTORE_IN_PROGRESS` (409); reads and deleting it still work. Before queueing, the API can refuse with `SNAPSHOT_EXCEEDS_STORAGE` (400; `err.snapshot_exceeds_storage` has `required_bytes`, `available_bytes` and, for databases, `required_ram_mb`), `APP_BUILDING` (409), `RESTORE_IN_PROGRESS` or `RESTORE_COOLDOWN` (429: the wait between restores or rollbacks, `RateLimitError.retry_after`, also in the `Retry-After` header). While a snapshot of an app is being taken, deploys, rollbacks, restarts, stops, environment changes and writes of the file manager fail with `OPERATION_IN_PROGRESS` (409): try again shortly.
437
+
438
+ #### Wait helpers
439
+
440
+ One pattern: `wait_for_<x>` follows something already started, `<verb>_and_wait` starts it and follows it. In all of them `wait_timeout` is the total wait (30 minutes by default), `timeout` the limit of each request and `interval` the poll interval; the work keeps running on the server after a timeout.
441
+
442
+ | Start | Follow | Both |
443
+ |---|---|---|
444
+ | `snapshots.create` | `snapshot_jobs.wait(resource_id, job_id)` | `snapshots.create_and_wait`, `apps.download` (also downloads the zip) |
445
+ | `snapshots.restore` | `snapshot_jobs.wait(resource_id, job_id)` | none |
446
+ | `stacks.snapshots.create` | `stacks.snapshots.wait_for_create(accepted)` | `stacks.snapshots.create_and_wait` |
447
+ | `stacks.snapshots.restore` | `stacks.snapshots.wait_for_restore(accepted)` | `stacks.snapshots.restore_and_wait` |
448
+
449
+ `apps.wait_until_ready(app_id, timeout=...)` keeps its `timeout` as the total wait for the build.
450
+
342
451
  ### Errors
343
452
 
344
453
  Every non-2xx response raises a `VertraAPIError` carrying the HTTP `status`, the API `code` (e.g. `APP_NOT_FOUND`) and `details`; `str(err)` includes the message. The API key is never part of the error, even when it is printed:
@@ -358,6 +467,8 @@ except VertraAPIError as err:
358
467
 
359
468
  A few errors carry a structured `details`; tolerant properties read them and give an empty value for any other error: `err.issues` (`DOCKERFILE_REFUSED`), `err.manifest_issues` (`TEMPLATE_MANIFEST_INVALID`), `err.secret_files` (`TEMPLATE_SECRET_IN_SOURCE`), `err.update_blocked` (`TEMPLATE_UPDATE_BLOCKED`) and `err.detach_action` (`TEMPLATE_DETACH_CONFIRMATION_REQUIRED`).
360
469
 
470
+ `apps.files.read` and `apps.files.write` handle files up to 10 MiB; above it the call fails with `FILE_TOO_LARGE` (413) and `details.max_bytes` is the limit.
471
+
361
472
  Other subclasses: `AuthenticationError` (401), `ScopeDeniedError` (403 — including a missing key scope) and `ValidationError` (400/422). The error codes are listed in the [API reference](https://docs.vertracloud.app/api-reference/introduction).
362
473
 
363
474
  ### Testing your code
@@ -377,7 +488,7 @@ client = VertraClient(api_key="test", transport=my_fake_transport)
377
488
  | Custom images | `client.images` | 13 |
378
489
  | Templates | `client.templates` (+ `.deploys`, `.share_links`, `.share`, `.updates`) | 32 |
379
490
  | Stacks | `client.stacks` (+ `.members`, `.bindings`, `.snapshots`) | 20 |
380
- | Snapshots | `client.snapshots` | 5 |
491
+ | Snapshots | `client.snapshots`, `client.snapshot_jobs` | 5 + 2 |
381
492
  | Account | `client.account` (+ `.sessions`, `.folders`, `.favorites`) | 10 |
382
493
  | Workspaces | `client.workspaces` (+ `.members`, `.roles`, `.invites`, `.action_requests`, `.apps`, `.databases`, `.templates`, `.stacks`, `.folders`, `.favorites`) | 34 |
383
494
  | Billing | `client.billing` (+ `.orders`, with `orders.quote`) | 8 |
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "vertracloud-api"
7
- version = "0.4.2"
7
+ version = "0.4.4"
8
8
  description = "Official Python SDK for the public API of Vertra Cloud, a Brazilian application hosting platform (PaaS)."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -6,9 +6,14 @@ from .errors import (
6
6
  AppBuildFailedError,
7
7
  AppNotReadyError,
8
8
  AuthenticationError,
9
+ DownloadIncompleteError,
9
10
  NotFoundError,
10
11
  RateLimitError,
11
12
  ScopeDeniedError,
13
+ SnapshotJobError,
14
+ SnapshotJobFailedError,
15
+ SnapshotJobSkippedError,
16
+ SnapshotJobTimeoutError,
12
17
  ValidationError,
13
18
  VertraAPIError,
14
19
  WaitTimeoutError,
@@ -24,7 +29,12 @@ __all__ = [
24
29
  "AppNotReadyError",
25
30
  "AppBuildFailedError",
26
31
  "WaitTimeoutError",
32
+ "SnapshotJobError",
33
+ "SnapshotJobFailedError",
34
+ "SnapshotJobSkippedError",
35
+ "SnapshotJobTimeoutError",
27
36
  "AuthenticationError",
37
+ "DownloadIncompleteError",
28
38
  "ScopeDeniedError",
29
39
  "NotFoundError",
30
40
  "ValidationError",