swytchcode-runtime 0.1.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.
- swytchcode_runtime-0.1.0/PKG-INFO +133 -0
- swytchcode_runtime-0.1.0/README.md +117 -0
- swytchcode_runtime-0.1.0/pyproject.toml +27 -0
- swytchcode_runtime-0.1.0/setup.cfg +4 -0
- swytchcode_runtime-0.1.0/swytchcode_runtime/__init__.py +6 -0
- swytchcode_runtime-0.1.0/swytchcode_runtime/errors.py +22 -0
- swytchcode_runtime-0.1.0/swytchcode_runtime/exec.py +97 -0
- swytchcode_runtime-0.1.0/swytchcode_runtime.egg-info/PKG-INFO +133 -0
- swytchcode_runtime-0.1.0/swytchcode_runtime.egg-info/SOURCES.txt +9 -0
- swytchcode_runtime-0.1.0/swytchcode_runtime.egg-info/dependency_links.txt +1 -0
- swytchcode_runtime-0.1.0/swytchcode_runtime.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swytchcode-runtime
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Thin runtime wrapper around the Swytchcode CLI
|
|
5
|
+
Author: Swytchcode
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: repository, https://gitlab.com/swytchcode/py-runtime
|
|
8
|
+
Keywords: swytchcode,cli,runtime,exec
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# swytchcode-runtime (Python)
|
|
18
|
+
|
|
19
|
+
Thin runtime wrapper around the Swytchcode CLI. Calls `swytchcode exec` for you so you can stay in Python without shell boilerplate.
|
|
20
|
+
|
|
21
|
+
**Requires:** The `swytchcode` binary must be installed and on your `PATH`.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install swytchcode-runtime
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or from the repo:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install /path/to/runtime-libraries/python-runtime
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Use
|
|
36
|
+
|
|
37
|
+
### JSON mode (default)
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from swytchcode_runtime import exec
|
|
41
|
+
|
|
42
|
+
result = exec("api.account.create", {"email": "test@example.com"})
|
|
43
|
+
# result is parsed JSON (any)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Equivalent to: `swytchcode exec api.account.create --json` with args on stdin.
|
|
47
|
+
|
|
48
|
+
**Request input (args):** The second argument is the kernel **args** object (sent as JSON on stdin). Use this shape so the kernel builds the request correctly:
|
|
49
|
+
- **body** — Request body (dict).
|
|
50
|
+
- **params** — Query/path params (e.g. `{"id": "cluster-123"}`).
|
|
51
|
+
- **Authorization** — Auth header value (e.g. `"Bearer token123"`).
|
|
52
|
+
- **headers** — Additional request headers (e.g. `{"X-Request-Id": "abc-123"}`).
|
|
53
|
+
- Other top-level keys are passed as query params.
|
|
54
|
+
|
|
55
|
+
Example with body, params, and headers:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
exec("api.cluster.get", {
|
|
59
|
+
"params": {"id": "cluster-123"},
|
|
60
|
+
"Authorization": "Bearer token123",
|
|
61
|
+
"headers": {"X-Request-Id": "abc-123"},
|
|
62
|
+
})
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Raw mode
|
|
66
|
+
|
|
67
|
+
Get stdout as a string instead of parsing JSON:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from swytchcode_runtime import exec
|
|
71
|
+
|
|
72
|
+
output = exec("api.report.export", {"id": "123"}, raw=True)
|
|
73
|
+
# output is the raw stdout string
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Options
|
|
77
|
+
|
|
78
|
+
- **cwd** – Working directory for the process (default: current directory).
|
|
79
|
+
- **env** – Extra environment variables (merged with `os.environ`).
|
|
80
|
+
- **raw** – If `True`, use `--raw` and return stdout as a string.
|
|
81
|
+
- **dry_run** – If `True`, pass `--dry-run` to the CLI; request details (method, url, headers, body) are output instead of calling the server.
|
|
82
|
+
- **allow_raw** – If `True`, pass `--allow-raw` to the CLI; required for executing raw methods (kernel has this disabled by default).
|
|
83
|
+
|
|
84
|
+
This runtime invokes `swytchcode exec [canonical_id]` with the flags above. For full exec behavior, see the Swytchcode kernel documentation.
|
|
85
|
+
|
|
86
|
+
### Error handling
|
|
87
|
+
|
|
88
|
+
Failures raise `SwytchcodeError` (spawn error, non-zero exit, invalid JSON). Use the helper to narrow:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from swytchcode_runtime import exec, SwytchcodeError, is_swytchcode_error
|
|
92
|
+
|
|
93
|
+
try:
|
|
94
|
+
exec("api.account.create", {"email": "test@example.com"})
|
|
95
|
+
except Exception as e:
|
|
96
|
+
if is_swytchcode_error(e):
|
|
97
|
+
print(e.message, e.cause)
|
|
98
|
+
raise
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## What this library is
|
|
102
|
+
|
|
103
|
+
- A thin process wrapper over the Swytchcode shell.
|
|
104
|
+
- A stable call surface: `exec(canonical_id, input=None, *, cwd=..., env=..., raw=...)`.
|
|
105
|
+
- A convenience for developers and IDE agents.
|
|
106
|
+
|
|
107
|
+
## What this library is not
|
|
108
|
+
|
|
109
|
+
- An HTTP SDK or API client.
|
|
110
|
+
- A replacement for the shell. All authority stays in the Swytchcode CLI.
|
|
111
|
+
|
|
112
|
+
This library **must not** and **does not**:
|
|
113
|
+
|
|
114
|
+
- Read `.swytchcode/*` or parse `tooling.json`.
|
|
115
|
+
- Validate schemas or add retries/timeouts.
|
|
116
|
+
- Call the registry or embed auth logic.
|
|
117
|
+
|
|
118
|
+
It is a pipe, not a brain.
|
|
119
|
+
|
|
120
|
+
## For Cursor / IDE agents
|
|
121
|
+
|
|
122
|
+
Generate code that uses this runtime instead of subprocess boilerplate.
|
|
123
|
+
|
|
124
|
+
**Preferred:**
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from swytchcode_runtime import exec
|
|
128
|
+
|
|
129
|
+
def create_account(input: dict) -> any:
|
|
130
|
+
return exec("api.account.create", input)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Avoid:** subprocess boilerplate, HTTP calls, or config parsing. Use `exec(...)` and let the CLI handle execution and policy.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# swytchcode-runtime (Python)
|
|
2
|
+
|
|
3
|
+
Thin runtime wrapper around the Swytchcode CLI. Calls `swytchcode exec` for you so you can stay in Python without shell boilerplate.
|
|
4
|
+
|
|
5
|
+
**Requires:** The `swytchcode` binary must be installed and on your `PATH`.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install swytchcode-runtime
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or from the repo:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install /path/to/runtime-libraries/python-runtime
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Use
|
|
20
|
+
|
|
21
|
+
### JSON mode (default)
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from swytchcode_runtime import exec
|
|
25
|
+
|
|
26
|
+
result = exec("api.account.create", {"email": "test@example.com"})
|
|
27
|
+
# result is parsed JSON (any)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Equivalent to: `swytchcode exec api.account.create --json` with args on stdin.
|
|
31
|
+
|
|
32
|
+
**Request input (args):** The second argument is the kernel **args** object (sent as JSON on stdin). Use this shape so the kernel builds the request correctly:
|
|
33
|
+
- **body** — Request body (dict).
|
|
34
|
+
- **params** — Query/path params (e.g. `{"id": "cluster-123"}`).
|
|
35
|
+
- **Authorization** — Auth header value (e.g. `"Bearer token123"`).
|
|
36
|
+
- **headers** — Additional request headers (e.g. `{"X-Request-Id": "abc-123"}`).
|
|
37
|
+
- Other top-level keys are passed as query params.
|
|
38
|
+
|
|
39
|
+
Example with body, params, and headers:
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
exec("api.cluster.get", {
|
|
43
|
+
"params": {"id": "cluster-123"},
|
|
44
|
+
"Authorization": "Bearer token123",
|
|
45
|
+
"headers": {"X-Request-Id": "abc-123"},
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Raw mode
|
|
50
|
+
|
|
51
|
+
Get stdout as a string instead of parsing JSON:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from swytchcode_runtime import exec
|
|
55
|
+
|
|
56
|
+
output = exec("api.report.export", {"id": "123"}, raw=True)
|
|
57
|
+
# output is the raw stdout string
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Options
|
|
61
|
+
|
|
62
|
+
- **cwd** – Working directory for the process (default: current directory).
|
|
63
|
+
- **env** – Extra environment variables (merged with `os.environ`).
|
|
64
|
+
- **raw** – If `True`, use `--raw` and return stdout as a string.
|
|
65
|
+
- **dry_run** – If `True`, pass `--dry-run` to the CLI; request details (method, url, headers, body) are output instead of calling the server.
|
|
66
|
+
- **allow_raw** – If `True`, pass `--allow-raw` to the CLI; required for executing raw methods (kernel has this disabled by default).
|
|
67
|
+
|
|
68
|
+
This runtime invokes `swytchcode exec [canonical_id]` with the flags above. For full exec behavior, see the Swytchcode kernel documentation.
|
|
69
|
+
|
|
70
|
+
### Error handling
|
|
71
|
+
|
|
72
|
+
Failures raise `SwytchcodeError` (spawn error, non-zero exit, invalid JSON). Use the helper to narrow:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from swytchcode_runtime import exec, SwytchcodeError, is_swytchcode_error
|
|
76
|
+
|
|
77
|
+
try:
|
|
78
|
+
exec("api.account.create", {"email": "test@example.com"})
|
|
79
|
+
except Exception as e:
|
|
80
|
+
if is_swytchcode_error(e):
|
|
81
|
+
print(e.message, e.cause)
|
|
82
|
+
raise
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## What this library is
|
|
86
|
+
|
|
87
|
+
- A thin process wrapper over the Swytchcode shell.
|
|
88
|
+
- A stable call surface: `exec(canonical_id, input=None, *, cwd=..., env=..., raw=...)`.
|
|
89
|
+
- A convenience for developers and IDE agents.
|
|
90
|
+
|
|
91
|
+
## What this library is not
|
|
92
|
+
|
|
93
|
+
- An HTTP SDK or API client.
|
|
94
|
+
- A replacement for the shell. All authority stays in the Swytchcode CLI.
|
|
95
|
+
|
|
96
|
+
This library **must not** and **does not**:
|
|
97
|
+
|
|
98
|
+
- Read `.swytchcode/*` or parse `tooling.json`.
|
|
99
|
+
- Validate schemas or add retries/timeouts.
|
|
100
|
+
- Call the registry or embed auth logic.
|
|
101
|
+
|
|
102
|
+
It is a pipe, not a brain.
|
|
103
|
+
|
|
104
|
+
## For Cursor / IDE agents
|
|
105
|
+
|
|
106
|
+
Generate code that uses this runtime instead of subprocess boilerplate.
|
|
107
|
+
|
|
108
|
+
**Preferred:**
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from swytchcode_runtime import exec
|
|
112
|
+
|
|
113
|
+
def create_account(input: dict) -> any:
|
|
114
|
+
return exec("api.account.create", input)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Avoid:** subprocess boilerplate, HTTP calls, or config parsing. Use `exec(...)` and let the CLI handle execution and policy.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "swytchcode-runtime"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Thin runtime wrapper around the Swytchcode CLI"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
keywords = ["swytchcode", "cli", "runtime", "exec"]
|
|
13
|
+
authors = [{ name = "Swytchcode" }]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.10",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
repository = "https://gitlab.com/swytchcode/py-runtime"
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
where = ["."]
|
|
27
|
+
include = ["swytchcode_runtime*"]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Errors raised by the Swytchcode runtime."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SwytchcodeError(Exception):
|
|
7
|
+
"""Raised when exec() fails: spawn error, non-zero exit, or invalid JSON output."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, message: str, cause: Any = None) -> None:
|
|
10
|
+
super().__init__(message)
|
|
11
|
+
self.message = message
|
|
12
|
+
self.cause = cause
|
|
13
|
+
|
|
14
|
+
def __str__(self) -> str:
|
|
15
|
+
if self.cause is not None:
|
|
16
|
+
return f"{self.message}: {self.cause}"
|
|
17
|
+
return self.message
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def is_swytchcode_error(exc: BaseException) -> bool:
|
|
21
|
+
"""Return True if exc is a SwytchcodeError."""
|
|
22
|
+
return isinstance(exc, SwytchcodeError)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Run swytchcode exec with optional JSON input on stdin."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import subprocess
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from .errors import SwytchcodeError
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def exec_( # noqa: A001 - shadowing intentional for API consistency with JS/Go
|
|
12
|
+
canonical_id: str,
|
|
13
|
+
input: Any = None,
|
|
14
|
+
*,
|
|
15
|
+
cwd: str | None = None,
|
|
16
|
+
env: dict[str, str] | None = None,
|
|
17
|
+
raw: bool = False,
|
|
18
|
+
dry_run: bool = False,
|
|
19
|
+
allow_raw: bool = False,
|
|
20
|
+
) -> Any:
|
|
21
|
+
"""
|
|
22
|
+
Run swytchcode exec <canonical_id> with optional JSON args on stdin.
|
|
23
|
+
|
|
24
|
+
Returns parsed JSON (default) or raw stdout as str when raw=True.
|
|
25
|
+
The swytchcode binary must be on PATH.
|
|
26
|
+
|
|
27
|
+
The input argument is the kernel args object sent on stdin. Use this shape so the
|
|
28
|
+
kernel builds the request correctly: body (request body), params (query/path params),
|
|
29
|
+
Authorization (auth header value), headers (map of header name to value); other
|
|
30
|
+
top-level keys are passed as query params.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
canonical_id: Swytchcode canonical command ID (e.g. "api.account.create").
|
|
34
|
+
input: Optional args object; serialized as JSON to stdin. Keys: body, params,
|
|
35
|
+
Authorization, headers, and any other as query params. None for no stdin.
|
|
36
|
+
cwd: Working directory for the process. Defaults to current directory.
|
|
37
|
+
env: Extra environment variables merged with os.environ.
|
|
38
|
+
raw: If True, use --raw and return stdout as a string.
|
|
39
|
+
dry_run: If True, pass --dry-run; request details are output instead of calling the server.
|
|
40
|
+
allow_raw: If True, pass --allow-raw; required for executing raw methods (kernel default is disabled).
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
Parsed result (any) or raw string when raw is True.
|
|
44
|
+
|
|
45
|
+
Raises:
|
|
46
|
+
SwytchcodeError: When the process fails, exits non-zero, or stdout is invalid JSON.
|
|
47
|
+
"""
|
|
48
|
+
canonical_id = canonical_id.strip()
|
|
49
|
+
if not canonical_id:
|
|
50
|
+
raise SwytchcodeError("canonical_id must be a non-empty string")
|
|
51
|
+
|
|
52
|
+
flag = "--raw" if raw else "--json"
|
|
53
|
+
cmd = ["swytchcode", "exec", canonical_id, flag]
|
|
54
|
+
if dry_run:
|
|
55
|
+
cmd.append("--dry-run")
|
|
56
|
+
if allow_raw:
|
|
57
|
+
cmd.append("--allow-raw")
|
|
58
|
+
|
|
59
|
+
run_env = os.environ.copy()
|
|
60
|
+
if env:
|
|
61
|
+
run_env.update(env)
|
|
62
|
+
|
|
63
|
+
stdin_payload: bytes | None = None
|
|
64
|
+
if input is not None:
|
|
65
|
+
stdin_payload = json.dumps(input).encode("utf-8")
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
result = subprocess.run(
|
|
69
|
+
cmd,
|
|
70
|
+
input=stdin_payload,
|
|
71
|
+
capture_output=True,
|
|
72
|
+
cwd=cwd or os.getcwd(),
|
|
73
|
+
env=run_env,
|
|
74
|
+
timeout=None,
|
|
75
|
+
)
|
|
76
|
+
except FileNotFoundError as e:
|
|
77
|
+
raise SwytchcodeError("Failed to spawn swytchcode", e) from e
|
|
78
|
+
except OSError as e:
|
|
79
|
+
raise SwytchcodeError("Failed to run swytchcode", e) from e
|
|
80
|
+
|
|
81
|
+
stderr = result.stderr.decode("utf-8", errors="replace").strip()
|
|
82
|
+
stdout = result.stdout.decode("utf-8", errors="replace")
|
|
83
|
+
|
|
84
|
+
if result.returncode != 0:
|
|
85
|
+
msg = stderr or "swytchcode exec failed"
|
|
86
|
+
raise SwytchcodeError(msg, result.returncode)
|
|
87
|
+
|
|
88
|
+
if raw:
|
|
89
|
+
return stdout
|
|
90
|
+
|
|
91
|
+
if not stdout.strip():
|
|
92
|
+
return None
|
|
93
|
+
|
|
94
|
+
try:
|
|
95
|
+
return json.loads(stdout)
|
|
96
|
+
except json.JSONDecodeError as e:
|
|
97
|
+
raise SwytchcodeError("Invalid JSON output from swytchcode", stdout) from e
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swytchcode-runtime
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Thin runtime wrapper around the Swytchcode CLI
|
|
5
|
+
Author: Swytchcode
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: repository, https://gitlab.com/swytchcode/py-runtime
|
|
8
|
+
Keywords: swytchcode,cli,runtime,exec
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# swytchcode-runtime (Python)
|
|
18
|
+
|
|
19
|
+
Thin runtime wrapper around the Swytchcode CLI. Calls `swytchcode exec` for you so you can stay in Python without shell boilerplate.
|
|
20
|
+
|
|
21
|
+
**Requires:** The `swytchcode` binary must be installed and on your `PATH`.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install swytchcode-runtime
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or from the repo:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install /path/to/runtime-libraries/python-runtime
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Use
|
|
36
|
+
|
|
37
|
+
### JSON mode (default)
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from swytchcode_runtime import exec
|
|
41
|
+
|
|
42
|
+
result = exec("api.account.create", {"email": "test@example.com"})
|
|
43
|
+
# result is parsed JSON (any)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Equivalent to: `swytchcode exec api.account.create --json` with args on stdin.
|
|
47
|
+
|
|
48
|
+
**Request input (args):** The second argument is the kernel **args** object (sent as JSON on stdin). Use this shape so the kernel builds the request correctly:
|
|
49
|
+
- **body** — Request body (dict).
|
|
50
|
+
- **params** — Query/path params (e.g. `{"id": "cluster-123"}`).
|
|
51
|
+
- **Authorization** — Auth header value (e.g. `"Bearer token123"`).
|
|
52
|
+
- **headers** — Additional request headers (e.g. `{"X-Request-Id": "abc-123"}`).
|
|
53
|
+
- Other top-level keys are passed as query params.
|
|
54
|
+
|
|
55
|
+
Example with body, params, and headers:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
exec("api.cluster.get", {
|
|
59
|
+
"params": {"id": "cluster-123"},
|
|
60
|
+
"Authorization": "Bearer token123",
|
|
61
|
+
"headers": {"X-Request-Id": "abc-123"},
|
|
62
|
+
})
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Raw mode
|
|
66
|
+
|
|
67
|
+
Get stdout as a string instead of parsing JSON:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from swytchcode_runtime import exec
|
|
71
|
+
|
|
72
|
+
output = exec("api.report.export", {"id": "123"}, raw=True)
|
|
73
|
+
# output is the raw stdout string
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Options
|
|
77
|
+
|
|
78
|
+
- **cwd** – Working directory for the process (default: current directory).
|
|
79
|
+
- **env** – Extra environment variables (merged with `os.environ`).
|
|
80
|
+
- **raw** – If `True`, use `--raw` and return stdout as a string.
|
|
81
|
+
- **dry_run** – If `True`, pass `--dry-run` to the CLI; request details (method, url, headers, body) are output instead of calling the server.
|
|
82
|
+
- **allow_raw** – If `True`, pass `--allow-raw` to the CLI; required for executing raw methods (kernel has this disabled by default).
|
|
83
|
+
|
|
84
|
+
This runtime invokes `swytchcode exec [canonical_id]` with the flags above. For full exec behavior, see the Swytchcode kernel documentation.
|
|
85
|
+
|
|
86
|
+
### Error handling
|
|
87
|
+
|
|
88
|
+
Failures raise `SwytchcodeError` (spawn error, non-zero exit, invalid JSON). Use the helper to narrow:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from swytchcode_runtime import exec, SwytchcodeError, is_swytchcode_error
|
|
92
|
+
|
|
93
|
+
try:
|
|
94
|
+
exec("api.account.create", {"email": "test@example.com"})
|
|
95
|
+
except Exception as e:
|
|
96
|
+
if is_swytchcode_error(e):
|
|
97
|
+
print(e.message, e.cause)
|
|
98
|
+
raise
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## What this library is
|
|
102
|
+
|
|
103
|
+
- A thin process wrapper over the Swytchcode shell.
|
|
104
|
+
- A stable call surface: `exec(canonical_id, input=None, *, cwd=..., env=..., raw=...)`.
|
|
105
|
+
- A convenience for developers and IDE agents.
|
|
106
|
+
|
|
107
|
+
## What this library is not
|
|
108
|
+
|
|
109
|
+
- An HTTP SDK or API client.
|
|
110
|
+
- A replacement for the shell. All authority stays in the Swytchcode CLI.
|
|
111
|
+
|
|
112
|
+
This library **must not** and **does not**:
|
|
113
|
+
|
|
114
|
+
- Read `.swytchcode/*` or parse `tooling.json`.
|
|
115
|
+
- Validate schemas or add retries/timeouts.
|
|
116
|
+
- Call the registry or embed auth logic.
|
|
117
|
+
|
|
118
|
+
It is a pipe, not a brain.
|
|
119
|
+
|
|
120
|
+
## For Cursor / IDE agents
|
|
121
|
+
|
|
122
|
+
Generate code that uses this runtime instead of subprocess boilerplate.
|
|
123
|
+
|
|
124
|
+
**Preferred:**
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from swytchcode_runtime import exec
|
|
128
|
+
|
|
129
|
+
def create_account(input: dict) -> any:
|
|
130
|
+
return exec("api.account.create", input)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Avoid:** subprocess boilerplate, HTTP calls, or config parsing. Use `exec(...)` and let the CLI handle execution and policy.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
swytchcode_runtime/__init__.py
|
|
4
|
+
swytchcode_runtime/errors.py
|
|
5
|
+
swytchcode_runtime/exec.py
|
|
6
|
+
swytchcode_runtime.egg-info/PKG-INFO
|
|
7
|
+
swytchcode_runtime.egg-info/SOURCES.txt
|
|
8
|
+
swytchcode_runtime.egg-info/dependency_links.txt
|
|
9
|
+
swytchcode_runtime.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
swytchcode_runtime
|