OS-native, on-device AI for Python, powered by rust_local_ai.
pip install python-local-ai Copy PIP instructions
OS-native, on-device AI for Python. It is a thin PyO3 binding over rust_local_ai, so every backend, capability check and safety rule is implemented once in Rust. Part of Universal Local AI (vezz.io).
Early 0.x, built on rust_local_ai 0.2. What a backend can do depends entirely on that core: see the table below. This package never downloads a model or installs a provider.
pip install python_local_ai Wheels are published for CPython 3.9+ (one abi3 wheel per platform):
"beta" means the Rust core builds and type-checks this backend in CI, but it hasn't yet been run against a real model.
The macOS wheels are built with the macOS 26 SDK, and the release fails if the Foundation Models bridge is missing. Other platforms fall back to the sdist, which needs Rust stable (and Xcode on macOS).
pip install maturin maturin develop # into the active virtualenv Quick start (blocking) import python_local_ai as lai model = lai.detect() # never raises, never downloads availability = model.availability_sync() if not availability: print("unavailable:", availability.reason, availability.detail) else: with model.open_session_sync("You are a helpful assistant.") as session: print(session.generate_sync("Explain reinforcement learning simply.").text) asyncio Every I/O method is awaitable. Each one also has a _sync twin that releases the GIL while it waits, so other threads keep running.
import asyncio import python_local_ai as lai async def main(): model = lai.detect() if not await model.availability(): return async with await model.open_session("Be brief.") as session: reply = await session.generate("Why does on-device AI matter?", temperature=0.3) print(reply.text, reply.output_tokens) if session.capabilities.streaming: async for chunk in session.stream("Now say it as a haiku."): print(chunk, end="", flush=True) asyncio.run(main()) session.stream(...) supports both async for and plain for. The generation starts on the first iteration. Call stream.close() to stop early and free the session for the next turn.
model = lai.detect() # the OS-native backend model = lai.openai_compatible("http://localhost:11434/v1") # e.g. Ollama model = lai.openai_compatible("http://127.0.0.1:8080/v1", "qwen3") # pick a model model = lai.inference_snap("qwen3") # a specific Ubuntu snap (Linux) openai_compatible only accepts plain http:// URLs on this machine (localhost, 127.0.0.0/8, ::1), so prompts never leave it. Without a model name it uses the first one the server lists.
model.prepare() (or prepare_sync()) explicitly asks the backend to get its model ready. On Windows this may start a large Phi Silica download, so ask the user first. No other call ever downloads anything.
Every error subclasses LocalAiError and carries a stable code:
GenerationCancelledError means session.cancel() stopped the generation. It is deliberately distinct from asyncio.CancelledError.
python_local_ai.testing.FakeBackend is the deterministic backend from Rust's testing module, so your tests exercise the same session rules as production:
from python_local_ai.testing import FakeBackend fake = FakeBackend() fake.push_response("hello", output_tokens=1) fake.set_stream_chunks(["a", "b"]) session = fake.model().open_session_sync() assert session.generate_sync("hi").text == "hello" assert list(session.stream("go")) == ["a", "b"] It can also simulate unavailability (set_availability), backend errors (push_backend_error), close failures (fail_next_closes), and a generation that blocks (set_generation_blocked) so you can test busy and cancel paths.
python -m venv .venv && . .venv/bin/activate pip install maturin pytest mypy typing_extensions maturin develop pytest # unit tests and doctests python -m mypy.stubtest python_local_ai._native cargo fmt --check && cargo clippy --all-targets -- -D warnings CI runs these steps on Linux, macOS and Windows with Python 3.9 and 3.13, runs the examples, and builds abi3 wheels and an sdist as artifacts. CI never publishes.
The Rust core comes from crates.io (rust_local_ai = "0.2.0" in Cargo.toml, locked in Cargo.lock). The resolved version is exposed as python_local_ai._native.RUST_LOCAL_AI_VERSION. To move to a new core, release rust_local_ai first, then bump it here and run the tests.
.github/workflows/release.yml builds every wheel and the sdist, tests the installed wheels on Linux, macOS and Windows, and uploads them to PyPI through Trusted Publishing when a GitHub release is published:
Dual-licensed under MIT or Apache-2.0, the same as rust_local_ai.
Apache Software License, MIT License (MIT OR Apache-2.0)
ai local-ai on-device apple-intelligence foundation-models
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Enable javascript to be able to filter the list of wheel files.
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 verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.




