riffsdk 0.24.0__tar.gz → 0.26.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.
- {riffsdk-0.24.0 → riffsdk-0.26.0}/AGENTS.md +1 -1
- {riffsdk-0.24.0 → riffsdk-0.26.0}/CHANGELOG.md +43 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/PKG-INFO +45 -4
- {riffsdk-0.24.0 → riffsdk-0.26.0}/README.md +44 -3
- {riffsdk-0.24.0 → riffsdk-0.26.0}/mise.toml +4 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/pyproject.toml +1 -1
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/storage/_async_client.py +44 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/storage/_client.py +44 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/storage/_common.py +59 -2
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/tasks/__init__.py +2 -1
- riffsdk-0.26.0/src/riffsdk/tasks/v0.py +332 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_async_client.py +8 -3
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_client.py +13 -5
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_importance.py +7 -2
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_imports.py +2 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_integration.py +20 -0
- riffsdk-0.26.0/tests/test_single_put_upload.py +205 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_tasks_v0.py +263 -1
- riffsdk-0.26.0/uv.lock +965 -0
- riffsdk-0.24.0/src/riffsdk/tasks/v0.py +0 -143
- riffsdk-0.24.0/uv.lock +0 -821
- {riffsdk-0.24.0 → riffsdk-0.26.0}/.github/workflows/ci.yml +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/.github/workflows/pr-comment.yml +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/.github/workflows/release.yml +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/.gitignore +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/.python-version +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/CLAUDE.md +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/LICENCE +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/LOCAL-TESTING.md +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/USAGE_PROMPT.md +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/examples/async_client.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/examples/basic_crud.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/examples/email_notice.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/examples/file_upload_download.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/examples/get_task.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/examples/interpret_document.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/examples/optimistic_concurrency.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/new-sdk-url-schema.md +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/__init__.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/__main__.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/_cli.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/_internal/__init__.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/_internal/auth.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/_internal/config.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/_internal/transport.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/ai/__init__.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/ai/v0.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/client.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/context.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/email/__init__.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/email/v0.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/storage/__init__.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/storage/_http.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/storage/_mime.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/storage/_models.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/storage/_session.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/storage/_streaming.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/storage/_upload.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/storage/exceptions.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/src/riffsdk/storage/py.typed +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/__init__.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/conftest.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_ai_v0.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_auth.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_cli.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_config.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_context.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_email_v0.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_exceptions.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_http.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_mime.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_models.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_session.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_streaming.py +0 -0
- {riffsdk-0.24.0 → riffsdk-0.26.0}/tests/test_upload.py +0 -0
|
@@ -60,7 +60,7 @@ src/riffsdk/
|
|
|
60
60
|
v0.py # notice_html/notice_text - the AI notice for emails
|
|
61
61
|
tasks/
|
|
62
62
|
__init__.py # Docstring only - importing it loads no version
|
|
63
|
-
v0.py # get_task - one task off the app's task board
|
|
63
|
+
v0.py # get_task, update_task_metadata - one task off the app's task board, and its metadata/assignee
|
|
64
64
|
ai/
|
|
65
65
|
__init__.py # Docstring only - importing it loads no version
|
|
66
66
|
v0.py # interpret_document - extract text from a stored document (LLM call)
|
|
@@ -2,6 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- version list -->
|
|
4
4
|
|
|
5
|
+
## v0.26.0 (2026-11-17)
|
|
6
|
+
|
|
7
|
+
### Chores
|
|
8
|
+
|
|
9
|
+
- Add mise upgrade task for in-range dependency upgrades
|
|
10
|
+
([#54](https://github.com/databutton/riff-sdk-python/pull/54),
|
|
11
|
+
[`c6a311e`](https://github.com/databutton/riff-sdk-python/commit/c6a311e639819c6efa89b17fa950ffc64712053f))
|
|
12
|
+
|
|
13
|
+
- Refresh dependencies within existing ranges
|
|
14
|
+
([#54](https://github.com/databutton/riff-sdk-python/pull/54),
|
|
15
|
+
[`c6a311e`](https://github.com/databutton/riff-sdk-python/commit/c6a311e639819c6efa89b17fa950ffc64712053f))
|
|
16
|
+
|
|
17
|
+
- Upgrade dependencies within existing ranges
|
|
18
|
+
([#55](https://github.com/databutton/riff-sdk-python/pull/55),
|
|
19
|
+
[`20f2bc6`](https://github.com/databutton/riff-sdk-python/commit/20f2bc6921ab3750749fe71116d9492f1bf7ae5f))
|
|
20
|
+
|
|
21
|
+
- Upgrade dependencies within existing ranges
|
|
22
|
+
([#53](https://github.com/databutton/riff-sdk-python/pull/53),
|
|
23
|
+
[`e08f84f`](https://github.com/databutton/riff-sdk-python/commit/e08f84fc6aaff188d7b62446cea8f4987b10a8e4))
|
|
24
|
+
|
|
25
|
+
### Documentation
|
|
26
|
+
|
|
27
|
+
- **tasks**: Only a metadata change wakes the task, not an assignee-only change
|
|
28
|
+
([`4e03702`](https://github.com/databutton/riff-sdk-python/commit/4e03702bdedb3e723d92e78059af5a69f0f6bef9))
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
- **tasks**: Update_task_metadata merges metadata and sets the assignee
|
|
33
|
+
([`c99a4dc`](https://github.com/databutton/riff-sdk-python/commit/c99a4dc8258021442a75ae8242ffa52ad5db7c72))
|
|
34
|
+
|
|
35
|
+
- **tasks**: Update_task_metadata wakes the task on change; wake=False opts out
|
|
36
|
+
([`ef12c09`](https://github.com/databutton/riff-sdk-python/commit/ef12c09e51f9c2714cb1a25f38bd4a9c955e1f9a))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## v0.25.0 (2026-10-26)
|
|
40
|
+
|
|
41
|
+
### Features
|
|
42
|
+
|
|
43
|
+
- **storage**: Send uploads that fit in one chunk as a single PUT
|
|
44
|
+
([#52](https://github.com/databutton/riff-sdk-python/pull/52),
|
|
45
|
+
[`4ceb3d8`](https://github.com/databutton/riff-sdk-python/commit/4ceb3d87601a299952b6d5b13a5aa2820e1ac9df))
|
|
46
|
+
|
|
47
|
+
|
|
5
48
|
## v0.24.0 (2026-10-16)
|
|
6
49
|
|
|
7
50
|
### Features
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: riffsdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.26.0
|
|
4
4
|
Summary: Python SDK for the Riff Storage API
|
|
5
5
|
Project-URL: Homepage, https://riff.ai
|
|
6
6
|
Author-email: Martin Sandve Alnæs <msa@databutton.io>
|
|
@@ -88,6 +88,35 @@ work left on them and nothing about the ones already finished, so it cannot
|
|
|
88
88
|
tell an item it has never seen from one whose task is done — and proposes the
|
|
89
89
|
same finished work every time it fires. `get_task` closes that gap.
|
|
90
90
|
|
|
91
|
+
To record what a trigger learned about a task, merge metadata into it and/or
|
|
92
|
+
set its assignee. A metadata change wakes the task's agent so it sees it
|
|
93
|
+
(`task.woken`); changing only the assignee does not. Pass `wake=False` for a
|
|
94
|
+
write it need not react to:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
task = tasks.update_task_metadata(
|
|
98
|
+
"TASK-42",
|
|
99
|
+
{"chase_count": 2, "stale_since": None}, # merged; None clears a key
|
|
100
|
+
approver="buyer@example.com", # user id or email; None unassigns; omit to leave alone
|
|
101
|
+
)
|
|
102
|
+
print(task["metadata"], task["approver"])
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Keys that are not configured fields are always accepted and saved as they are.
|
|
106
|
+
A value for a *configured* field is checked against its type (a number field
|
|
107
|
+
takes a number, a select one of its options, a date an ISO 8601 string); one that
|
|
108
|
+
fails is not written, but the call does not fail -- the rest lands, and the
|
|
109
|
+
held-back keys come back on `task.rejected_metadata` (key -> why) and are logged
|
|
110
|
+
as a warning. Only configured fields are **shown** on the board, as list/board
|
|
111
|
+
columns and in the task's key information. A builder adds one in *Configure
|
|
112
|
+
fields* (Show in list / Show in summary), and the keys you wrote that are not
|
|
113
|
+
configured come back on `task.unconfigured_metadata_keys`.
|
|
114
|
+
|
|
115
|
+
Only metadata and the assignee (`approver`) can be written -- status and summary
|
|
116
|
+
belong to the agent working the task. A trigger tool can also set both from its
|
|
117
|
+
result: see the `metadata` and `approver` fields of a task item in the trigger
|
|
118
|
+
contract.
|
|
119
|
+
|
|
91
120
|
Import the version you are writing against, bound to a short name as above.
|
|
92
121
|
A version does not change under you: when the API changes it appears as a new
|
|
93
122
|
version, and the one you imported keeps behaving as it did. Importing
|
|
@@ -101,6 +130,14 @@ version, and the one you imported keeps behaving as it did. Importing
|
|
|
101
130
|
name (`task["status"]`, `task["metadata"]`, `task.get("summary")`, or
|
|
102
131
|
`task.data` for the whole dict), so a task gaining a field needs no SDK
|
|
103
132
|
release.
|
|
133
|
+
- `update_task_metadata(ref, metadata=None, *, approver=UNSET, wake=True, client=None)` --
|
|
134
|
+
merges `metadata` into the task and/or sets its assignee, and returns the
|
|
135
|
+
updated `Task`. Safe to repeat (setting what the task already holds is a
|
|
136
|
+
no-op, and wakes nothing). A metadata change wakes the task's agent unless
|
|
137
|
+
`wake=False`; an assignee-only change wakes nothing; a finished task is never reopened (`task.woken` and
|
|
138
|
+
`task.not_woken_reason` report what happened). Raises `TaskError` if there is no such task (`status_code` 404 --
|
|
139
|
+
unlike `get_task`, a write to nothing has not happened), and `ValueError` if
|
|
140
|
+
there is nothing to update. `update_task_metadata_async` is the async form.
|
|
104
141
|
- Raises `TaskError` if the lookup failed -- including on a persistent 429/5xx
|
|
105
142
|
after retrying with backoff. A task that does not exist is not a failure;
|
|
106
143
|
it comes back as `None`.
|
|
@@ -109,9 +146,9 @@ version, and the one you imported keeps behaving as it did. Importing
|
|
|
109
146
|
ambient environment the first time it's needed -- pass your own to point it
|
|
110
147
|
elsewhere or to share it explicitly with other `riffsdk.tasks`/`riffsdk.ai`
|
|
111
148
|
calls.
|
|
112
|
-
- The board
|
|
113
|
-
the same app in the workspace sees the workspace's. There is
|
|
114
|
-
configure for that, and no way to
|
|
149
|
+
- The board is the app's own, for reads and writes: a deployed app sees its
|
|
150
|
+
production tasks, the same app in the workspace sees the workspace's. There is
|
|
151
|
+
nothing to configure for that, and no way to reach the other one.
|
|
115
152
|
- Runs from an app's backend, where the environment it needs is already set.
|
|
116
153
|
|
|
117
154
|
## AI
|
|
@@ -237,6 +274,10 @@ same way when `--scope` is omitted.
|
|
|
237
274
|
- `ResumableUpload` / `AsyncResumableUpload` -- multipart resumable uploads for large files
|
|
238
275
|
- `StorageReader` / `StorageWriter` -- streaming read/write
|
|
239
276
|
|
|
277
|
+
`upload_file` and `upload_stream` send an input that fits in one chunk (at most 8 MiB) as a
|
|
278
|
+
single `put`, which takes one request instead of the four a multipart upload needs. Larger
|
|
279
|
+
inputs, including streams of unknown size that turn out larger, use a multipart upload.
|
|
280
|
+
|
|
240
281
|
### Content types
|
|
241
282
|
|
|
242
283
|
`content_type` is optional on `put`, `upload_file`, `upload_stream`, `begin_upload` and
|
|
@@ -74,6 +74,35 @@ work left on them and nothing about the ones already finished, so it cannot
|
|
|
74
74
|
tell an item it has never seen from one whose task is done — and proposes the
|
|
75
75
|
same finished work every time it fires. `get_task` closes that gap.
|
|
76
76
|
|
|
77
|
+
To record what a trigger learned about a task, merge metadata into it and/or
|
|
78
|
+
set its assignee. A metadata change wakes the task's agent so it sees it
|
|
79
|
+
(`task.woken`); changing only the assignee does not. Pass `wake=False` for a
|
|
80
|
+
write it need not react to:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
task = tasks.update_task_metadata(
|
|
84
|
+
"TASK-42",
|
|
85
|
+
{"chase_count": 2, "stale_since": None}, # merged; None clears a key
|
|
86
|
+
approver="buyer@example.com", # user id or email; None unassigns; omit to leave alone
|
|
87
|
+
)
|
|
88
|
+
print(task["metadata"], task["approver"])
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Keys that are not configured fields are always accepted and saved as they are.
|
|
92
|
+
A value for a *configured* field is checked against its type (a number field
|
|
93
|
+
takes a number, a select one of its options, a date an ISO 8601 string); one that
|
|
94
|
+
fails is not written, but the call does not fail -- the rest lands, and the
|
|
95
|
+
held-back keys come back on `task.rejected_metadata` (key -> why) and are logged
|
|
96
|
+
as a warning. Only configured fields are **shown** on the board, as list/board
|
|
97
|
+
columns and in the task's key information. A builder adds one in *Configure
|
|
98
|
+
fields* (Show in list / Show in summary), and the keys you wrote that are not
|
|
99
|
+
configured come back on `task.unconfigured_metadata_keys`.
|
|
100
|
+
|
|
101
|
+
Only metadata and the assignee (`approver`) can be written -- status and summary
|
|
102
|
+
belong to the agent working the task. A trigger tool can also set both from its
|
|
103
|
+
result: see the `metadata` and `approver` fields of a task item in the trigger
|
|
104
|
+
contract.
|
|
105
|
+
|
|
77
106
|
Import the version you are writing against, bound to a short name as above.
|
|
78
107
|
A version does not change under you: when the API changes it appears as a new
|
|
79
108
|
version, and the one you imported keeps behaving as it did. Importing
|
|
@@ -87,6 +116,14 @@ version, and the one you imported keeps behaving as it did. Importing
|
|
|
87
116
|
name (`task["status"]`, `task["metadata"]`, `task.get("summary")`, or
|
|
88
117
|
`task.data` for the whole dict), so a task gaining a field needs no SDK
|
|
89
118
|
release.
|
|
119
|
+
- `update_task_metadata(ref, metadata=None, *, approver=UNSET, wake=True, client=None)` --
|
|
120
|
+
merges `metadata` into the task and/or sets its assignee, and returns the
|
|
121
|
+
updated `Task`. Safe to repeat (setting what the task already holds is a
|
|
122
|
+
no-op, and wakes nothing). A metadata change wakes the task's agent unless
|
|
123
|
+
`wake=False`; an assignee-only change wakes nothing; a finished task is never reopened (`task.woken` and
|
|
124
|
+
`task.not_woken_reason` report what happened). Raises `TaskError` if there is no such task (`status_code` 404 --
|
|
125
|
+
unlike `get_task`, a write to nothing has not happened), and `ValueError` if
|
|
126
|
+
there is nothing to update. `update_task_metadata_async` is the async form.
|
|
90
127
|
- Raises `TaskError` if the lookup failed -- including on a persistent 429/5xx
|
|
91
128
|
after retrying with backoff. A task that does not exist is not a failure;
|
|
92
129
|
it comes back as `None`.
|
|
@@ -95,9 +132,9 @@ version, and the one you imported keeps behaving as it did. Importing
|
|
|
95
132
|
ambient environment the first time it's needed -- pass your own to point it
|
|
96
133
|
elsewhere or to share it explicitly with other `riffsdk.tasks`/`riffsdk.ai`
|
|
97
134
|
calls.
|
|
98
|
-
- The board
|
|
99
|
-
the same app in the workspace sees the workspace's. There is
|
|
100
|
-
configure for that, and no way to
|
|
135
|
+
- The board is the app's own, for reads and writes: a deployed app sees its
|
|
136
|
+
production tasks, the same app in the workspace sees the workspace's. There is
|
|
137
|
+
nothing to configure for that, and no way to reach the other one.
|
|
101
138
|
- Runs from an app's backend, where the environment it needs is already set.
|
|
102
139
|
|
|
103
140
|
## AI
|
|
@@ -223,6 +260,10 @@ same way when `--scope` is omitted.
|
|
|
223
260
|
- `ResumableUpload` / `AsyncResumableUpload` -- multipart resumable uploads for large files
|
|
224
261
|
- `StorageReader` / `StorageWriter` -- streaming read/write
|
|
225
262
|
|
|
263
|
+
`upload_file` and `upload_stream` send an input that fits in one chunk (at most 8 MiB) as a
|
|
264
|
+
single `put`, which takes one request instead of the four a multipart upload needs. Larger
|
|
265
|
+
inputs, including streams of unknown size that turn out larger, use a multipart upload.
|
|
266
|
+
|
|
226
267
|
### Content types
|
|
227
268
|
|
|
228
269
|
`content_type` is optional on `put`, `upload_file`, `upload_stream`, `begin_upload` and
|
|
@@ -26,3 +26,7 @@ run = "uv run ruff check --fix src tests"
|
|
|
26
26
|
description = "Run integration tests against a local riff stack's front proxy"
|
|
27
27
|
env = { API_RIFF_NEW_URL = "http://localhost:8080", RIFF_INTEGRATION_TEST = "true" }
|
|
28
28
|
run = "uv run pytest tests/test_integration.py -v"
|
|
29
|
+
|
|
30
|
+
[tasks.upgrade]
|
|
31
|
+
description = "Refresh uv.lock to the newest versions within the declared ranges"
|
|
32
|
+
run = ["uv lock --upgrade", "uv sync"]
|
|
@@ -13,10 +13,14 @@ from riffsdk.storage._common import (
|
|
|
13
13
|
COMPLETED_MARKERS,
|
|
14
14
|
DownloadInfo,
|
|
15
15
|
ImportanceCategory,
|
|
16
|
+
PrefixedStream,
|
|
16
17
|
importance_headers,
|
|
17
18
|
mark_body,
|
|
19
|
+
read_up_to,
|
|
18
20
|
resolve_params,
|
|
19
21
|
scope_headers,
|
|
22
|
+
single_put_limit,
|
|
23
|
+
upload_result_from_meta,
|
|
20
24
|
)
|
|
21
25
|
from riffsdk.storage._http import AsyncTransport
|
|
22
26
|
from riffsdk.storage._mime import (
|
|
@@ -423,6 +427,23 @@ class AsyncStorageClient:
|
|
|
423
427
|
file_size = os.path.getsize(path)
|
|
424
428
|
cs = chunk_size or self._chunk_size
|
|
425
429
|
|
|
430
|
+
if file_size <= single_put_limit(cs):
|
|
431
|
+
with open(path, "rb") as f:
|
|
432
|
+
data = f.read()
|
|
433
|
+
meta = await self.put(
|
|
434
|
+
key,
|
|
435
|
+
data,
|
|
436
|
+
content_type=content_type,
|
|
437
|
+
if_version_matches=if_version_matches,
|
|
438
|
+
if_not_exists=if_not_exists,
|
|
439
|
+
scope=scope,
|
|
440
|
+
importance=importance,
|
|
441
|
+
importance_note=importance_note,
|
|
442
|
+
)
|
|
443
|
+
if on_progress:
|
|
444
|
+
on_progress(len(data), len(data))
|
|
445
|
+
return upload_result_from_meta(meta)
|
|
446
|
+
|
|
426
447
|
upload = await self.begin_upload(
|
|
427
448
|
key,
|
|
428
449
|
total_size=file_size,
|
|
@@ -468,9 +489,32 @@ class AsyncStorageClient:
|
|
|
468
489
|
Pass ``total_size`` when the size is known to use pre-signed part URLs.
|
|
469
490
|
Leave it ``None`` to stream an input of unknown size: the source is read
|
|
470
491
|
in part-size chunks until EOF, signing part URLs on demand.
|
|
492
|
+
|
|
493
|
+
An input that fits in one chunk (up to 8 MiB) is sent as a single PUT.
|
|
471
494
|
"""
|
|
472
495
|
cs = chunk_size or self._chunk_size
|
|
473
496
|
|
|
497
|
+
limit = single_put_limit(cs)
|
|
498
|
+
if total_size is None or total_size <= limit:
|
|
499
|
+
# Read one byte past the limit: only then do we know whether an
|
|
500
|
+
# unknown-size stream ends within it.
|
|
501
|
+
head = read_up_to(stream, limit + 1 if total_size is None else total_size)
|
|
502
|
+
if len(head) <= limit:
|
|
503
|
+
meta = await self.put(
|
|
504
|
+
key,
|
|
505
|
+
head,
|
|
506
|
+
content_type=content_type,
|
|
507
|
+
if_version_matches=if_version_matches,
|
|
508
|
+
if_not_exists=if_not_exists,
|
|
509
|
+
scope=scope,
|
|
510
|
+
importance=importance,
|
|
511
|
+
importance_note=importance_note,
|
|
512
|
+
)
|
|
513
|
+
if on_progress:
|
|
514
|
+
on_progress(len(head), len(head))
|
|
515
|
+
return upload_result_from_meta(meta)
|
|
516
|
+
stream = PrefixedStream(head, stream)
|
|
517
|
+
|
|
474
518
|
upload = await self.begin_upload(
|
|
475
519
|
key,
|
|
476
520
|
total_size=total_size,
|
|
@@ -13,10 +13,14 @@ from riffsdk.storage._common import (
|
|
|
13
13
|
COMPLETED_MARKERS,
|
|
14
14
|
DownloadInfo,
|
|
15
15
|
ImportanceCategory,
|
|
16
|
+
PrefixedStream,
|
|
16
17
|
importance_headers,
|
|
17
18
|
mark_body,
|
|
19
|
+
read_up_to,
|
|
18
20
|
resolve_params,
|
|
19
21
|
scope_headers,
|
|
22
|
+
single_put_limit,
|
|
23
|
+
upload_result_from_meta,
|
|
20
24
|
)
|
|
21
25
|
from riffsdk.storage._http import SyncTransport
|
|
22
26
|
from riffsdk.storage._mime import (
|
|
@@ -430,6 +434,23 @@ class StorageClient:
|
|
|
430
434
|
file_size = os.path.getsize(path)
|
|
431
435
|
cs = chunk_size or self._chunk_size
|
|
432
436
|
|
|
437
|
+
if file_size <= single_put_limit(cs):
|
|
438
|
+
with open(path, "rb") as f:
|
|
439
|
+
data = f.read()
|
|
440
|
+
meta = self.put(
|
|
441
|
+
key,
|
|
442
|
+
data,
|
|
443
|
+
content_type=content_type,
|
|
444
|
+
if_version_matches=if_version_matches,
|
|
445
|
+
if_not_exists=if_not_exists,
|
|
446
|
+
scope=scope,
|
|
447
|
+
importance=importance,
|
|
448
|
+
importance_note=importance_note,
|
|
449
|
+
)
|
|
450
|
+
if on_progress:
|
|
451
|
+
on_progress(len(data), len(data))
|
|
452
|
+
return upload_result_from_meta(meta)
|
|
453
|
+
|
|
433
454
|
upload = self.begin_upload(
|
|
434
455
|
key,
|
|
435
456
|
total_size=file_size,
|
|
@@ -475,9 +496,32 @@ class StorageClient:
|
|
|
475
496
|
Pass ``total_size`` when the size is known to use pre-signed part URLs.
|
|
476
497
|
Leave it ``None`` to stream an input of unknown size: the source is read
|
|
477
498
|
in part-size chunks until EOF, signing part URLs on demand.
|
|
499
|
+
|
|
500
|
+
An input that fits in one chunk (up to 8 MiB) is sent as a single PUT.
|
|
478
501
|
"""
|
|
479
502
|
cs = chunk_size or self._chunk_size
|
|
480
503
|
|
|
504
|
+
limit = single_put_limit(cs)
|
|
505
|
+
if total_size is None or total_size <= limit:
|
|
506
|
+
# Read one byte past the limit: only then do we know whether an
|
|
507
|
+
# unknown-size stream ends within it.
|
|
508
|
+
head = read_up_to(stream, limit + 1 if total_size is None else total_size)
|
|
509
|
+
if len(head) <= limit:
|
|
510
|
+
meta = self.put(
|
|
511
|
+
key,
|
|
512
|
+
head,
|
|
513
|
+
content_type=content_type,
|
|
514
|
+
if_version_matches=if_version_matches,
|
|
515
|
+
if_not_exists=if_not_exists,
|
|
516
|
+
scope=scope,
|
|
517
|
+
importance=importance,
|
|
518
|
+
importance_note=importance_note,
|
|
519
|
+
)
|
|
520
|
+
if on_progress:
|
|
521
|
+
on_progress(len(head), len(head))
|
|
522
|
+
return upload_result_from_meta(meta)
|
|
523
|
+
stream = PrefixedStream(head, stream)
|
|
524
|
+
|
|
481
525
|
upload = self.begin_upload(
|
|
482
526
|
key,
|
|
483
527
|
total_size=total_size,
|
|
@@ -2,13 +2,13 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import base64
|
|
4
4
|
import logging
|
|
5
|
-
from typing import Literal, TypedDict, get_args
|
|
5
|
+
from typing import BinaryIO, Literal, TypedDict, get_args
|
|
6
6
|
|
|
7
7
|
import httpx
|
|
8
8
|
|
|
9
9
|
from riffsdk._internal.config import sdk_base_url
|
|
10
10
|
from riffsdk._internal.transport import ConnectionParams, resolve_connection_params
|
|
11
|
-
from riffsdk.storage._models import Scope
|
|
11
|
+
from riffsdk.storage._models import ObjectMeta, Scope, UploadResult
|
|
12
12
|
|
|
13
13
|
# Why a file matters to the session: an original input, a key file during
|
|
14
14
|
# processing, or an output. Sent as X-Riff-Resource-Importance.
|
|
@@ -152,3 +152,60 @@ def resolve_params(
|
|
|
152
152
|
task_id=task_id,
|
|
153
153
|
uds=uds,
|
|
154
154
|
)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
# Uploads no larger than this (and no larger than the chunk size) go as one
|
|
158
|
+
# PUT /objects request instead of the signed-URL flow, which costs three
|
|
159
|
+
# riff-api calls and a GCS PUT however small the file is. Kept well under
|
|
160
|
+
# riff-api's PUT limit so the whole body can sit in memory.
|
|
161
|
+
SINGLE_PUT_MAX = 8 * 1024 * 1024
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def single_put_limit(chunk_size: int) -> int:
|
|
165
|
+
"""The largest upload sent as a single PUT for this chunk size."""
|
|
166
|
+
return min(chunk_size, SINGLE_PUT_MAX)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def read_up_to(stream: BinaryIO, n: int) -> bytes:
|
|
170
|
+
"""Read ``n`` bytes from ``stream``, fewer only at EOF.
|
|
171
|
+
|
|
172
|
+
A single ``read`` may return less than asked (pipes, sockets), which must
|
|
173
|
+
not be mistaken for the end of the stream.
|
|
174
|
+
"""
|
|
175
|
+
buf = bytearray()
|
|
176
|
+
while len(buf) < n:
|
|
177
|
+
chunk = stream.read(n - len(buf))
|
|
178
|
+
if not chunk:
|
|
179
|
+
break
|
|
180
|
+
buf += chunk
|
|
181
|
+
return bytes(buf)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class PrefixedStream:
|
|
185
|
+
"""A stream that yields ``head`` before reading on from ``rest``.
|
|
186
|
+
|
|
187
|
+
Lets a caller look ahead at the start of a stream (to decide between a
|
|
188
|
+
single PUT and a multipart upload) without losing those bytes.
|
|
189
|
+
"""
|
|
190
|
+
|
|
191
|
+
def __init__(self, head: bytes, rest: BinaryIO) -> None:
|
|
192
|
+
self._head = head
|
|
193
|
+
self._rest = rest
|
|
194
|
+
|
|
195
|
+
def read(self, n: int) -> bytes:
|
|
196
|
+
if not self._head:
|
|
197
|
+
return self._rest.read(n)
|
|
198
|
+
out, self._head = self._head[:n], self._head[n:]
|
|
199
|
+
if len(out) < n:
|
|
200
|
+
out += read_up_to(self._rest, n - len(out))
|
|
201
|
+
return out
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def upload_result_from_meta(meta: ObjectMeta) -> UploadResult:
|
|
205
|
+
return UploadResult(
|
|
206
|
+
key=meta.key,
|
|
207
|
+
version=meta.version,
|
|
208
|
+
size=meta.size,
|
|
209
|
+
content_type=meta.content_type,
|
|
210
|
+
created_at=meta.created_at,
|
|
211
|
+
)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
"""Read the app's task board.
|
|
1
|
+
"""Read the app's task board, and record metadata and the assignee on its tasks.
|
|
2
2
|
|
|
3
3
|
Import the version you are writing against, bound to a short name::
|
|
4
4
|
|
|
5
5
|
import riffsdk.tasks.v0 as tasks
|
|
6
6
|
|
|
7
7
|
task = tasks.get_task("TASK-42")
|
|
8
|
+
tasks.update_task_metadata("TASK-42", {"checked": True})
|
|
8
9
|
|
|
9
10
|
A version does not change under you. When the API changes it appears as a new
|
|
10
11
|
version, and the one you imported keeps behaving as it did.
|