drums-sdk 0.2.5__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.
@@ -0,0 +1,72 @@
1
+ # Changelog
2
+
3
+ All notable changes to the `drums` Python SDK. The SDK talks to drumsd over its HTTP API; the drumsd version each
4
+ SDK version was built against is noted where it matters.
5
+
6
+ ## 0.2.5 - first release on PyPI
7
+
8
+ The first version published on PyPI, as `drums-sdk` (`pip install drums-sdk`; the import name stays `drums`). Versions 0.2.0 to 0.2.4 shipped as wheels sent with invites.
9
+ Everything below in the 0.2.x entries is included.
10
+
11
+ Packaging and release:
12
+
13
+ - Package metadata for PyPI: readme, classifiers, project URLs, `requires-python >= 3.9`, no runtime dependencies.
14
+ - `LICENSE`, `CHANGELOG.md`, `RELEASE.md`, and a GitHub Actions release workflow (PyPI Trusted Publishing, TestPyPI
15
+ on demand).
16
+ - Docstrings no longer point at documents that live in other repositories.
17
+
18
+ Since 0.2.4 (drumsd 0.4.2 and later):
19
+
20
+ - `Env.prefork()`: prepare a fork right after an action, so a later `fork()` from that point is fast.
21
+ - `Reward.audit`, `Reward.audit_flags`, `Reward.trusted`: the per-rollout reward audit drumsd returns (recheck,
22
+ redundant checker, scope, checker timeout or crash). `trusted` is `True` only for a valid episode with a score and
23
+ no audit flag; an older drumsd sends no audit, so `trusted` is `None`, never `True`.
24
+ - `drums.hybrid`: GUI, shell, file and app-API tools over one desktop (`HybridTools`, and `TOOLS` as JSON schema).
25
+ - `drums.mcp`: an MCP stdio server exposing the hybrid tools plus `verify`; `python -m drums.mcp --env ID` or
26
+ `--create [--task task.json]`. Token from `DRUMS_TOKEN`, else the file in `DRUMS_TOKEN_FILE`, else
27
+ `/etc/drums/token`. A bound env is never closed on exit; a created one is.
28
+ - `TaskUnsupported` (422 `task_unsupported`): the task needs the agent itself to act as root, which this execution
29
+ profile does not allow. Setup steps that need root are run by drumsd as provisioning and are supported.
30
+
31
+ ## 0.2.4
32
+
33
+ - `EnvGone` (410, and the older 409 "slot is destroyed"); `close()` is a no-op on a gone env.
34
+ - `fork()` returns `ForkResult`: the list of children plus `.state`, the saved state the fork made.
35
+ `keep_state=False` deletes it when the children close. `last_state` and `last_fork` are deprecated.
36
+ - Leases on `create`, `fork` and `save` (`idle_timeout=`, `ttl=`; default: reaped after 30 minutes unused).
37
+ - The client closes the envs it created at process exit, on SIGTERM/SIGHUP (when their handlers were the default)
38
+ and when used as a context manager; `connect(..., close_on_exit=False)` turns that off.
39
+ - `Reward.invalid_reasons`.
40
+ - The legacy `env()` entry point defaults to the installed image.
41
+
42
+ ## 0.2.3
43
+
44
+ - `client.env_records()` pages through env records (destroyed ones opt-in).
45
+ - `CheckpointStale` for a saved state made from an installed image that has since changed.
46
+
47
+ ## 0.2.2
48
+
49
+ - `step()` raises `ActionFailed` when the action ran and exited non-zero; `check=False` returns the result as is.
50
+ - `Overloaded` (429): create, save and fork are refused near the host's memory limit.
51
+ - `drums.aio` runs calls on its own thread pool (`max_threads`, default 1024), not the event loop's default
52
+ executor, so N envs driven with `asyncio.gather` really run N calls at once.
53
+
54
+ ## 0.2.1
55
+
56
+ - `NotQuiescent` (a `Conflict`), `env.wait_quiescent(timeout, window)`, and `quiesce_timeout=` on `fork` and `save`.
57
+ - `client.delete_state()`, `env.from_state`.
58
+ - `Client()` takes the token from `DRUMS_TOKEN` when none is given.
59
+ - `env.wait_valid()` blocks until the episode's alive gate resolves and raises `GateFailed` if it is invalid.
60
+
61
+ ## 0.2.0
62
+
63
+ - New client: `connect(url, token)`, `client.create(image, task, from_state)`, and on an env `step`, `observe`,
64
+ `fork`, `save`, `verify`, `reset`, `close`.
65
+ - Typed errors carrying the server's status, message and body; errors about an env carry its record and gate report.
66
+ - GET-only retries while the daemon is unreachable; POST and DELETE are never retried.
67
+ - Batch and asyncio variants; `client.metrics()`.
68
+ - Unit tests against a fake daemon (no network).
69
+
70
+ ## 0.1.0
71
+
72
+ - Thin client: `env`, `reset`, `step`, `branch`, `save`, `from_state`, `valid`.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
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]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,5 @@
1
+ include LICENSE
2
+ include README.md
3
+ include CHANGELOG.md
4
+ include RELEASE.md
5
+ recursive-include tests *.py
@@ -0,0 +1,141 @@
1
+ Metadata-Version: 2.4
2
+ Name: drums-sdk
3
+ Version: 0.2.5
4
+ Summary: Drums SDK: isolated desktop environments for computer-use RL. Create a desktop, act, screenshot, fork, verify.
5
+ Author: Drums Labs
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://drums.run
8
+ Project-URL: Documentation, https://console.drums.run/docs
9
+ Project-URL: SDK reference, https://console.drums.run/docs/reference/python-sdk
10
+ Project-URL: Repository, https://github.com/Drums-Labs/drums-python-sdk
11
+ Project-URL: Changelog, https://github.com/Drums-Labs/drums-python-sdk/blob/main/CHANGELOG.md
12
+ Project-URL: Issues, https://github.com/Drums-Labs/drums-python-sdk/issues
13
+ Keywords: drums,computer-use,reinforcement-learning,rl,desktop,environment,osworld,agents,sandbox
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
26
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
+ Requires-Python: >=3.9
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Dynamic: license-file
31
+
32
+ # drums-sdk
33
+
34
+ Python SDK for [Drums](https://drums.run): isolated desktop environments for computer-use agents and RL.
35
+ Create a desktop, act in it, take screenshots, fork it into copies of the same state, and score it with a task's
36
+ checker. Standard library only; Python 3.9 or later.
37
+
38
+ Full documentation: **[console.drums.run/docs](https://console.drums.run/docs)**
39
+
40
+ ## Five-minute start
41
+
42
+ ### 1. Install
43
+
44
+ ```bash
45
+ python3 -m venv drums-venv
46
+ drums-venv/bin/pip install drums-sdk
47
+ ```
48
+
49
+ The package on PyPI is `drums-sdk`; the import name is `drums`.
50
+
51
+ ```python
52
+ import drums
53
+ ```
54
+
55
+ ### 2. Point it at your Drums
56
+
57
+ The SDK reads two environment variables. Your API key comes from **API Keys** in the
58
+ [console](https://console.drums.run); it starts with `drums_sk_` and is shown once.
59
+
60
+ ```bash
61
+ export DRUMS_URL=https://beta.drums.run/gw # Drums Cloud gateway; or http://127.0.0.1:7070 for a local drumsd
62
+ export DRUMS_TOKEN=drums_sk_... # your API key
63
+ ```
64
+
65
+ Check the connection:
66
+
67
+ ```python
68
+ import drums
69
+
70
+ client = drums.connect() # reads DRUMS_URL and DRUMS_TOKEN
71
+ print(client.health()["version"])
72
+ ```
73
+
74
+ A `401` raises `drums.AuthError`: the key is mistyped, revoked or expired.
75
+
76
+ ### 3. Create a computer, screenshot, act, verify, destroy
77
+
78
+ Save as `quickstart.py` and run `drums-venv/bin/python quickstart.py`. It starts a desktop with OSWorld task
79
+ `e0df059f` (rename a folder on the Desktop), waits until every gate of the episode has passed, saves a screenshot,
80
+ performs the task with one action, runs the task's checker and closes the desktop.
81
+
82
+ ```python
83
+ import drums
84
+
85
+ with drums.connect() as client: # closes every desktop it created when the block ends
86
+ with client.create(task="e0df059f", ttl=900) as env: # OSWorld task id; ttl: lifetime in seconds
87
+ env.wait_valid() # every gate of this episode passed
88
+ obs = env.observe() # PNG screenshot plus metadata
89
+ open("screen.png", "wb").write(obs.png)
90
+ print("task:", obs.meta["instruction"])
91
+ env.step({"type": "execute", "shell": True,
92
+ "command": "mv ~/Desktop/todo_list_Jan_1 ~/Desktop/todo_list_Jan_2"})
93
+ reward = env.verify(strict=False) # the task's checker, with the episode's validity
94
+ print("score", reward.score, "valid", reward.valid, reward.invalid_reasons)
95
+ print("computers left:", len(client.envs())) # 0: the with-block destroyed it
96
+ ```
97
+
98
+ Expected output (ids and sizes differ):
99
+
100
+ ```text
101
+ task: I have a directory named "todo_list_Jan_1". Can you help me change its name into "todo_list_Jan_2"?
102
+ score 1 valid True []
103
+ computers left: 0
104
+ ```
105
+
106
+ A GUI agent acts with pyautogui instead of a shell command: `env.step("pyautogui.click(960, 540)")`.
107
+ Use a score only when `valid` is `True`; with the default `strict=True`, `verify()` raises `InvalidEpisode`
108
+ for an invalid episode instead of returning a reward.
109
+
110
+ ### 4. Go further
111
+
112
+ - Fork one desktop into N copies of the same state for group rollouts: `with env.fork(8) as kids: ...`
113
+ ([guide](https://console.drums.run/docs/guides/group-rollouts-with-fork))
114
+ - Run a policy over many tasks: [Evaluate on OSWorld](https://console.drums.run/docs/guides/evaluate-on-osworld)
115
+ - `drums.aio` is the asyncio variant of the same calls; `drums.hybrid` adds shell, file and app-API tools over one
116
+ desktop; `python -m drums.mcp` serves them to an agent over MCP (stdio).
117
+ - Every method: [Python SDK reference](https://console.drums.run/docs/reference/python-sdk).
118
+ Every endpoint: [HTTP API](https://console.drums.run/docs/reference/http-api).
119
+ If something fails: [Errors](https://console.drums.run/docs/reference/errors).
120
+
121
+ ## How it behaves
122
+
123
+ - **Cleanup.** `with drums.connect() as client:` closes every desktop the client created when the block ends, and so
124
+ do process exit and SIGTERM/SIGHUP. Desktops and saved states also have server-side leases (default: reaped after
125
+ 30 minutes unused), so a crashed trainer does not hold a host.
126
+ - **Validity.** Every episode starts with a gate report (isolation, mounts, network, limits, state hash, processes
127
+ alive after resume). `Reward.valid` is `True` only when every gate passed and the desktop was never quarantined.
128
+ - **Retries.** GET requests are retried while the server is unreachable (up to `retry_s`, default 60 s). POST and
129
+ DELETE are never retried: after a lost reply the outcome is unknown, so check `client.envs()` before trying again.
130
+ - **Errors.** Every failure is a typed exception under `drums.DrumsError` carrying the server's status, message and
131
+ body; errors about a desktop carry its record and gate report.
132
+
133
+ ## Development
134
+
135
+ ```bash
136
+ git clone https://github.com/Drums-Labs/drums-python-sdk.git
137
+ cd drums-python-sdk
138
+ python3 -m unittest discover -s tests -v # runs against a fake daemon; no network
139
+ ```
140
+
141
+ See [CHANGELOG.md](CHANGELOG.md) for what changed in each version and [RELEASE.md](RELEASE.md) for how a release is cut.
@@ -0,0 +1,110 @@
1
+ # drums-sdk
2
+
3
+ Python SDK for [Drums](https://drums.run): isolated desktop environments for computer-use agents and RL.
4
+ Create a desktop, act in it, take screenshots, fork it into copies of the same state, and score it with a task's
5
+ checker. Standard library only; Python 3.9 or later.
6
+
7
+ Full documentation: **[console.drums.run/docs](https://console.drums.run/docs)**
8
+
9
+ ## Five-minute start
10
+
11
+ ### 1. Install
12
+
13
+ ```bash
14
+ python3 -m venv drums-venv
15
+ drums-venv/bin/pip install drums-sdk
16
+ ```
17
+
18
+ The package on PyPI is `drums-sdk`; the import name is `drums`.
19
+
20
+ ```python
21
+ import drums
22
+ ```
23
+
24
+ ### 2. Point it at your Drums
25
+
26
+ The SDK reads two environment variables. Your API key comes from **API Keys** in the
27
+ [console](https://console.drums.run); it starts with `drums_sk_` and is shown once.
28
+
29
+ ```bash
30
+ export DRUMS_URL=https://beta.drums.run/gw # Drums Cloud gateway; or http://127.0.0.1:7070 for a local drumsd
31
+ export DRUMS_TOKEN=drums_sk_... # your API key
32
+ ```
33
+
34
+ Check the connection:
35
+
36
+ ```python
37
+ import drums
38
+
39
+ client = drums.connect() # reads DRUMS_URL and DRUMS_TOKEN
40
+ print(client.health()["version"])
41
+ ```
42
+
43
+ A `401` raises `drums.AuthError`: the key is mistyped, revoked or expired.
44
+
45
+ ### 3. Create a computer, screenshot, act, verify, destroy
46
+
47
+ Save as `quickstart.py` and run `drums-venv/bin/python quickstart.py`. It starts a desktop with OSWorld task
48
+ `e0df059f` (rename a folder on the Desktop), waits until every gate of the episode has passed, saves a screenshot,
49
+ performs the task with one action, runs the task's checker and closes the desktop.
50
+
51
+ ```python
52
+ import drums
53
+
54
+ with drums.connect() as client: # closes every desktop it created when the block ends
55
+ with client.create(task="e0df059f", ttl=900) as env: # OSWorld task id; ttl: lifetime in seconds
56
+ env.wait_valid() # every gate of this episode passed
57
+ obs = env.observe() # PNG screenshot plus metadata
58
+ open("screen.png", "wb").write(obs.png)
59
+ print("task:", obs.meta["instruction"])
60
+ env.step({"type": "execute", "shell": True,
61
+ "command": "mv ~/Desktop/todo_list_Jan_1 ~/Desktop/todo_list_Jan_2"})
62
+ reward = env.verify(strict=False) # the task's checker, with the episode's validity
63
+ print("score", reward.score, "valid", reward.valid, reward.invalid_reasons)
64
+ print("computers left:", len(client.envs())) # 0: the with-block destroyed it
65
+ ```
66
+
67
+ Expected output (ids and sizes differ):
68
+
69
+ ```text
70
+ task: I have a directory named "todo_list_Jan_1". Can you help me change its name into "todo_list_Jan_2"?
71
+ score 1 valid True []
72
+ computers left: 0
73
+ ```
74
+
75
+ A GUI agent acts with pyautogui instead of a shell command: `env.step("pyautogui.click(960, 540)")`.
76
+ Use a score only when `valid` is `True`; with the default `strict=True`, `verify()` raises `InvalidEpisode`
77
+ for an invalid episode instead of returning a reward.
78
+
79
+ ### 4. Go further
80
+
81
+ - Fork one desktop into N copies of the same state for group rollouts: `with env.fork(8) as kids: ...`
82
+ ([guide](https://console.drums.run/docs/guides/group-rollouts-with-fork))
83
+ - Run a policy over many tasks: [Evaluate on OSWorld](https://console.drums.run/docs/guides/evaluate-on-osworld)
84
+ - `drums.aio` is the asyncio variant of the same calls; `drums.hybrid` adds shell, file and app-API tools over one
85
+ desktop; `python -m drums.mcp` serves them to an agent over MCP (stdio).
86
+ - Every method: [Python SDK reference](https://console.drums.run/docs/reference/python-sdk).
87
+ Every endpoint: [HTTP API](https://console.drums.run/docs/reference/http-api).
88
+ If something fails: [Errors](https://console.drums.run/docs/reference/errors).
89
+
90
+ ## How it behaves
91
+
92
+ - **Cleanup.** `with drums.connect() as client:` closes every desktop the client created when the block ends, and so
93
+ do process exit and SIGTERM/SIGHUP. Desktops and saved states also have server-side leases (default: reaped after
94
+ 30 minutes unused), so a crashed trainer does not hold a host.
95
+ - **Validity.** Every episode starts with a gate report (isolation, mounts, network, limits, state hash, processes
96
+ alive after resume). `Reward.valid` is `True` only when every gate passed and the desktop was never quarantined.
97
+ - **Retries.** GET requests are retried while the server is unreachable (up to `retry_s`, default 60 s). POST and
98
+ DELETE are never retried: after a lost reply the outcome is unknown, so check `client.envs()` before trying again.
99
+ - **Errors.** Every failure is a typed exception under `drums.DrumsError` carrying the server's status, message and
100
+ body; errors about a desktop carry its record and gate report.
101
+
102
+ ## Development
103
+
104
+ ```bash
105
+ git clone https://github.com/Drums-Labs/drums-python-sdk.git
106
+ cd drums-python-sdk
107
+ python3 -m unittest discover -s tests -v # runs against a fake daemon; no network
108
+ ```
109
+
110
+ See [CHANGELOG.md](CHANGELOG.md) for what changed in each version and [RELEASE.md](RELEASE.md) for how a release is cut.
@@ -0,0 +1,113 @@
1
+ # Releasing `drums-sdk` to PyPI
2
+
3
+ The distribution on PyPI is `drums-sdk`; the import name stays `drums`. (PyPI rejected the name `drums` as
4
+ too similar to the existing project `drum`.)
5
+
6
+ The release is automated by `.github/workflows/release.yml`. A pushed tag `vX.Y.Z` builds, checks and tests the
7
+ package and publishes it to PyPI; a manual run of the workflow publishes to TestPyPI first. No tokens are stored in
8
+ the repository: publishing uses PyPI Trusted Publishing (OIDC). The commands below are everything the owner runs.
9
+
10
+ ## 0. One-time decisions and setup (owner)
11
+
12
+ ### 0.1 License
13
+
14
+ Apache License 2.0 (`LICENSE`, `license = "Apache-2.0"` in `pyproject.toml`, confirmed 2026-11-12). The workflow
15
+ refuses to publish if the line is removed or `LICENSE` is a placeholder.
16
+
17
+ ### 0.2 Register the Trusted Publisher on PyPI
18
+
19
+ The `drums-sdk` project does not exist on PyPI yet, so register a **pending** publisher (it becomes the project's
20
+ publisher on the first upload). Signed in to pypi.org as the account that will own the project:
21
+
22
+ 1. Open https://pypi.org/manage/account/publishing/
23
+ 2. Under "Add a new pending publisher", choose **GitHub** and enter exactly:
24
+
25
+ | Field | Value |
26
+ |---|---|
27
+ | PyPI project name | `drums-sdk` |
28
+ | Owner | `Drums-Labs` |
29
+ | Repository name | `drums-python-sdk` |
30
+ | Workflow name | `release.yml` |
31
+ | Environment name | `pypi` |
32
+
33
+ 3. Do the same on TestPyPI at https://test.pypi.org/manage/account/publishing/ with the environment name
34
+ `testpypi` (the other four fields identical). TestPyPI is a separate account; create one if needed.
35
+
36
+ ### 0.3 Create the GitHub environments
37
+
38
+ In the repository: Settings -> Environments -> New environment. Create `pypi` and `testpypi`. For `pypi`, add
39
+ yourself as a required reviewer so a tag push cannot publish without a click from you. (Trusted Publishing is bound
40
+ to these environment names; the names must match the table above.)
41
+
42
+ ### 0.4 Fallback: an API token instead of OIDC
43
+
44
+ Only if Trusted Publishing cannot be used: create a project-scoped API token on pypi.org and add it as the
45
+ repository secret `PYPI_API_TOKEN` (and `TEST_PYPI_API_TOKEN` for TestPyPI). The workflow uses a token when the secret
46
+ exists and OIDC otherwise. Never paste a token into a file, a command line or a chat.
47
+
48
+ ## 1. Merge the release PR
49
+
50
+ Merge `pypi-release` into `main`. Confirm `main` is what you want
51
+ to ship:
52
+
53
+ ```bash
54
+ git checkout main && git pull --ff-only
55
+ python3 -m unittest discover -s tests
56
+ python3 -c 'import tomllib; print(tomllib.load(open("pyproject.toml","rb"))["project"]["version"])'
57
+ ```
58
+
59
+ The printed version is the release version; `drums/__init__.py` must say the same (`__version__`).
60
+
61
+ ## 2. TestPyPI first
62
+
63
+ Run the workflow by hand; it publishes to TestPyPI only:
64
+
65
+ ```bash
66
+ gh workflow run release.yml --ref main
67
+ gh run watch
68
+ ```
69
+
70
+ Then verify the TestPyPI package in a clean venv. `--extra-index-url` is not needed (the package has no
71
+ dependencies), and `--no-deps` makes sure nothing is pulled from anywhere else:
72
+
73
+ ```bash
74
+ cd "$(mktemp -d)"
75
+ python3 -m venv v && v/bin/pip install --no-deps -i https://test.pypi.org/simple/ drums-sdk
76
+ v/bin/python -c 'import drums; print(drums.__version__); drums.Client'
77
+ ```
78
+
79
+ Check https://test.pypi.org/project/drums-sdk/ : the README renders, the links are right, the license shows.
80
+
81
+ ## 3. Tag and publish to PyPI
82
+
83
+ ```bash
84
+ V=$(python3 -c 'import tomllib; print(tomllib.load(open("pyproject.toml","rb"))["project"]["version"])')
85
+ git tag -a "v$V" -m "drums $V"
86
+ git push origin "v$V"
87
+ gh run watch
88
+ ```
89
+
90
+ The `publish to PyPI` job waits for your approval on the `pypi` environment (step 0.3); approve it in the Actions
91
+ tab. The job prints the SHA256 of every file it uploads.
92
+
93
+ ## 4. Verify the public package
94
+
95
+ ```bash
96
+ cd "$(mktemp -d)"
97
+ python3 -m venv v && v/bin/pip install drums-sdk
98
+ v/bin/python -c 'import drums; print(drums.__version__); drums.Client'
99
+ ```
100
+
101
+ Then check https://pypi.org/project/drums-sdk/ and create the GitHub release from the tag:
102
+
103
+ ```bash
104
+ gh release create "v$V" --title "drums $V" --notes-file <(awk "/^## $V/{f=1;next} /^## /{f=0} f" CHANGELOG.md)
105
+ ```
106
+
107
+ ## 5. After the first release
108
+
109
+ - Later releases: bump `version` in `pyproject.toml` and `__version__` in `drums/__init__.py` together, add a
110
+ `CHANGELOG.md` entry, merge, then steps 2 to 4. The workflow fails if the tag and the version disagree.
111
+ - A version can be uploaded to PyPI exactly once. A broken release gets a new patch version, never a re-upload.
112
+ - Update the install instructions in the docs (`console.drums.run/docs/quickstart` and
113
+ `/docs/reference/python-sdk` still describe installing from a wheel file) to `pip install drums-sdk`.