Skip to main content

Thin runtime wrapper around the Swytchcode CLI

Project description

swytchcode-runtime (Python)

Thin runtime wrapper around the Swytchcode CLI. Calls swytchcode exec for you so you can stay in Python without shell boilerplate.

Requires: The swytchcode binary must be installed and on your PATH.

Install

pip install swytchcode-runtime

Or from the repo:

pip install /path/to/runtime-libraries/python-runtime

Use

JSON mode (default)

from swytchcode_runtime import exec

result = exec("api.account.create", {"email": "test@example.com"})
# result is parsed JSON (any)

Equivalent to: swytchcode exec api.account.create --json with args on stdin.

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:

  • body — Request body (dict).
  • params — Query/path params (e.g. {"id": "cluster-123"}).
  • Authorization — Auth header value (e.g. "Bearer token123").
  • headers — Additional request headers (e.g. {"X-Request-Id": "abc-123"}).
  • Other top-level keys are passed as query params.

Example with body, params, and headers:

exec("api.cluster.get", {
    "params": {"id": "cluster-123"},
    "Authorization": "Bearer token123",
    "headers": {"X-Request-Id": "abc-123"},
})

Raw mode

Get stdout as a string instead of parsing JSON:

from swytchcode_runtime import exec

output = exec("api.report.export", {"id": "123"}, raw=True)
# output is the raw stdout string

Options

  • cwd – Working directory for the process (default: current directory).
  • env – Extra environment variables (merged with os.environ).
  • raw – If True, use --raw and return stdout as a string.
  • dry_run – If True, pass --dry-run to the CLI; request details (method, url, headers, body) are output instead of calling the server.
  • allow_raw – If True, pass --allow-raw to the CLI; required for executing raw methods (kernel has this disabled by default).

This runtime invokes swytchcode exec [canonical_id] with the flags above. For full exec behavior, see the Swytchcode kernel documentation.

Error handling

Failures raise SwytchcodeError (spawn error, non-zero exit, invalid JSON). Use the helper to narrow:

from swytchcode_runtime import exec, SwytchcodeError, is_swytchcode_error

try:
    exec("api.account.create", {"email": "test@example.com"})
except Exception as e:
    if is_swytchcode_error(e):
        print(e.message, e.cause)
    raise

What this library is

  • A thin process wrapper over the Swytchcode shell.
  • A stable call surface: exec(canonical_id, input=None, *, cwd=..., env=..., raw=...).
  • A convenience for developers and IDE agents.

What this library is not

  • An HTTP SDK or API client.
  • A replacement for the shell. All authority stays in the Swytchcode CLI.

This library must not and does not:

  • Read .swytchcode/* or parse tooling.json.
  • Validate schemas or add retries/timeouts.
  • Call the registry or embed auth logic.

It is a pipe, not a brain.

For Cursor / IDE agents

Generate code that uses this runtime instead of subprocess boilerplate.

Preferred:

from swytchcode_runtime import exec

def create_account(input: dict) -> any:
    return exec("api.account.create", input)

Avoid: subprocess boilerplate, HTTP calls, or config parsing. Use exec(...) and let the CLI handle execution and policy.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swytchcode_runtime-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swytchcode_runtime-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file swytchcode_runtime-0.1.0.tar.gz.

File metadata

  • Download URL: swytchcode_runtime-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for swytchcode_runtime-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1713d3e3441417c9ee105488a7dfd05e33e895a88589916d31e6582ff0dcc1ab
MD5 accdf46017a2710e888612a1c7f570f0
BLAKE2b-256 1535b2abfb84161d7540203ccdb43897f6668075413e542057a4d394c053aa4a

See more details on using hashes here.

File details

Details for the file swytchcode_runtime-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for swytchcode_runtime-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 12510ba39f5714009473b193788cc4d77e7300a295dad0f2f8a2d47af32b0208
MD5 7bd4b6f61075000ec8f8f460f96e8ac7
BLAKE2b-256 3f2f6b4e1298f774145da1ca51bca08909f5cb76fe5994dc010f72e254bb72ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page