Skip to main content

local_llm_wrapper

Local-first LLM wrapper with a stable text-in text-out API. Supports pluggable transports (Ollama, Apple, and an optional Claude Code CLI cloud transport) with structured output helpers and retry for unattended runs.

Package name: local-llm-wrapper (import as local_llm_wrapper).

Overview

  • Library-first wrapper for text models with a small, stable API.
  • Local-first design; an optional cloud transport (Claude Code CLI) is also available.
  • Fallback across transports when a backend is unavailable.
  • Structured helpers for rename/sort workflows with strict parsing and format-fix retries.

Features

  • Pluggable transports in local_llm_wrapper/transports/.
  • Fallback chain in LLMClient with guardrail and context-window handling.
  • Structured prompts and parsers for rename, keep, and sort workflows.
  • Prompt sanitization and output normalization utilities.
  • Quiet mode for non-verbose runs.
  • Unified API for text prompts and chat-style message lists.

Quick start

import local_llm_wrapper.llm as llm

client = llm.LLMClient(
	transports=[
		llm.AppleTransport(),
		llm.OllamaTransport(model=llm.choose_model(None)),
	],
	quiet=True,
)

response = client.generate("Say hello in one sentence.", max_tokens=120)
print(response)

Chat example

import local_llm_wrapper.llm as llm

client = llm.LLMClient(
	transports=[llm.OllamaTransport(model="qwen3.5:9b-q4_K_M")],
	quiet=True,
)
messages = [
	{"role": "system", "content": "Answer in one sentence."},
	{"role": "user", "content": "What is a mutex?"},
]
print(client.generate(messages=messages, max_tokens=120))

CLI example

source source_me.sh && python3 llm_generate.py -p "Say hello in one sentence." -t 80

CLI usage

llm_generate.py is a repo-root helper for quick prompt tests against the Ollama transport.

source source_me.sh && python3 llm_generate.py --help

Options:

  • -p, --prompt: Prompt text to send (default: "Say hello in one sentence.").
  • -m, --model: Override the auto-selected model (default: auto).
  • -t, --max-tokens: Maximum tokens to generate (default: 80).
  • -q, --quiet: Suppress progress output (default).
  • -v, --verbose: Show progress output.

CLI chat demo

llm_chat.py is an interactive chat loop that uses chat-style messages.

source source_me.sh && python3 llm_chat.py

Options:

  • -m, --model: Override the auto-selected model (default: auto).
  • -s, --system: Optional system message to start the chat.
  • -t, --max-tokens: Maximum tokens to generate per response (default: 240).
  • -q, --quiet: Suppress progress output (default).
  • -v, --verbose: Show progress output.

XML tag demo

llm_xml_demo.py requests a tagged response and extracts <answer> from the model output.

source source_me.sh && python3 llm_xml_demo.py -p "Say hello in one sentence."

Structured helpers

The engine includes structured helpers for common file-organization tasks.

import local_llm_wrapper.llm as llm

client = llm.LLMClient(transports=[llm.OllamaTransport(model="qwen3.5:9b-q4_K_M")])
item = {
	"path": "notes.txt",
	"name": "notes",
	"ext": "txt",
	"description": "meeting notes",
}
result = client.sort([item])
print(result.assignments)

Install extras

The Apple backend requires at least one Apple SDK. Install via optional extras:

pip install local-llm-wrapper[apple]           # prebuilt wheels, no Xcode needed (recommended)
pip install local-llm-wrapper[apple-official]   # Apple's official SDK, requires Xcode 26+
pip install local-llm-wrapper[apple-all]        # both backends (for dev/CI)

When both SDKs are installed, the transport prefers apple-fm-sdk when it is available and safe to use, and falls back to apple-foundation-models otherwise.

Claude Code transport

ClaudeCodeTransport delegates to the claude CLI in non-interactive --print mode.

import local_llm_wrapper.llm as llm

client = llm.LLMClient(
	transports=[
		llm.AppleTransport(),
		llm.OllamaTransport(model=llm.choose_model(None)),
		llm.ClaudeCodeTransport(model="sonnet"),
	],
	quiet=True,
)

response = client.generate("Say hello in one sentence.", max_tokens=120)
print(response)

Caveats when using ClaudeCodeTransport:

  • Prompts are sent to the Anthropic cloud, not processed locally or offline.
  • The CLI runs in --print mode which skips the workspace trust dialog; only use it from directories you trust.
  • By default, all Claude Code tools are disabled (--tools ""), so the transport does not intentionally grant workspace read, write, or execute access.

Transports

  • Apple: local_llm_wrapper/transports/apple.py (dual-backend: apple-fm-sdk and apple-foundation-models).
  • Ollama: local_llm_wrapper/transports/ollama.py.
  • Claude Code CLI: local_llm_wrapper/transports/claude_code.py.
  • Protocol: local_llm_wrapper/transports/base.py.

Errors

Standardized exception types live in local_llm_wrapper/errors.py so callers can handle guardrails, context window errors, and transport availability consistently.

Testing

source source_me.sh && python3 -m pytest tests/

Docs

Notes

  • This repo is text-only; image or OCR workflows belong elsewhere.
  • Configuration is explicit through arguments or config objects, not custom environment variables.

Metadata

Release files for local-llm-wrapper 26.5

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

Source distribution (sdist)

Source distribution for local-llm-wrapper 26.5
File Size Uploaded Provenance Actions
local_llm_wrapper-26.5.tar.gz 149.0 kB Without provenance Details for local_llm_wrapper-26.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for local-llm-wrapper 26.5
File Interpreter ABI Platform Actions
local_llm_wrapper-26.5-py3-none-any.whl Python 3 none any Details for local_llm_wrapper-26.5-py3-none-any.whl

Total release size: 199.9 kB

Release files / local_llm_wrapper-26.5.tar.gz

Download URL local_llm_wrapper-26.5.tar.gz
Size 149.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8bae56dc3c27f5ae94f4c8d223247706328dc8be93b97b86012db16bcb73e68f
BLAKE2b-256 checksum
How to use checksums
124c3945e9cd92c49ea208f9c7bc9465bcf29366b9f2a413d7e9cce6103353cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / local_llm_wrapper-26.5-py3-none-any.whl

Download URL local_llm_wrapper-26.5-py3-none-any.whl
Size 50.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
469a6414ffae9250ad44b56b4c2db94d412c535058722da16a7050ae2f67d73a
BLAKE2b-256 checksum
How to use checksums
fd8cfab27cc00b1d7f0c14b75061a185769e0df63179077e290ebc7cc28ca0eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for local-llm-wrapper 26.5

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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

26.5 This release

2 release files No 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