runpodkit 0.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.
- runpodkit-0.2.0/CHANGELOG.md +32 -0
- runpodkit-0.2.0/CONTRIBUTING.md +36 -0
- runpodkit-0.2.0/LICENSE +21 -0
- runpodkit-0.2.0/MANIFEST.in +3 -0
- runpodkit-0.2.0/PKG-INFO +380 -0
- runpodkit-0.2.0/README.md +350 -0
- runpodkit-0.2.0/SECURITY.md +17 -0
- runpodkit-0.2.0/install.sh +137 -0
- runpodkit-0.2.0/pyproject.toml +46 -0
- runpodkit-0.2.0/runpodkit/__init__.py +10 -0
- runpodkit-0.2.0/runpodkit/__main__.py +6 -0
- runpodkit-0.2.0/runpodkit/cli.py +248 -0
- runpodkit-0.2.0/runpodkit/client.py +422 -0
- runpodkit-0.2.0/runpodkit/lib/runpod.sh +89 -0
- runpodkit-0.2.0/runpodkit.egg-info/PKG-INFO +380 -0
- runpodkit-0.2.0/runpodkit.egg-info/SOURCES.txt +25 -0
- runpodkit-0.2.0/runpodkit.egg-info/dependency_links.txt +1 -0
- runpodkit-0.2.0/runpodkit.egg-info/entry_points.txt +2 -0
- runpodkit-0.2.0/runpodkit.egg-info/top_level.txt +1 -0
- runpodkit-0.2.0/setup.cfg +4 -0
- runpodkit-0.2.0/tests/fixtures/pod_exited.json +83 -0
- runpodkit-0.2.0/tests/fixtures/pod_running.json +84 -0
- runpodkit-0.2.0/tests/helpers.py +136 -0
- runpodkit-0.2.0/tests/test_bash.py +447 -0
- runpodkit-0.2.0/tests/test_cli.py +596 -0
- runpodkit-0.2.0/tests/test_client.py +648 -0
- runpodkit-0.2.0/tests/test_install.py +212 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. Versions follow [Semantic Versioning](https://semver.org/).
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [0.2.0] - 2026-12-01
|
|
8
|
+
|
|
9
|
+
First public release.
|
|
10
|
+
|
|
11
|
+
- MIT license, packaging metadata, and GitHub Actions CI: Python 3.9-3.15 on Linux, shell tests under a source-built GNU Bash 3.2.57, and a separate macOS workflow.
|
|
12
|
+
- README rewritten for general use: quick start, pip install from GitHub, `install.sh` for shared clones, vendored-copy recipe.
|
|
13
|
+
- README: "Setting your API key" covers a plain environment variable or [cred-broker](https://github.com/kcherry497/cred-broker) for AI coding agents.
|
|
14
|
+
- Contributing guide, security policy, issue and pull-request templates, Dependabot for Actions.
|
|
15
|
+
- Test fixtures anonymized (documentation IP ranges, placeholder pod ID).
|
|
16
|
+
- `create`: if the recovery lookup after an uncertain POST also fails, the error now still says `create outcome UNKNOWN` instead of surfacing only the POST error, so it is never mistaken for a safe-to-retry failure.
|
|
17
|
+
- Client closes HTTP error responses after reading them (Python 3.14+ warned about the leak).
|
|
18
|
+
- CLI: `runpodkit --version`; `bash-lib` output is never redacted, and placeholder keys shorter than 8 characters are not redacted (they mangled ordinary output).
|
|
19
|
+
|
|
20
|
+
## [0.1.1] - 2026-11-29
|
|
21
|
+
|
|
22
|
+
- `create` snapshots the IDs of same-name pods before its first POST. The retry guard and recovery only return a pod that is not in that snapshot, so an older same-name pod is never mistaken for the newly created, billing one.
|
|
23
|
+
- `find_pod` gains `exclude_ids`.
|
|
24
|
+
|
|
25
|
+
## [0.1.0] - 2026-11-29
|
|
26
|
+
|
|
27
|
+
- Initial release: `RunPod` client for REST v2 (list, get, find, start, stop, restart, terminate, network volumes, create with guarded GPU fallback, `wait_status`, `wait_ssh` with a TCP check), pure helpers (`pod_state`, `ssh_endpoint`, `to_v1`), the `runpodkit` CLI, the Bash library, and `install.sh`.
|
|
28
|
+
|
|
29
|
+
[Unreleased]: https://github.com/kcherry497/runpod-kit/compare/v0.2.0...HEAD
|
|
30
|
+
[0.2.0]: https://github.com/kcherry497/runpod-kit/releases/tag/v0.2.0
|
|
31
|
+
[0.1.1]: https://github.com/kcherry497/runpod-kit/blob/main/CHANGELOG.md#011---2026-11-29
|
|
32
|
+
[0.1.0]: https://github.com/kcherry497/runpod-kit/blob/main/CHANGELOG.md#010---2026-11-29
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Contributing to runpodkit
|
|
2
|
+
|
|
3
|
+
Thanks for helping. A few ground rules keep this toolkit small and safe to depend on.
|
|
4
|
+
|
|
5
|
+
## Ground rules
|
|
6
|
+
|
|
7
|
+
- **Standard library only.** No runtime dependencies. Tests use `unittest`.
|
|
8
|
+
- **Python 3.9+ and Bash 3.2+.** The Bash library has to keep working on the macOS system Bash.
|
|
9
|
+
- **Offline tests for every behavior change.** HTTP and TCP are mocked; the suite must never touch the real RunPod API.
|
|
10
|
+
- **Money safety is a feature.** Changes to `create()` must preserve the rules in the README: never re-POST after an uncertain result, and never return a pod the call did not create.
|
|
11
|
+
- **Never log or print the API key.** Keys come from the environment only, never argv.
|
|
12
|
+
|
|
13
|
+
## Development
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/kcherry497/runpod-kit.git
|
|
17
|
+
cd runpod-kit
|
|
18
|
+
python3 -m unittest discover -s tests -v
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
To run the shell tests under several Bash builds (for example a Bash 3.2 binary), pass absolute paths:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
RUNPODKIT_TEST_BASHES=/path/to/bash3.2:/bin/bash python3 -m unittest discover -s tests -v
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Pull requests
|
|
28
|
+
|
|
29
|
+
1. Open an issue first for anything larger than a small fix.
|
|
30
|
+
2. Keep each PR focused, with tests.
|
|
31
|
+
3. Add a line under an "Unreleased" heading in `CHANGELOG.md`.
|
|
32
|
+
4. CI must pass on every Python version and under Bash 3.2.57. The separate macOS workflow should pass too; it can lag when GitHub's macOS runners are busy.
|
|
33
|
+
|
|
34
|
+
## Reporting RunPod API changes
|
|
35
|
+
|
|
36
|
+
RunPod's API shifts from time to time. If something broke, an issue with a redacted response body (strip `env` and any IDs you care about) is the most useful report you can file.
|
runpodkit-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kevin Cherry
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
runpodkit-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: runpodkit
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Dependency-free RunPod REST v2 pod control for Python, Bash and the command line
|
|
5
|
+
Author: Kevin Cherry
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/kcherry497/runpod-kit
|
|
8
|
+
Project-URL: Issues, https://github.com/kcherry497/runpod-kit/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/kcherry497/runpod-kit/blob/main/CHANGELOG.md
|
|
10
|
+
Keywords: runpod,gpu,cloud,pods,cli
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: POSIX
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
24
|
+
Classifier: Programming Language :: Unix Shell
|
|
25
|
+
Classifier: Topic :: System :: Systems Administration
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
<p align="center">
|
|
32
|
+
<img src=".github/assets/banner.svg" alt="runpodkit: RunPod pod control for Python, Bash and the CLI" width="100%">
|
|
33
|
+
</p>
|
|
34
|
+
|
|
35
|
+
<p align="center">
|
|
36
|
+
<a href="https://github.com/kcherry497/runpod-kit/actions/workflows/ci.yml"><img src="https://github.com/kcherry497/runpod-kit/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
37
|
+
<a href="https://github.com/kcherry497/runpod-kit/releases"><img src="https://img.shields.io/github/v/release/kcherry497/runpod-kit?sort=semver" alt="Release"></a>
|
|
38
|
+
<img src="https://img.shields.io/badge/python-3.9%20%E2%80%93%203.15-3776AB?logo=python&logoColor=white" alt="Python 3.9 to 3.15">
|
|
39
|
+
<img src="https://img.shields.io/badge/bash-3.2%2B-4EAA25?logo=gnubash&logoColor=white" alt="Bash 3.2+">
|
|
40
|
+
<img src="https://img.shields.io/badge/dependencies-0-brightgreen" alt="Zero dependencies">
|
|
41
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT license"></a>
|
|
42
|
+
</p>
|
|
43
|
+
|
|
44
|
+
<p align="center">
|
|
45
|
+
<a href="#quick-start">Quick start</a> ·
|
|
46
|
+
<a href="#install">Install</a> ·
|
|
47
|
+
<a href="#setting-your-api-key">API key</a> ·
|
|
48
|
+
<a href="#python-usage">Python</a> ·
|
|
49
|
+
<a href="#bash-usage">Bash</a> ·
|
|
50
|
+
<a href="#cli-reference">CLI</a> ·
|
|
51
|
+
<a href="#create-money-safety-rules">Money safety</a>
|
|
52
|
+
</p>
|
|
53
|
+
|
|
54
|
+
A small, dependency-free toolkit for controlling [RunPod](https://www.runpod.io/) GPU pods from Python, Bash scripts, and the command line: list, start, stop, restart, create, terminate, and wait for a reachable SSH endpoint.
|
|
55
|
+
|
|
56
|
+
- **Python**: standard library only, Python 3.9+.
|
|
57
|
+
- **Bash**: a sourceable library that works on Bash 3.2+, including the macOS system Bash.
|
|
58
|
+
- **CLI**: `runpodkit`, which the Bash library wraps.
|
|
59
|
+
|
|
60
|
+
It targets the RunPod REST v2 API (`https://api.runpod.io/v2`). The v1 API at `rest.runpod.io` is retired; `to_v1()` adds v1-shaped fields for code that still expects them.
|
|
61
|
+
|
|
62
|
+
## Why another client?
|
|
63
|
+
|
|
64
|
+
Two things bit us in production. This toolkit handles both for you.
|
|
65
|
+
|
|
66
|
+
> [!WARNING]
|
|
67
|
+
> **Stale SSH endpoints after a start.** For roughly 25 seconds after a start, the API reports `RUNNING` with the *previous* run's SSH port, which refuses connections, and the port changes on every restart. `wait_ssh` re-reads the pod on every poll and only returns an endpoint that actually accepts TCP.
|
|
68
|
+
|
|
69
|
+
> [!CAUTION]
|
|
70
|
+
> **Double-billing on create.** A timeout or 5xx on create does not mean no pod was made. `create` never re-POSTs after an uncertain result. It recovers the pod it made by name, or tells you plainly that the outcome is unknown. See [create() money-safety rules](#create-money-safety-rules).
|
|
71
|
+
|
|
72
|
+
## Quick start
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pipx install "git+https://github.com/kcherry497/runpod-kit.git@v0.2.0" # or pip inside a venv; see Install
|
|
76
|
+
export RUNPOD_API_KEY=... # or let an AI agent use it safely: see "Setting your API key"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Python**
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from runpodkit import RunPod, pod_state
|
|
83
|
+
|
|
84
|
+
rp = RunPod() # reads RUNPOD_API_KEY
|
|
85
|
+
for pod in rp.list_pods():
|
|
86
|
+
print(pod["id"], pod["name"], pod_state(pod))
|
|
87
|
+
|
|
88
|
+
rp.start("POD_ID")
|
|
89
|
+
host, port = rp.wait_ssh("POD_ID") # only returns once TCP connects
|
|
90
|
+
print(f"ssh -p {port} root@{host}")
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**CLI**
|
|
94
|
+
|
|
95
|
+
```console
|
|
96
|
+
$ runpodkit list | jq -r '.[] | "\(.id) \(.name) \(.status)"'
|
|
97
|
+
$ runpodkit start POD_ID >/dev/null && runpodkit wait-ssh POD_ID
|
|
98
|
+
203.0.113.10 22088
|
|
99
|
+
$ runpodkit stop POD_ID >/dev/null
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Bash**
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
. "$(runpodkit bash-lib)"
|
|
106
|
+
rp_action "$POD_ID" start >/dev/null
|
|
107
|
+
read -r host port < <(rp_wait_ssh "$POD_ID" 320) && ssh -p "$port" "root@$host"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Install
|
|
111
|
+
|
|
112
|
+
As a command-line tool, with [pipx](https://pipx.pypa.io/) (no dependencies):
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
pipx install "git+https://github.com/kcherry497/runpod-kit.git@v0.2.0"
|
|
116
|
+
runpodkit --version
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
As a library in your project, inside its virtual environment:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
python3 -m pip install "git+https://github.com/kcherry497/runpod-kit.git@v0.2.0"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Plain `pip install` into a system Python is refused on Ubuntu 23.04+, Debian 12+ and Homebrew Python (PEP 668); use pipx, a venv, or `install.sh` below.
|
|
126
|
+
|
|
127
|
+
Or keep a clone and link it into one or more interpreters without pip:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
git clone https://github.com/kcherry497/runpod-kit.git
|
|
131
|
+
cd runpod-kit
|
|
132
|
+
./install.sh python3 # user site + ~/.local/bin/runpodkit
|
|
133
|
+
# a root-owned venv (e.g. a service), with the launcher on cron's PATH:
|
|
134
|
+
sudo RUNPODKIT_BIN=/usr/local/bin ./install.sh /srv/myapp/venv/bin/python
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
`install.sh` writes a `runpodkit.pth` into each interpreter's site-packages, pointing at the clone. It also writes a `runpodkit` launcher to `${RUNPODKIT_BIN:-~/.local/bin}`. It is idempotent and needs no pip or network. Don't run it under sudo for a *system* `python3`: that would write root's user site. The clone must be readable by every user that imports it.
|
|
138
|
+
|
|
139
|
+
Two things follow from the `.pth` approach, which make it handy when several programs on one host share the toolkit:
|
|
140
|
+
|
|
141
|
+
- **Updating is `git pull`** in the clone. Every importer and every bash script picks the new code up immediately.
|
|
142
|
+
- **Rollback** is `git checkout <tag>`.
|
|
143
|
+
|
|
144
|
+
### Setting your API key
|
|
145
|
+
|
|
146
|
+
runpodkit reads the key from `RUNPOD_API_KEY` and nowhere else: there is no key flag, so it never lands in argv or shell history. Pick whichever way of supplying it fits.
|
|
147
|
+
|
|
148
|
+
**Option 1: an environment variable.** Simplest, for your own shell or a service unit:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
export RUNPOD_API_KEY=... # from the RunPod console (Settings → API Keys)
|
|
152
|
+
runpodkit list
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Option 2: [cred-broker](https://github.com/kcherry497/cred-broker), when an AI coding agent drives runpodkit.** The key stays encrypted in `pass`, and the agent works with the name `runpod` only. `cred exec` decrypts the key into `RUNPOD_API_KEY` for that one command, filters it out of the command's output, and logs the call. Add an entry to `~/.config/cred-broker/manifest.yaml`:
|
|
156
|
+
|
|
157
|
+
```yaml
|
|
158
|
+
runpod:
|
|
159
|
+
describes: RunPod API key (list/start/stop/create/terminate pods)
|
|
160
|
+
pass_path: agent/runpod
|
|
161
|
+
env: RUNPOD_API_KEY
|
|
162
|
+
risk: high
|
|
163
|
+
note: create starts billing; terminate deletes the pod and its disk.
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Store the key once, in your own terminal (`! cred set runpod` inside Claude Code), then wrap any runpodkit call:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
cred set runpod # prompts; the value never passes through the agent
|
|
170
|
+
cred exec runpod -- runpodkit list
|
|
171
|
+
cred exec runpod -- python3 my_pod_script.py # Python API: RunPod() picks the key up from the env
|
|
172
|
+
cred exec runpod -- bash -c '. "$(runpodkit bash-lib)"; rp_wait_ssh "$1" 320' _ "$POD_ID"
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
A RunPod key can start billing pods, so give the agent a key of its own where you can, and mark it `risk: high` as above. See cred-broker's [threat model](https://github.com/kcherry497/cred-broker#threat-model) for what it does and does not protect against.
|
|
176
|
+
|
|
177
|
+
### Where `runpodkit.pth` goes
|
|
178
|
+
|
|
179
|
+
`./install.sh [PYTHON ...]` defaults to `python3`. It checks that each interpreter is Python >= 3.9 and writes `runpodkit.pth` containing the absolute clone directory:
|
|
180
|
+
|
|
181
|
+
| Interpreter | Destination for `runpodkit.pth` |
|
|
182
|
+
| --- | --- |
|
|
183
|
+
| Venv | That venv's `sysconfig` purelib directory |
|
|
184
|
+
| System Python marked externally managed under PEP 668 | That interpreter's user site |
|
|
185
|
+
| Unmanaged system Python with an existing, writable purelib | Its purelib directory |
|
|
186
|
+
| Unmanaged system Python with missing or non-writable purelib | Its user site, with a diagnostic |
|
|
187
|
+
|
|
188
|
+
A non-writable venv purelib is an error. The installer checks imports from a neutral directory and warns if an interpreter does not resolve this clone, for example because its user site is disabled.
|
|
189
|
+
|
|
190
|
+
### Vendored copy (no install)
|
|
191
|
+
|
|
192
|
+
To ship runpodkit inside another app, copy the `runpodkit/` package next to your scripts and point `RUNPODKIT_BUNDLE` at the directory containing it. Define the CLI as a shell function and source the library:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
RUNPODKIT_BUNDLE=/path/to/bundle
|
|
196
|
+
runpodkit() {
|
|
197
|
+
PYTHONPATH="${RUNPODKIT_BUNDLE}${PYTHONPATH:+:$PYTHONPATH}" python3 -m runpodkit "$@"
|
|
198
|
+
}
|
|
199
|
+
. "$(runpodkit bash-lib)"
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Python usage
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
from runpodkit import (
|
|
206
|
+
BOOTING, RunPod, RunPodError, RunPodTimeoutError,
|
|
207
|
+
pod_state, ssh_endpoint, to_v1,
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
rp = RunPod()
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
`RunPod(api_key=None, base_url=None, timeout=30)` reads `RUNPOD_API_KEY` when no key argument is supplied, and `RUNPOD_API_URL` when no base URL argument is supplied. The URL defaults to `https://api.runpod.io/v2`, with trailing slashes removed. A missing or empty key raises `RunPodError`. The HTTP request timeout is in seconds.
|
|
214
|
+
|
|
215
|
+
| Method | Result |
|
|
216
|
+
| --- | --- |
|
|
217
|
+
| `rp.list_pods()` | List of pod dicts across all cursor pages, including terminated pods |
|
|
218
|
+
| `rp.get_pod(pod_id)` | Pod dict, or `None` on HTTP 404 |
|
|
219
|
+
| `rp.find_pod(name, include_terminated=False, exclude_ids=())` | First exact-name, non-terminated match in API order, skipping IDs in `exclude_ids`; otherwise `None`. With `include_terminated=True`, falls back to the first terminated match |
|
|
220
|
+
| `rp.start(pod_id)` | POSTs the `start` action; returns pod dict |
|
|
221
|
+
| `rp.stop(pod_id)` | POSTs the `stop` action; returns pod dict |
|
|
222
|
+
| `rp.restart(pod_id)` | POSTs the `restart` action; returns pod dict |
|
|
223
|
+
| `rp.terminate(pod_id)` | DELETE HTTP status, normally `204`; returns `404` when already missing |
|
|
224
|
+
| `rp.network_volumes()` | List of network-volume dicts |
|
|
225
|
+
| `rp.wait_status(pod_id, want, timeout=240, poll=6)` | Pod dict when normalized state matches `want`, case insensitive; `{}` for a missing pod when waiting for `NOTFOUND` |
|
|
226
|
+
| `rp.wait_ssh(pod_id, timeout=320, poll=6, tcp_timeout=5)` | `(host, port)` after a fresh GET yields an endpoint that accepts TCP |
|
|
227
|
+
| `rp.create(body, gpu_ids=None)` | Created or recovered pod dict. With a list such as `gpu_ids=["NVIDIA RTX A5000", "NVIDIA A40"]`, tries the GPU types in order under the rules below |
|
|
228
|
+
|
|
229
|
+
Wait durations are seconds. Timeouts, polling intervals, and TCP timeouts must be finite positive numbers. Both wait methods tolerate transport errors, HTTP 429, and HTTP 5xx while polling; other HTTP errors propagate. Deadline expiry raises `RunPodTimeoutError`. `wait_ssh` checks TCP reachability, not SSH authentication.
|
|
230
|
+
|
|
231
|
+
The helpers perform no network requests:
|
|
232
|
+
|
|
233
|
+
| Helper | Behavior |
|
|
234
|
+
| --- | --- |
|
|
235
|
+
| `pod_state(pod)` | Uppercases `status`; returns `NOTFOUND` for non-dicts or missing/invalid status; maps `RUNNING` with absent or null `runtime` to `STARTING` |
|
|
236
|
+
| `ssh_endpoint(pod)` | Returns `(host, int_port)` from the first valid private-22 TCP entry in a `RUNNING` pod's `runtime.ports`, otherwise `None`; does not probe TCP |
|
|
237
|
+
| `to_v1(pod)` | Deep-copies a pod dict and adds/replaces `desiredStatus`, `publicIp`, and `portMappings`; never mutates the input |
|
|
238
|
+
| `BOOTING` | Frozenset of `PROVISIONING`, `CREATED`, `STARTING`, `RESTARTING`, `INITIALIZING` |
|
|
239
|
+
|
|
240
|
+
`to_v1` sets `desiredStatus` to `RUNNING` for running or booting states, otherwise to `pod_state(pod)`. It sets `publicIp` to the SSH host or `""`, and `portMappings` to `{"22": port}` or `{}`. It requires a dict.
|
|
241
|
+
|
|
242
|
+
`RunPodError` is a `RuntimeError` with `.status` (HTTP code, or `None` for transport/local errors) and `.body` (response text or diagnostic body, truncated to 500 characters). `RunPodTimeoutError` subclasses it and always has `.status is None`. Input validation can raise `ValueError` or `TypeError`.
|
|
243
|
+
|
|
244
|
+
Start a pod, wait for its current endpoint, then connect using an existing SSH key:
|
|
245
|
+
|
|
246
|
+
```python
|
|
247
|
+
import os
|
|
248
|
+
import subprocess
|
|
249
|
+
from runpodkit import RunPod
|
|
250
|
+
|
|
251
|
+
rp = RunPod() # RUNPOD_API_KEY is already supplied in the environment.
|
|
252
|
+
pod_id = os.environ["POD_ID"]
|
|
253
|
+
rp.start(pod_id)
|
|
254
|
+
host, port = rp.wait_ssh(pod_id)
|
|
255
|
+
subprocess.run(["ssh", "-p", str(port), f"root@{host}"], check=True)
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## create() money-safety rules
|
|
259
|
+
|
|
260
|
+
1. `body` must be a dict with a non-empty string `name`. If supplied, `gpu_ids` must be a non-empty list of distinct, non-empty strings. Invalid inputs raise `ValueError`. The body is deep-copied; the caller's object is never changed.
|
|
261
|
+
2. Without `gpu_ids`, there is one attempt with the body unchanged. With GPU IDs, each attempt replaces `gpu` with `{"id": gpu_id, "count": count}`. Count comes from the original `gpu["count"]` when present in a dict, otherwise defaults to `1`.
|
|
262
|
+
3. Before every attempt after the first, `find_pod(name)` checks for an existing non-terminated pod. If found, it is returned without another POST. If the lookup fails, its error propagates and no POST follows. No existing pod is ever *returned* before the first attempt; the only call before it is the ID snapshot described in rule 6.
|
|
263
|
+
4. A successful POST must return a dict with a non-empty string `id`. A malformed success response, including invalid JSON, triggers recovery by name because a pod may already have been created; it never triggers another POST.
|
|
264
|
+
5. Only HTTP 4xx errors other than `401`, `403`, and `429` allow fallback to the next GPU. Those three codes raise immediately without fallback or recovery lookup.
|
|
265
|
+
6. A transport error, HTTP 5xx, or another uncertain POST result triggers `find_pod(name)`. A found pod is returned. If absent, a `RunPodError` preserving the original status/body reports `create outcome UNKNOWN` and warns that a pod may still appear and bill. If the recovery lookup itself fails, the error still reports `create outcome UNKNOWN` (keeping the original POST status/body, with the lookup error as its cause), because a pod may exist even though it could not be checked. Recovery never re-POSTs; check `runpodkit list` before manually retrying. Before its first POST, `create` snapshots the IDs of pods already carrying that name; the retry guard and the recovery only ever return a pod **not** in that snapshot, so an older same-name husk is never mistaken for the new (billing) pod. A failed snapshot raises before any POST.
|
|
266
|
+
7. If every GPU attempt is refused by an eligible 4xx, the last refusal error is raised.
|
|
267
|
+
|
|
268
|
+
## Bash usage
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
set -uo pipefail
|
|
272
|
+
. "$(runpodkit bash-lib)"
|
|
273
|
+
|
|
274
|
+
# RUNPOD_API_KEY is already supplied in the environment.
|
|
275
|
+
info=$(rp_get "$POD_ID")
|
|
276
|
+
printf '%s\n' "$info" | rp_state
|
|
277
|
+
printf '%s\n' "$info" | rp_ssh
|
|
278
|
+
rp_action "$POD_ID" start
|
|
279
|
+
if endpoint=$(rp_wait_ssh "$POD_ID" 320); then
|
|
280
|
+
read -r host port <<< "$endpoint"
|
|
281
|
+
ssh -p "$port" "root@$host"
|
|
282
|
+
fi
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
| Function | Standard output | Return code |
|
|
286
|
+
| --- | --- | --- |
|
|
287
|
+
| `rp_get ID` | Pod JSON; a missing pod prints a JSON object whose `detail` is `"pod not found"` | `0` for found or missing; `1` for other CLI failures; `2` for missing/empty ID |
|
|
288
|
+
| `rp_state` | Reads pod JSON from stdin; prints one state word, or `NOTFOUND` if the CLI fails or is silent | Always `0` |
|
|
289
|
+
| `rp_ssh` | Reads pod JSON from stdin; prints `ip port` and newline, or nothing if unavailable or the CLI fails | Always `0` |
|
|
290
|
+
| `rp_action ID start\|stop\|restart` | CLI pod JSON | CLI status unchanged; `2` for missing/empty arguments or an invalid action |
|
|
291
|
+
| `rp_delete ID` | HTTP status: normally `204`, `404` if missing, or another HTTP error code; nothing on transport failure | CLI status unchanged (`0` for deleted/missing, `1` for errors); `2` for missing/empty ID |
|
|
292
|
+
| `rp_wait_ssh ID [TIMEOUT]` | `ip port` and newline on success; default timeout `320` seconds | `0` on success; `1` on any CLI failure, including timeout; `2` for missing/empty ID |
|
|
293
|
+
|
|
294
|
+
Argument errors write a diagnostic to stderr. These wrappers preserve CLI stderr. Pod JSON uses the CLI's default `env` stripping.
|
|
295
|
+
|
|
296
|
+
Each invocation uses a non-empty `$RP` first, otherwise `$RUNPOD_API_KEY`, otherwise an empty key. The wrapper exports the selected key only inside a subshell for the CLI call, never in argv. A non-empty `RUNPOD_API_URL` shell variable is also exported there, even if it was not exported by the caller.
|
|
297
|
+
|
|
298
|
+
`RUNPODKIT_CLI` selects an alternate executable path or shell function name; it is one quoted command name, not a command string with arguments. Empty or unset means `runpodkit`. A function named `runpodkit`, including the vendored-copy definition above, works directly. Subshell execution isolates exports and function side effects from the caller.
|
|
299
|
+
|
|
300
|
+
The library is safe to source under `set -uo pipefail` and preserves shell options, traps, and `IFS`. It uses no `exit`. Under `set -e`, handle expected nonzero function returns with `if` or another shell conditional.
|
|
301
|
+
|
|
302
|
+
## CLI reference
|
|
303
|
+
|
|
304
|
+
Use either `runpodkit` or `python3 -m runpodkit`. Every subcommand supports `--help`.
|
|
305
|
+
|
|
306
|
+
| Subcommand and arguments | Standard output | Command-specific exit codes |
|
|
307
|
+
| --- | --- | --- |
|
|
308
|
+
| `list [--all] [--with-env]` | JSON array; hides `TERMINATED` unless `--all` | `0` |
|
|
309
|
+
| `get ID [--with-env]` | Pod JSON; on 404, a JSON object whose `detail` is `"pod not found"` | `0` found; `3` missing |
|
|
310
|
+
| `state ID` or `state -` | State word; `NOTFOUND` for a missing pod or invalid/empty stdin JSON | `0`, including `NOTFOUND` |
|
|
311
|
+
| `ssh ID` or `ssh -` | `ip port` and newline, or nothing when unavailable | `0` endpoint; `1` unavailable |
|
|
312
|
+
| `wait-ssh ID [--timeout N]` | Reachable `ip port`; default `320` seconds | `0` ready; `3` timeout |
|
|
313
|
+
| `wait-status ID STATUS [--timeout N] [--with-env]` | Pod JSON; case-insensitive target, default `240` seconds | `0` matched; `3` timeout |
|
|
314
|
+
| `start ID [--with-env]` | Pod JSON from action response | `0` |
|
|
315
|
+
| `stop ID [--with-env]` | Pod JSON from action response | `0` |
|
|
316
|
+
| `restart ID [--with-env]` | Pod JSON from action response | `0` |
|
|
317
|
+
| `delete ID` | HTTP status, including `404` when already missing; prints other HTTP error codes too; no stdout on transport failure | `0` deleted/missing; `1` other errors |
|
|
318
|
+
| `create --body FILE [--gpu ID ...] [--with-env]` | Created or recovered pod JSON; `FILE` may be `-` for stdin | `0` |
|
|
319
|
+
| `volumes` | Network-volume JSON array | `0` |
|
|
320
|
+
| `bash-lib` | Absolute path to the Bash library | `0` |
|
|
321
|
+
| `version` | `runpodkit` followed by its version | `0` |
|
|
322
|
+
|
|
323
|
+
All commands can also return `1` for operational errors, `2` for usage errors, or `130` on keyboard interrupt. Exit `3` is reserved for `get` not found and wait timeouts. Broken stdout pipes return `1` quietly. Operational errors normally write one line prefixed `runpodkit:` to stderr; an unavailable `ssh` endpoint returns `1` silently.
|
|
324
|
+
|
|
325
|
+
The CLI reads the API key only from `RUNPOD_API_KEY`, with no key flag. `state -`, `ssh -`, `bash-lib`, and `version` need no key and make no network requests. Other commands use `RUNPOD_API_URL` if supplied.
|
|
326
|
+
|
|
327
|
+
JSON output is indented by two spaces with a trailing newline. By default, commands printing pod JSON remove each pod's top-level `env` field. `--with-env` keeps it and is supported only by `list`, `get`, `wait-status`, `start`, `stop`, `restart`, and `create`. `volumes` prints its response without this pod-field filtering. Python API results retain `env`.
|
|
328
|
+
|
|
329
|
+
`create` reads a JSON object from a file or stdin. Repeat `--gpu` or supply several IDs after one flag; quote GPU IDs containing spaces:
|
|
330
|
+
|
|
331
|
+
```bash
|
|
332
|
+
runpodkit create --body pod.json --gpu "NVIDIA RTX A5000" "NVIDIA A40"
|
|
333
|
+
runpodkit create --body pod.json --gpu "NVIDIA RTX A5000" --gpu "NVIDIA A40"
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## RunPod v2 behavior notes
|
|
337
|
+
|
|
338
|
+
These are recorded API observations; startup timing is not a guarantee.
|
|
339
|
+
|
|
340
|
+
- V2 `status` is the observed state. The v1-style `desiredStatus` added by `to_v1` is a compatibility field and maps booting states to `RUNNING`.
|
|
341
|
+
- `runtime` can be null while booting. `pod_state` treats `status: RUNNING` with null or missing runtime as `STARTING`.
|
|
342
|
+
- SSH comes from a `runtime.ports` entry with integer `private: 22`, `type: "tcp"`, a non-empty IP, and a positive public port. A decimal-string public port is accepted and converted to an integer. The private-19123 `http` entry is ignored. `ssh.direct` can be stale and is never used.
|
|
343
|
+
- **Stale runtime after start:** for about 25 seconds, the API has reported `RUNNING` with the previous run's SSH port, which refuses connections. The port changes on every restart. `wait_ssh` re-GETs the pod on every poll and TCP-probes that poll's endpoint; it does not cache the first `RUNNING` endpoint. `wait_status(..., "RUNNING")` alone does not establish SSH readiness.
|
|
344
|
+
- Wrong-state actions can return HTTP `409`; for example, stopping an `EXITED` pod. The client propagates the error instead of treating the action as successful.
|
|
345
|
+
- Create capacity refusals return HTTP `400`. This is eligible for the guarded GPU fallback described above.
|
|
346
|
+
- The minimum persistent volume is 10 GB.
|
|
347
|
+
- Cloudflare has rejected Python's default urllib User-Agent with HTTP `403` and `error code: 1010`. Every client request sends the browser-style `Mozilla/5.0 (X11; Linux x86_64) runpodkit/` User-Agent followed by the package version, along with Bearer authorization, JSON content type, and JSON accept headers.
|
|
348
|
+
|
|
349
|
+
## Security
|
|
350
|
+
|
|
351
|
+
The CLI accepts the API key through the environment, and Bash passes it only through the child environment. The client sends it in the Authorization header. The key is never added to argv and is redacted from client-generated error messages, error bodies, and `repr(rp)`; the CLI also redacts it from output and diagnostics. Supply credentials through the environment rather than command-line arguments.
|
|
352
|
+
|
|
353
|
+
Pod `env` fields are stripped from CLI JSON by default because they may contain secrets. `--with-env` exposes them. Python API results and `to_v1` copies retain them; key redaction is not general redaction of every secret in a response.
|
|
354
|
+
|
|
355
|
+
Tests are offline: HTTP and TCP calls are mocked, with guards against unmocked client network access. Bash tests use local stubs or stdin parsing; installer tests use temporary directories and interpreters.
|
|
356
|
+
|
|
357
|
+
## Running the tests
|
|
358
|
+
|
|
359
|
+
From the clone root:
|
|
360
|
+
|
|
361
|
+
```bash
|
|
362
|
+
python3 -m unittest discover -s tests -v
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
`tests/test_bash.py` and `tests/test_install.py` can run every shell scenario under several Bash executables. Supply colon-separated absolute paths:
|
|
366
|
+
|
|
367
|
+
```bash
|
|
368
|
+
RUNPODKIT_TEST_BASHES=/path/to/bash3.2:/bin/bash \
|
|
369
|
+
python3 -m unittest discover -s tests -v
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
Without this variable, the shell tests use `bash` from `PATH` and are skipped only if there is none. Configured paths must be absolute, existing executables; a wrong path is a test error, never a silent skip. The tests require no API key, pip, or network.
|
|
373
|
+
|
|
374
|
+
## Contributing
|
|
375
|
+
|
|
376
|
+
Issues and pull requests are welcome. Keep the runtime standard-library only, keep Bash 3.2 compatibility, and add an offline test for any behavior change. CI runs the suite on Python 3.9 through 3.13, the shell tests under a source-built GNU Bash 3.2.57, and a separate real-macOS job.
|
|
377
|
+
|
|
378
|
+
## License
|
|
379
|
+
|
|
380
|
+
MIT. See [LICENSE](LICENSE). Not affiliated with or endorsed by RunPod.
|