hot-dev 1.1.2__tar.gz → 1.2.0__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 (32) hide show
  1. {hot_dev-1.1.2 → hot_dev-1.2.0}/.github/workflows/ci.yml +23 -0
  2. hot_dev-1.2.0/AGENTS.md +73 -0
  3. {hot_dev-1.1.2 → hot_dev-1.2.0}/LICENSE +14 -2
  4. hot_dev-1.2.0/NOTICE +2 -0
  5. {hot_dev-1.1.2 → hot_dev-1.2.0}/PKG-INFO +36 -7
  6. {hot_dev-1.1.2 → hot_dev-1.2.0}/README.md +34 -6
  7. hot_dev-1.2.0/integration/fixture/.env.example +3 -0
  8. hot_dev-1.2.0/integration/fixture/.gitignore +5 -0
  9. hot_dev-1.2.0/integration/fixture/hot/src/fixture/sdk.hot +56 -0
  10. hot_dev-1.2.0/integration/fixture/hot.hot +22 -0
  11. hot_dev-1.2.0/integration/mint_key.py +42 -0
  12. hot_dev-1.2.0/integration/run.sh +44 -0
  13. {hot_dev-1.1.2 → hot_dev-1.2.0}/pyproject.toml +1 -1
  14. {hot_dev-1.1.2 → hot_dev-1.2.0}/src/hot/__init__.py +3 -1
  15. {hot_dev-1.1.2 → hot_dev-1.2.0}/src/hot/_transport.py +61 -18
  16. {hot_dev-1.1.2 → hot_dev-1.2.0}/src/hot/client.py +4 -0
  17. {hot_dev-1.1.2 → hot_dev-1.2.0}/src/hot/errors.py +33 -0
  18. {hot_dev-1.1.2 → hot_dev-1.2.0}/src/hot/resources.py +583 -90
  19. {hot_dev-1.1.2 → hot_dev-1.2.0}/tests/openapi_operations.json +3 -0
  20. {hot_dev-1.1.2 → hot_dev-1.2.0}/tests/test_client.py +90 -10
  21. hot_dev-1.2.0/tests/test_integration.py +120 -0
  22. {hot_dev-1.1.2 → hot_dev-1.2.0}/tests/test_openapi_coverage.py +3 -0
  23. {hot_dev-1.1.2 → hot_dev-1.2.0}/tests/test_reconnect.py +19 -33
  24. hot_dev-1.2.0/tests/test_runs.py +84 -0
  25. hot_dev-1.2.0/tests/test_tasks.py +79 -0
  26. hot_dev-1.1.2/AGENTS.md +0 -43
  27. {hot_dev-1.1.2 → hot_dev-1.2.0}/.github/workflows/release.yml +0 -0
  28. {hot_dev-1.1.2 → hot_dev-1.2.0}/.gitignore +0 -0
  29. {hot_dev-1.1.2 → hot_dev-1.2.0}/src/hot/py.typed +0 -0
  30. {hot_dev-1.1.2 → hot_dev-1.2.0}/src/hot/sse.py +0 -0
  31. {hot_dev-1.1.2 → hot_dev-1.2.0}/src/hot/types.py +0 -0
  32. {hot_dev-1.1.2 → hot_dev-1.2.0}/tests/test_resources.py +0 -0
@@ -40,3 +40,26 @@ jobs:
40
40
 
41
41
  - name: Build
42
42
  run: python -m build
43
+
44
+ integration:
45
+ name: Integration (hot dev)
46
+ runs-on: ubuntu-latest
47
+ steps:
48
+ - name: Checkout
49
+ uses: actions/checkout@v4
50
+
51
+ - name: Set up Python
52
+ uses: actions/setup-python@v5
53
+ with:
54
+ python-version: "3.13"
55
+
56
+ - name: Install package
57
+ run: |
58
+ python -m venv .venv
59
+ .venv/bin/python -m pip install -e ".[dev]"
60
+
61
+ - name: Install hot
62
+ uses: hot-dev/setup-hot@v1
63
+
64
+ - name: Run integration tests
65
+ run: ./integration/run.sh
@@ -0,0 +1,73 @@
1
+ # AGENTS.md - hot-python
2
+
3
+ This repo contains the Python SDK for the Hot Dev API.
4
+
5
+ ## Package Shape
6
+
7
+ - PyPI distribution name: `hot-dev`
8
+ - Python import package: `hot`
9
+ - Source layout: `src/hot/`, with `py.typed` marker
10
+ - Runtime dependency: `httpx`
11
+ - Versioning follows the public API package version, starting at `1.0.0`.
12
+
13
+ ## Commands
14
+
15
+ ```bash
16
+ python -m pip install -e ".[dev]"
17
+ ruff check .
18
+ pytest
19
+ python -m build
20
+ ```
21
+
22
+ ## CI and Releases
23
+
24
+ - CI runs on pushes and pull requests to `main`: install, lint (`ruff`), test
25
+ (`pytest`), and build (`python -m build`) on Python 3.10–3.13.
26
+ - PyPI releases run from tags named `v<version>` matching the
27
+ `pyproject.toml` version.
28
+ - Publishing uses PyPI Trusted Publishing via OIDC against the `pypi` GitHub
29
+ Actions environment — no PyPI token secret is required, but the project
30
+ publisher must be configured on PyPI before the first tag push.
31
+
32
+ Release flow:
33
+
34
+ ```bash
35
+ # Bump the version in pyproject.toml.
36
+ git add pyproject.toml
37
+ git commit -m "release v<version>"
38
+ git tag v<version>
39
+ git push origin main v<version>
40
+ ```
41
+
42
+ Always update the SDK version in lockstep with new API surface area added to
43
+ the matching `@hot-dev/sdk` JavaScript release when possible.
44
+
45
+ ## Integration Tests
46
+
47
+ `integration/run.sh` starts a scratch `hot dev` (requires the `hot` CLI and
48
+ python3 on PATH) serving the Hot fixture project in `integration/fixture`
49
+ (project `sdk-fixture`: an echo event handler, an always-failing handler and
50
+ function, and hot:call targets). It binds 127.0.0.1 on HOT_TEST_PORT (default
51
+ 4725), mints a full-access API key directly in the fixture's sqlite database,
52
+ exports HOT_TEST_BASE_URL / HOT_TEST_API_KEY, and runs `pytest tests/test_integration.py`.
53
+ The integration tests skip when HOT_TEST_API_KEY is unset, so regular test
54
+ runs are unaffected. The fixture pins the API to 127.0.0.1 because binding
55
+ "localhost" can yield an IPv6-only listener that JDK-style clients (which
56
+ dial the first resolved address only) cannot reach.
57
+
58
+ ## Lockstep Releases
59
+
60
+ All five SDK repos (hot-js, hot-python, hot-go, hot-rust, hot-java) release in
61
+ lockstep. Checklist for a coordinated release:
62
+
63
+ 1. Bump every SDK's version: js `npm version` (syncs src/version.ts via the
64
+ `version` script), python pyproject.toml, rust Cargo.toml, java
65
+ gradle.properties + README snippets, go `Version` constant in client.go.
66
+ 2. Regenerate each repo's openapi-operations fixture from a current `hot dev`
67
+ and reconcile the coverage tables.
68
+ 3. Run every repo's `integration/run.sh`.
69
+ 4. Commit, tag `v<version>`, push in each repo.
70
+
71
+ The integration fixture (integration/fixture, mint_key.py, run.sh) is
72
+ duplicated across all five repos; the canonical copy lives in **hot-python** —
73
+ change it there first, then sync the others.
@@ -1,3 +1,4 @@
1
+
1
2
  Apache License
2
3
  Version 2.0, January 2004
3
4
  http://www.apache.org/licenses/
@@ -48,7 +49,7 @@
48
49
  "Contribution" shall mean any work of authorship, including
49
50
  the original version of the Work and any modifications or additions
50
51
  to that Work or Derivative Works thereof, that is intentionally
51
- submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
53
  or by an individual or Legal Entity authorized to submit on behalf of
53
54
  the copyright owner. For the purposes of this definition, "submitted"
54
55
  means any form of electronic, verbal, or written communication sent
@@ -175,7 +176,18 @@
175
176
 
176
177
  END OF TERMS AND CONDITIONS
177
178
 
178
- Copyright 2026 Hot Dev, LLC
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
179
191
 
180
192
  Licensed under the Apache License, Version 2.0 (the "License");
181
193
  you may not use this file except in compliance with the License.
hot_dev-1.2.0/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Hot Dev Python SDK
2
+ Copyright 2026 Hot Dev, LLC
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hot-dev
3
- Version: 1.1.2
3
+ Version: 1.2.0
4
4
  Summary: Python SDK for the Hot Dev API
5
5
  Project-URL: Homepage, https://hot.dev
6
6
  Project-URL: Repository, https://github.com/hot-dev/hot-python
@@ -8,6 +8,7 @@ Project-URL: Issues, https://github.com/hot-dev/hot-python/issues
8
8
  Author: Hot Dev, LLC
9
9
  License-Expression: Apache-2.0
10
10
  License-File: LICENSE
11
+ License-File: NOTICE
11
12
  Keywords: agents,api,hot,hot-dev,sdk,streaming
12
13
  Requires-Python: >=3.10
13
14
  Requires-Dist: httpx>=0.28
@@ -81,6 +82,27 @@ should call your own backend route instead of exposing a Hot API key.
81
82
  Most management endpoints require an API key. Sessions and service keys are
82
83
  permission-scoped and are mainly for event publishing and stream reads.
83
84
 
85
+ When code has a run id but does not need the full stream, wait on its durable
86
+ terminal snapshot:
87
+
88
+ ```python
89
+ run = hot.runs.wait(run_id, timeout=300)
90
+ print(run["result"])
91
+ ```
92
+
93
+ When a run returns a background task id, wait through the durable task resource:
94
+
95
+ ```python
96
+ task = hot.tasks.wait(task_id, timeout=300)
97
+ print(task["result"])
98
+ ```
99
+
100
+ The task waiter receives the latest persisted state first and reconnects, so it
101
+ cannot miss a task that completed before subscription. A failed, cancelled, or
102
+ timed-out task raises `HotTaskError` with the final task record.
103
+ The task's parent stream also emits durable `task:update` events, which is
104
+ useful when one subscription needs to coordinate several tasks.
105
+
84
106
  ## Async Usage
85
107
 
86
108
  ```python
@@ -126,13 +148,20 @@ except HotApiError as error:
126
148
  print(error.status_code, error.code, error.request_id, error.retry_after)
127
149
  ```
128
150
 
151
+ ### Retries
152
+
153
+ JSON requests are retried automatically (at most twice) when the API responds
154
+ 429 with a `retry_after`; other errors are raised as-is. Streaming and raw
155
+ requests are never retried.
156
+
129
157
  ## Resources
130
158
 
131
159
  `HotClient` mirrors the Hot API v1 resources:
132
160
 
133
161
  - `hot.events` — publish, list, get, inspect event runs, and call Hot functions with `call_hot(fn, args)`
134
- - `hot.streams` — subscribe to run streams, wait for run results, and publish events atomically (reconnects automatically across the 5-minute SSE timeout; pass `reconnect=False` to opt out)
135
- - `hot.runs` — list, inspect, and view run stats
162
+ - `hot.streams` — subscribe to run and task updates, wait for run results, and publish events atomically (reconnects automatically across the 5-minute SSE timeout; pass `reconnect=False` to opt out)
163
+ - `hot.runs` — list, inspect, subscribe to, and wait for durable runs
164
+ - `hot.tasks` — get, subscribe to, and wait for durable background tasks
136
165
  - `hot.files` — upload, download, list, and delete files (including multipart uploads)
137
166
  - `hot.projects` — create, list, update, activate, deactivate, and delete projects
138
167
  - `hot.builds` — upload, download, deploy, and look up live/deployed builds
@@ -148,9 +177,9 @@ endpoints that do not yet have a resource helper.
148
177
 
149
178
  `hot.env.subscribe()` requires API key credentials and a live API pub/sub
150
179
  backend; local API servers without pub/sub return a 503. `subscribe_with_event`
151
- reconnects across the API's 5-minute SSE timeout and stops after the first
152
- terminal `run:*` event it sees, so keep using the stream directly if your app
153
- expects multiple independent runs on the same stream.
180
+ reconnects across the API's 5-minute SSE timeout and stops after the terminal
181
+ run correlated to the event it published. Unrelated runs on the same stream do
182
+ not end the iterator.
154
183
 
155
184
  ## Customizing the HTTP Client
156
185
 
@@ -203,7 +232,7 @@ python -m build
203
232
  ## Related
204
233
 
205
234
  - [Hot Dev documentation](https://hot.dev/docs)
206
- - [Python SDK docs](https://hot.dev/docs/api/python)
235
+ - [SDK docs](https://hot.dev/docs/api/sdks)
207
236
  - [JavaScript / TypeScript SDK](https://www.npmjs.com/package/@hot-dev/sdk)
208
237
  - [Hot Chat demo](https://github.com/hot-dev/hot-demos/tree/main/hot-chat)
209
238
 
@@ -62,6 +62,27 @@ should call your own backend route instead of exposing a Hot API key.
62
62
  Most management endpoints require an API key. Sessions and service keys are
63
63
  permission-scoped and are mainly for event publishing and stream reads.
64
64
 
65
+ When code has a run id but does not need the full stream, wait on its durable
66
+ terminal snapshot:
67
+
68
+ ```python
69
+ run = hot.runs.wait(run_id, timeout=300)
70
+ print(run["result"])
71
+ ```
72
+
73
+ When a run returns a background task id, wait through the durable task resource:
74
+
75
+ ```python
76
+ task = hot.tasks.wait(task_id, timeout=300)
77
+ print(task["result"])
78
+ ```
79
+
80
+ The task waiter receives the latest persisted state first and reconnects, so it
81
+ cannot miss a task that completed before subscription. A failed, cancelled, or
82
+ timed-out task raises `HotTaskError` with the final task record.
83
+ The task's parent stream also emits durable `task:update` events, which is
84
+ useful when one subscription needs to coordinate several tasks.
85
+
65
86
  ## Async Usage
66
87
 
67
88
  ```python
@@ -107,13 +128,20 @@ except HotApiError as error:
107
128
  print(error.status_code, error.code, error.request_id, error.retry_after)
108
129
  ```
109
130
 
131
+ ### Retries
132
+
133
+ JSON requests are retried automatically (at most twice) when the API responds
134
+ 429 with a `retry_after`; other errors are raised as-is. Streaming and raw
135
+ requests are never retried.
136
+
110
137
  ## Resources
111
138
 
112
139
  `HotClient` mirrors the Hot API v1 resources:
113
140
 
114
141
  - `hot.events` — publish, list, get, inspect event runs, and call Hot functions with `call_hot(fn, args)`
115
- - `hot.streams` — subscribe to run streams, wait for run results, and publish events atomically (reconnects automatically across the 5-minute SSE timeout; pass `reconnect=False` to opt out)
116
- - `hot.runs` — list, inspect, and view run stats
142
+ - `hot.streams` — subscribe to run and task updates, wait for run results, and publish events atomically (reconnects automatically across the 5-minute SSE timeout; pass `reconnect=False` to opt out)
143
+ - `hot.runs` — list, inspect, subscribe to, and wait for durable runs
144
+ - `hot.tasks` — get, subscribe to, and wait for durable background tasks
117
145
  - `hot.files` — upload, download, list, and delete files (including multipart uploads)
118
146
  - `hot.projects` — create, list, update, activate, deactivate, and delete projects
119
147
  - `hot.builds` — upload, download, deploy, and look up live/deployed builds
@@ -129,9 +157,9 @@ endpoints that do not yet have a resource helper.
129
157
 
130
158
  `hot.env.subscribe()` requires API key credentials and a live API pub/sub
131
159
  backend; local API servers without pub/sub return a 503. `subscribe_with_event`
132
- reconnects across the API's 5-minute SSE timeout and stops after the first
133
- terminal `run:*` event it sees, so keep using the stream directly if your app
134
- expects multiple independent runs on the same stream.
160
+ reconnects across the API's 5-minute SSE timeout and stops after the terminal
161
+ run correlated to the event it published. Unrelated runs on the same stream do
162
+ not end the iterator.
135
163
 
136
164
  ## Customizing the HTTP Client
137
165
 
@@ -184,7 +212,7 @@ python -m build
184
212
  ## Related
185
213
 
186
214
  - [Hot Dev documentation](https://hot.dev/docs)
187
- - [Python SDK docs](https://hot.dev/docs/api/python)
215
+ - [SDK docs](https://hot.dev/docs/api/sdks)
188
216
  - [JavaScript / TypeScript SDK](https://www.npmjs.com/package/@hot-dev/sdk)
189
217
  - [Hot Chat demo](https://github.com/hot-dev/hot-demos/tree/main/hot-chat)
190
218
 
@@ -0,0 +1,3 @@
1
+ # Hot Dev API Key. Create at https://app.hot.dev/keys
2
+ # API Keys are scoped to your Organization and Environment
3
+ HOT_API_KEY=
@@ -0,0 +1,5 @@
1
+ .hot/
2
+ hot/ctx.hot
3
+ hot/dev.key
4
+ .env
5
+ dev.out
@@ -0,0 +1,56 @@
1
+ // Deterministic handlers and functions exercised by the SDK integration tests.
2
+ // Every SDK's integration suite drives the same four flows:
3
+ // - publish "sdk:echo" and read the run result back over SSE
4
+ // - publish "sdk:task", extract its user-shaped task ID, and await the task
5
+ // - hot:call ::fixture::sdk/add-nums for the call/wait helper
6
+ // - publish "sdk:fail" to observe the run:fail error path
7
+ ::fixture::sdk ns
8
+
9
+ ::task ::hot::task
10
+
11
+ // Echoes the event payload back as the run result.
12
+ on-sdk-echo
13
+ meta {on-event: "sdk:echo"}
14
+ fn (event) {
15
+ {echoed: event.data}
16
+ }
17
+
18
+ // Runs asynchronously after on-sdk-task returns its task ID to the SDK.
19
+ complete-background-work
20
+ fn (args: Any): Map {
21
+ {processed: args.value}
22
+ }
23
+
24
+ // Starts a durable task without awaiting it. The nested run-result shape is
25
+ // intentionally owned by this handler; SDK callers decide how to extract IDs.
26
+ on-sdk-task
27
+ meta {on-event: "sdk:task"}
28
+ fn (event) {
29
+ info ::task/start(::fixture::sdk/complete-background-work, event.data)
30
+ {work: {task: info.id}}
31
+ }
32
+
33
+ // Always fails, with a stable message the tests assert on.
34
+ on-sdk-fail
35
+ meta {on-event: "sdk:fail"}
36
+ fn (event) {
37
+ fail("sdk fixture failure")
38
+ }
39
+
40
+ // Called via the hot:call event by the call-hot/wait helpers.
41
+ add-nums
42
+ fn (a: Int, b: Int): Int {
43
+ add(a, b)
44
+ }
45
+
46
+ // String round-trip for a second hot:call shape.
47
+ shout
48
+ fn (text: Str): Str {
49
+ uppercase(text)
50
+ }
51
+
52
+ // Callable function that always fails, for hot:call error-path tests.
53
+ always-fail
54
+ fn (): Str {
55
+ fail("sdk fixture failure")
56
+ }
@@ -0,0 +1,22 @@
1
+ // Hot configuration for the SDK integration-test fixture project.
2
+ ::hot::conf ns
3
+
4
+ ::env ::hot::env
5
+
6
+ hot.set.project "sdk-fixture"
7
+
8
+ // The integration-test runner picks free ports via these env vars.
9
+ hot.api.port Int(::env/get("HOT_API_PORT", "4681"))
10
+ hot.app.port Int(::env/get("HOT_APP_PORT", "4680"))
11
+
12
+ // Bind the IPv4 loopback explicitly: "localhost" can resolve to ::1 only,
13
+ // which clients that dial 127.0.0.1 (e.g. the JDK) cannot reach.
14
+ hot.api.host Str(::env/get("HOT_API_HOST", "127.0.0.1"))
15
+ hot.app.host Str(::env/get("HOT_APP_HOST", "127.0.0.1"))
16
+
17
+ hot.project.sdk-fixture.src.paths ["./hot/src"]
18
+ hot.project.sdk-fixture.test.paths ["./hot/test"]
19
+ hot.project.sdk-fixture.resources.paths ["./hot/resources"]
20
+ hot.project.sdk-fixture.deps {}
21
+
22
+ hot.dev.open false
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env python3
2
+ """Mint a full-access API key directly in a local `hot dev` sqlite database.
3
+
4
+ Usage: mint_key.py <path-to-.hot/db/hot.sqlite.db>
5
+ Prints the plaintext key (hot_<uuid>_<secret>) on stdout.
6
+ """
7
+ import base64
8
+ import hashlib
9
+ import json
10
+ import secrets
11
+ import sqlite3
12
+ import sys
13
+ import uuid
14
+
15
+ db_path = sys.argv[1]
16
+ conn = sqlite3.connect(db_path)
17
+ env_id = conn.execute("select env_id from env limit 1").fetchone()[0]
18
+ user_id = conn.execute("select user_id from user limit 1").fetchone()[0]
19
+
20
+ key_id = uuid.uuid4()
21
+ secret = secrets.token_hex(32)
22
+ key_data = json.dumps(
23
+ {
24
+ "algorithm": "sha256",
25
+ "hash": base64.b64encode(hashlib.sha256(secret.encode()).digest()).decode(),
26
+ }
27
+ )
28
+
29
+ conn.execute(
30
+ "insert into api_key (api_key_id, env_id, description, key_data,"
31
+ " created_by_user_id, permissions) values (?, ?, ?, ?, ?, ?)",
32
+ (
33
+ key_id.bytes,
34
+ env_id,
35
+ "sdk-integration-tests",
36
+ key_data,
37
+ user_id,
38
+ json.dumps({"*:*": ["*"]}),
39
+ ),
40
+ )
41
+ conn.commit()
42
+ print(f"hot_{key_id.hex}_{secret}")
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env bash
2
+ # Runs this SDK's integration tests against a scratch `hot dev` instance.
3
+ #
4
+ # Requires the `hot` CLI (https://hot.dev) and python3 on PATH. Starts a
5
+ # dedicated dev server for the fixture project on HOT_TEST_PORT (default
6
+ # 4725), mints a local API key directly in the fixture's sqlite database,
7
+ # exports HOT_TEST_BASE_URL / HOT_TEST_API_KEY, and runs the suite.
8
+ set -euo pipefail
9
+ cd "$(dirname "$0")"
10
+
11
+ PORT="${HOT_TEST_PORT:-4725}"
12
+ APP_PORT=$((PORT + 50))
13
+
14
+ command -v hot >/dev/null || { echo "error: hot CLI not found on PATH" >&2; exit 1; }
15
+ command -v python3 >/dev/null || { echo "error: python3 not found on PATH" >&2; exit 1; }
16
+
17
+ echo "starting hot dev on :$PORT (app :$APP_PORT)..."
18
+ (cd fixture && exec env HOT_API_PORT="$PORT" HOT_APP_PORT="$APP_PORT" hot dev --log.target file > dev.out 2>&1) &
19
+ DEV_PID=$!
20
+ trap 'kill "$DEV_PID" 2>/dev/null || true' EXIT
21
+
22
+ up=""
23
+ for _ in $(seq 1 60); do
24
+ if curl -sf -m 2 "http://localhost:$PORT/status" > /dev/null 2>&1; then up=1; break; fi
25
+ kill -0 "$DEV_PID" 2>/dev/null || { echo "error: hot dev exited early:" >&2; tail -20 fixture/dev.out >&2; exit 1; }
26
+ sleep 2
27
+ done
28
+ [ -n "$up" ] || { echo "error: hot dev did not become ready" >&2; tail -20 fixture/dev.out >&2; exit 1; }
29
+
30
+ export HOT_TEST_BASE_URL="http://127.0.0.1:$PORT"
31
+ # `hot key create` ships in hot > 2.6.1; fall back to minting directly in
32
+ # sqlite (mint_key.py) for older CLIs. Drop the fallback once the hot
33
+ # release containing `hot key create` is the oldest supported version.
34
+ if HOT_TEST_API_KEY="$(cd fixture && hot key create --description sdk-integration 2>/dev/null)" && [ -n "$HOT_TEST_API_KEY" ]; then
35
+ echo "minted key via hot key create"
36
+ else
37
+ HOT_TEST_API_KEY="$(python3 mint_key.py fixture/.hot/db/hot.sqlite.db)"
38
+ echo "minted key via mint_key.py (hot CLI without \`hot key create\`)"
39
+ fi
40
+ export HOT_TEST_API_KEY
41
+
42
+ echo "hot dev ready; running integration tests..."
43
+ cd ..
44
+ PYTHON="${PYTHON:-python3}"; [ -x .venv/bin/python ] && PYTHON=.venv/bin/python; "$PYTHON" -m pytest tests/test_integration.py -v
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "hot-dev"
7
- version = "1.1.2"
7
+ version = "1.2.0"
8
8
  description = "Python SDK for the Hot Dev API"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -1,10 +1,12 @@
1
1
  from .client import AsyncHotClient, HotClient
2
- from .errors import HotApiError
2
+ from .errors import HotApiError, HotRunError, HotTaskError
3
3
  from .sse import consume_sse_blocks
4
4
 
5
5
  __all__ = [
6
6
  "AsyncHotClient",
7
7
  "HotApiError",
8
8
  "HotClient",
9
+ "HotRunError",
10
+ "HotTaskError",
9
11
  "consume_sse_blocks",
10
12
  ]
@@ -1,5 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import asyncio
4
+ import importlib.metadata
5
+ import time
3
6
  from collections.abc import Mapping
4
7
  from typing import Any
5
8
 
@@ -9,6 +12,26 @@ from .errors import parse_api_error
9
12
 
10
13
  DEFAULT_BASE_URL = "https://api.hot.dev"
11
14
 
15
+ try:
16
+ _VERSION = importlib.metadata.version("hot-dev")
17
+ except importlib.metadata.PackageNotFoundError: # pragma: no cover
18
+ _VERSION = "unknown"
19
+
20
+ USER_AGENT = f"hot-sdk-python/{_VERSION}"
21
+
22
+ # JSON requests retry on 429 when the server supplies retry_after.
23
+ _MAX_RETRIES = 2
24
+ _MAX_RETRY_AFTER_SECONDS = 30.0
25
+
26
+
27
+ def _retry_delay(response: httpx.Response, attempts: int) -> float | None:
28
+ if response.status_code != 429 or attempts >= _MAX_RETRIES:
29
+ return None
30
+ error = parse_api_error(response.status_code, response.text, dict(response.headers))
31
+ if not error.retry_after:
32
+ return None
33
+ return min(float(error.retry_after), _MAX_RETRY_AFTER_SECONDS)
34
+
12
35
 
13
36
  class SyncTransport:
14
37
  def __init__(
@@ -37,14 +60,20 @@ class SyncTransport:
37
60
  json: Any = None,
38
61
  params: Mapping[str, Any] | None = None,
39
62
  ) -> dict[str, Any]:
40
- response = self.client.request(
41
- method,
42
- f"{self.api_base_url}{path}",
43
- headers=self.headers({"Accept": "application/json"}),
44
- json=json,
45
- params=without_none(params),
46
- )
47
- return parse_response(response)
63
+ attempts = 0
64
+ while True:
65
+ response = self.client.request(
66
+ method,
67
+ f"{self.api_base_url}{path}",
68
+ headers=self.headers({"Accept": "application/json"}),
69
+ json=json,
70
+ params=without_none(params),
71
+ )
72
+ delay = _retry_delay(response, attempts)
73
+ if delay is None:
74
+ return parse_response(response)
75
+ attempts += 1
76
+ time.sleep(delay)
48
77
 
49
78
  def request_raw(
50
79
  self,
@@ -70,7 +99,11 @@ class SyncTransport:
70
99
  return response
71
100
 
72
101
  def headers(self, extra: Mapping[str, str] | None = None) -> dict[str, str]:
73
- return {"Authorization": f"Bearer {self.token}", **dict(extra or {})}
102
+ return {
103
+ "Authorization": f"Bearer {self.token}",
104
+ "User-Agent": USER_AGENT,
105
+ **dict(extra or {}),
106
+ }
74
107
 
75
108
 
76
109
  class AsyncTransport:
@@ -100,14 +133,20 @@ class AsyncTransport:
100
133
  json: Any = None,
101
134
  params: Mapping[str, Any] | None = None,
102
135
  ) -> dict[str, Any]:
103
- response = await self.client.request(
104
- method,
105
- f"{self.api_base_url}{path}",
106
- headers=self.headers({"Accept": "application/json"}),
107
- json=json,
108
- params=without_none(params),
109
- )
110
- return parse_response(response)
136
+ attempts = 0
137
+ while True:
138
+ response = await self.client.request(
139
+ method,
140
+ f"{self.api_base_url}{path}",
141
+ headers=self.headers({"Accept": "application/json"}),
142
+ json=json,
143
+ params=without_none(params),
144
+ )
145
+ delay = _retry_delay(response, attempts)
146
+ if delay is None:
147
+ return parse_response(response)
148
+ attempts += 1
149
+ await asyncio.sleep(delay)
111
150
 
112
151
  async def request_raw(
113
152
  self,
@@ -133,7 +172,11 @@ class AsyncTransport:
133
172
  return response
134
173
 
135
174
  def headers(self, extra: Mapping[str, str] | None = None) -> dict[str, str]:
136
- return {"Authorization": f"Bearer {self.token}", **dict(extra or {})}
175
+ return {
176
+ "Authorization": f"Bearer {self.token}",
177
+ "User-Agent": USER_AGENT,
178
+ **dict(extra or {}),
179
+ }
137
180
 
138
181
 
139
182
  def parse_response(response: httpx.Response) -> dict[str, Any]:
@@ -19,6 +19,7 @@ from .resources import (
19
19
  AsyncServiceKeysResource,
20
20
  AsyncSessionsResource,
21
21
  AsyncStreamsResource,
22
+ AsyncTasksResource,
22
23
  BuildsResource,
23
24
  ContextResource,
24
25
  DomainsResource,
@@ -31,6 +32,7 @@ from .resources import (
31
32
  ServiceKeysResource,
32
33
  SessionsResource,
33
34
  StreamsResource,
35
+ TasksResource,
34
36
  )
35
37
 
36
38
 
@@ -63,6 +65,7 @@ class HotClient:
63
65
  self.service_keys = ServiceKeysResource(self._transport)
64
66
  self.sessions = SessionsResource(self._transport)
65
67
  self.streams = StreamsResource(self._transport)
68
+ self.tasks = TasksResource(self._transport)
66
69
 
67
70
  @property
68
71
  def token(self) -> str:
@@ -131,6 +134,7 @@ class AsyncHotClient:
131
134
  self.service_keys = AsyncServiceKeysResource(self._transport)
132
135
  self.sessions = AsyncSessionsResource(self._transport)
133
136
  self.streams = AsyncStreamsResource(self._transport)
137
+ self.tasks = AsyncTasksResource(self._transport)
134
138
 
135
139
  @property
136
140
  def token(self) -> str: