Skip to main content

spawnllm

Delete your subprocess wrappers around claude, codex, and gemini. spawnllm subshells all three CLIs — or drives Claude in-process through the bundled Agent SDK — plus local MLX and Apple's on-device Foundation Models, and returns one Pydantic-validated Response, so the per-model plumbing you hand-rolled goes away.

CI PyPI License: MIT

Get started

uvx spawnllm status
Terminal running 'uvx spawnllm status' — every backend reports ready and auto-selection picks claude

Driving with an agent? Paste this:

Run `uv add spawnllm` in this project.
Replace our hand-rolled claude/codex subprocess code with spawnllm's `call_sync`,
or `extract_sync` with a Pydantic response model for structured output.
Verify available backends with `uvx spawnllm status`.
Docs: https://yasyf.github.io/spawnllm/

Use cases

Delete your hand-rolled claude/codex subprocess plumbing

Every small tool grows its own subprocess.run(["claude", "-p", ...]) — argv quirks, stdin piping, exit-code guesswork — and each copy drifts. One call replaces all of it:

from spawnllm import call_sync

print(call_sync("Reply with just the word: pong"))

Prints pong. With no backend=, spawnllm auto-selects the first installed, authenticated backend — a CLI backend gets the prompt over stdin — and retries transient 529/overloaded/rate-limit failures with capped backoff.

Get a validated Pydantic object back, not a string to parse

Scraping JSON out of a model's stdout means regexes, code fences, and silent schema drift. extract_sync validates instead:

from pydantic import BaseModel

from spawnllm import extract_sync


class Capital(BaseModel):
    country: str
    capital: str


result = extract_sync("What is the capital of France?", Capital)
print(result.capital)  # Paris

The backend turns Capital into a JSON-schema constraint on the call itself, and a non-conforming reply raises pydantic.ValidationError instead of sneaking downstream.

Keep billing on your subscription, not a stray API key

An ANTHROPIC_API_KEY left in your shell silently flips the claude CLI from your logged-in plan to per-token API billing. spawnllm strips each provider's key vars from the child environment by default, so every run bills the login:

from spawnllm import call_sync

print(call_sync("Reply with just the word: pong"))

Prints pong, billed to your Claude plan even with ANTHROPIC_API_KEY exported. Pass api_auth=True to opt back into key auth. The same guard covers codex (OPENAI_API_KEY/CODEX_API_KEY) and the Gemini family, in Python, Go, and Rust alike; an explicit RunSpec.env entry always wins.

Call Claude with zero installs

The sdk extra adds a backend over the Claude Agent SDK, whose wheel bundles the Claude Code CLI — no separate claude install:

uv add "spawnllm[sdk]"

claude-sdk registers first in the auto-selection chain and signs in with your existing subscription credentials (keychain login or CLAUDE_CODE_OAUTH_TOKEN), so the call_sync above works on a machine that has never installed the CLI.

Run Apple-Silicon MLX models with fused adapters and prompt-cache reuse

Shipping a LoRA-tuned local model means hand-rolling adapter fusion, model caching, and worker-thread lifecycle. The MLX extra owns all three:

uv add "spawnllm[mlx]"

AdapterFuser.ensure_fused fuses your compressed adapter into the base model once and caches the result in the Hugging Face hub layout; MlxEngine loads it on a dedicated worker thread, precomputes a prompt cache for your shared prefix messages, and batches generation. Wrap the engine in an MlxBackend and the same run_sync call works.

Call Apple's on-device model with zero downloads

Even local MLX starts with a multi-gigabyte model fetch. On a Mac with Apple Intelligence, AppleBackend skips that too: a prebuilt Swift sidecar inside the macOS wheel drives Apple's Foundation Models framework against the model already resident on the device. No extra, no compiler, no credentials, no network — installing spawnllm is the whole setup, uvx spawnllm included:

from spawnllm import AppleBackend, call_sync

print(call_sync("Reply with just the word: pong", backend=AppleBackend()))

Auto-selection tries this backend last and only for model="small"; an explicit backend=AppleBackend() always reaches it. Session and decoding knobs (use_case, guardrails, instructions, temperature, sampling) ride in via RunSpec(provider_configs={"apple": AppleConfig(...)}). Structured extract_sync works too, nested models included, and schema constraints now bind during decoding: minimum/maximum, minItems/maxItems, and string-valued enums are enforced exactly (a non-string enum such as Literal[1, 2] fails before generation, extract_sync raising BackendCallError), and a Field(pattern=...) constrains the value's shape — length, separators, and character families. Apple's decoder rejects bracket character classes, so the sidecar widens each to the narrowest escape it accepts (^[A-Z]{3}-\d{4}$ decodes as \w{3}-\d{4}), and pydantic stays the exact validator: a value that fits the widened shape but violates your regex raises a plain ValidationError. Self-referential models extract cleanly; a mutually recursive pair (A referencing B referencing A) fails cleanly instead, extract_sync raising BackendCallError and run returning an error Response. Requires macOS 26+ on Apple Silicon with Apple Intelligence enabled — every other platform gets the pure-Python wheel and reports the backend as not installed.

Ask a yes/no, label, or score question in about 120 ms

A classifier that runs on every hook event or every PR comment can't wait seconds for a chat model to write JSON. decide_sync asks TypeSafe's Jev or OpenAI Decisions instead. Both return probabilities, not prose, and one question set runs unchanged on either:

from spawnllm import Binary, Label, decide_sync

decision = decide_sync(
    "Our nightly release has failed for 3 days. Please roll it back now.",
    {
        "rollback": Binary("Does the message ask to roll back a release?"),
        "action": Label("Which release action does it ask for?", {"none": None, "release": None, "rollback": None}),
    },
)
print(decision.answers["rollback"].p_yes)  # 0.99
print(decision.answers["action"].choice)  # rollback

On a warm keep-alive connection from a Mac, a three-question Jev call took 120 to 130 ms end to end. Pass provider=OPENAI to ask gpt-6-luna instead. Retries cover 408, 429, 5xx, and 529 and stop at timeout. Keys come from TYPESAFE_API_KEY or OPENAI_API_KEY, or on macOS from a Keychain item that spawnllm key set jev (or openai) writes from stdin.

Call the same backends from Go or Rust

All three languages run the identical engine: argv planning, output parsing, schema strictification, and retry policy live once in a Rust core — linked natively by the Rust crate, embedded as WASM by the Go module and the Python package — pinned by a shared golden-vector suite and released in lockstep.

go get github.com/yasyf/spawnllm/go   # pure Go, no cgo — the core embeds as WASM
cargo add spawnllm                    # async-first, with a blocking mirror

Both expose Call/call and typed Extract/extract against your existing CLI logins, and both reach Apple's on-device model on a capable Mac with binrun installed to fetch the digest-pinned sidecar — see the Go README and the Rust README. MLX stays Python-only.

More in the docs

  • Spec-driven runs — a literal model id, per-provider flag passthrough, and envelope-aware retry via RunSpec — Running reference
  • Decisions — every question and answer type, the provider pins, and the retry and key-lookup rules — Deciding reference
  • Backend selection — the priority chain, plus specialty= routing (debugging and review go to Codex, general to the Claude Agent SDK backend) — Backends reference
  • Transport helpers — run_cli, collect_process, and map_concurrent, the subprocess plumbing shared by every CLI backend — Transport reference
  • The CLI — spawnllm call, status, backends, and key set from any shell — CLI reference
  • MLX internals — the adapter codec, fuser, and runtime patches behind the local engine — MLX reference

Read the docs for the full guide and API reference. Licensed under MIT.

Metadata

Release files for spawnllm 0.17.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spawnllm 0.17.2
File Size Uploaded Provenance Actions
spawnllm-0.17.2.tar.gz 320.8 kB With provenance Details for spawnllm-0.17.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for spawnllm 0.17.2
File Interpreter ABI Platform Actions
spawnllm-0.17.2-py3-none-macosx_26_0_arm64.whl Python 3 none macOS 26.0+ ARM64 Details for spawnllm-0.17.2-py3-none-macosx_26_0_arm64.whl
spawnllm-0.17.2-py3-none-any.whl Python 3 none any Details for spawnllm-0.17.2-py3-none-any.whl

Total release size: 1.1 MB

Release files / spawnllm-0.17.2.tar.gz

Download URL spawnllm-0.17.2.tar.gz
Size 320.8 kB
Tags Source
SHA-256 checksum
How to use checksums
74ac9a9668a9a2c1e9b929080e57b705cacd7d340facbbfd4a42ed1d24908619
BLAKE2b-256 checksum
How to use checksums
de71ec20bc5ad1afacdceb3f93a10eec8b1d86ba51433fe1ccc9047a6a83770e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Release files / spawnllm-0.17.2-py3-none-macosx_26_0_arm64.whl

Download URL spawnllm-0.17.2-py3-none-macosx_26_0_arm64.whl
Size 417.3 kB
Tags Python 3 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
617f3dabac09d860de00c1fd8d6d747c0a07cc012542ac9cadc16fde677ad29b
BLAKE2b-256 checksum
How to use checksums
6a184a4a08f59093c565021ef60d57b5d28c714e45c22e5137c2ffe8a59da6b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Release files / spawnllm-0.17.2-py3-none-any.whl

Download URL spawnllm-0.17.2-py3-none-any.whl
Size 331.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
699e1aed34d457a858178aa12fea1a5723c2325f23da40c2899554108e732012
BLAKE2b-256 checksum
How to use checksums
0b9a4f82f90029eb9fceb1dc5634a65df4f6106959e32cb74f7418722a2b3b1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Security for spawnllm 0.17.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 3 files in this release have been uploaded with provenance metadata.

Select from 3 files

Attestation for spawnllm-0.17.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.17.2 This release

3 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page