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.

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 RunSpecRunning 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 helpersrun_cli, collect_process, and map_concurrent, the subprocess plumbing shared by every CLI backend — Transport reference
  • The CLIspawnllm call, status, and backends 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.

Download files

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

Source Distribution

spawnllm-0.12.0.tar.gz (211.3 kB view details)

Uploaded Source

Built Distributions

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

spawnllm-0.12.0-py3-none-macosx_26_0_arm64.whl (311.1 kB view details)

Uploaded Python 3macOS 26.0+ ARM64

spawnllm-0.12.0-py3-none-any.whl (223.8 kB view details)

Uploaded Python 3

File details

Details for the file spawnllm-0.12.0.tar.gz.

File metadata

  • Download URL: spawnllm-0.12.0.tar.gz
  • Upload date:
  • Size: 211.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for spawnllm-0.12.0.tar.gz
Algorithm Hash digest
SHA256 5c02fb3df85fac25b338f0117b2891e2023ce3a46cdeaeb34d45a9c1cd3b5f32
MD5 9c5b52113a91116c302a157eee795712
BLAKE2b-256 7681cd6fc549d8bc52dd3adfdeaaafa9e3859c784bc75526bccafb08b91cdb1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for spawnllm-0.12.0.tar.gz:

Publisher: release.yml on yasyf/spawnllm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spawnllm-0.12.0-py3-none-macosx_26_0_arm64.whl.

File metadata

File hashes

Hashes for spawnllm-0.12.0-py3-none-macosx_26_0_arm64.whl
Algorithm Hash digest
SHA256 1688fbd9709c7d35340f6dbd877822257191e1af23bf36d1f9ecbfc4fe7c95ac
MD5 5e162c7859d435f6bf73b640d7e436c1
BLAKE2b-256 aee39be923a754892af32e0d6ff663b27d015b09d5daaf0a86f4b5933f7754d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for spawnllm-0.12.0-py3-none-macosx_26_0_arm64.whl:

Publisher: release.yml on yasyf/spawnllm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spawnllm-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: spawnllm-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 223.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for spawnllm-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 938ad3a682988a319514c7f2bc30b1d433a924ffa2b5d2b58f066c8e8fa64877
MD5 9ed6f573e71a4b8f20f99af1f61447ac
BLAKE2b-256 00e6bc3b2d993a8fc3b0437b0d41b448b146c664bae36d018fc9b229d5f1d02b

See more details on using hashes here.

Provenance

The following attestation bundles were made for spawnllm-0.12.0-py3-none-any.whl:

Publisher: release.yml on yasyf/spawnllm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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